stm32内部AD采样程序Word文件下载.docx
- 文档编号:21099008
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:12
- 大小:18.05KB
stm32内部AD采样程序Word文件下载.docx
《stm32内部AD采样程序Word文件下载.docx》由会员分享,可在线阅读,更多相关《stm32内部AD采样程序Word文件下载.docx(12页珍藏版)》请在冰豆网上搜索。
//驱动版本,默认为A版本,一共4个版本
voiddelayms(unsignedintii)//1ms延时函数
{
unsignedinti,x;
for(x=0;
x<
ii;
x++)
for(i=0;
i<
100;
i++);
}
voidsend(unsignedcharvalue,unsignedcharcd)//写8位数据
unsignedchari,dt;
LED1OFF;
LED4OFF;
if(cd==0)
LED3OFF;
else
LED3ON;
LED4ON;
dt=value;
for(i=0;
8;
i++)
if(dt&
0x80)
dt=dt<
<
1;
LED1ON;
//cs=1;
voidreaddata()//读数据
unsignedchari,j;
unsignedcharch[6];
send(0x09,0);
//读数据
//cs=0;
//sclk=0;
6;
ch[i]=0;
for(j=0;
j<
j++)
//sclk=1;
if(!
(GPIO_ReadOutputDataBit(GPIOF,GPIO_Pin_2)))//sdata==0)
ch[i]=ch[i]|(1<
(7-j));
switch(ch[0])
case255:
Ver='
break;
case127:
B'
case0:
if(ch[1]+ch[2]+ch[3]==0)
D'
}else
C'
voidLCD_Initialize()//LCD初始化
unsignedchari;
LED2ON;
//rest=1;
//sdata=0;
LED2OFF;
//rest=0;
delayms(50);
send(0x00,0);
//NOP
delayms(5);
send(0x01,0);
//LCDSoftwareReset
send(0xC6,0);
//InitialEscape
send(0xB9,0);
//Refreshset
send(0x00,1);
readdata();
//读出数据
send(0xB5,0);
//GammaCurveSet
send(0x01,1);
send(0xbd,0);
//commondriveroutputselect//很重要的
if(Ver=='
)
send(0x04,1);
send(0xBE,0);
//PowerControl
send(0x03,1);
send(0x11,0);
//Sleepout
send(0xBA,0);
send(0x7F,1);
send(0x36,0);
//扫描方式
if(Ver=='
send(0x00|0x08,1);
//RGB
send(0x00,1);
send(0xB7,0);
//Temperaturegradientset
i<
14;
i++)
send(0,1);
send(0x29,0);
//displayON
send(0x03,0);
//BoosterVoltageON
delayms(20);
//BoosterVoltagestabilisierenlassen
send(0x20,0);
//displayinversionOFF
send(0x25,0);
//Writecontrast
switch(Ver)//对比度设置
case'
:
send(70,1);
//对比度设置
send(67,1);
//send(74,1);
send(66,1);
//send(64,1);
send(39,1);
//************************
//颜色模式设置:
color=1为4096色模式
//:
color=0为256色模式
voidLCD_ColorSet(unsignedcharColor)
if(Color==1){
send(0x3a,0);
//interfacepixelformat
//0x03为4096色,0x02为256色
send(0x02,1);
send(0x2d,0);
//调色板设置
||Ver=='
//red
send(~0x00,1);
send(~0x02,1);
send(~0x03,1);
send(~0x04,1);
send(~0x05,1);
send(~0x06,1);
send(~0x08,1);
send(~0x0f,1);
//green
//blue
send(0x05,1);
send(0x06,1);
send(0x08,1);
send(0x0f,1);
voidaddset(unsignedcharx1,unsignedchary1,unsignedcharx2,unsignedchary2)//坐标设置4个参数依次为开始X,开始Y,结束x,结束Y
send(0x2a,0);
//columnaddressset
send(x1,1);
send(x2,1);
send(0x2B,0);
//pageaddressset
send(y1,1);
send(y2,1);
send(0x2C,0);
//memorywrite
//清屏:
color=1为4096色模式清屏
color=0为256色模式清屏
voidLCD_Clear(unsignedintvalue,unsignedcharColor)
unsignedcharx,y;
addset(0,0,97,66);
if(Color==1)
for(y=0;
y<
67;
y++)
for(x=0;
x<
49;
x++)
{send(value>
>
4,1);
send(((value&
0x0f)<
4)|(value>
8),1);
send(value,1);
98;
x++)
//在指定位置显示一个字符(8*12大小)
//dcolor为内容颜色,gbcolor为背静颜色
voidshowdian(unsignedcharx,unsignedchary,unsignedchardcolor,unsignedcharbgcolor)
addset(x,y,x+1,y+1);
//设置区域
send(dcolor,1);
send(bgcolor,1);
intmain(void)
//inti,j;
#ifdefDEBUG
debug();
#endif
/*Systemclocksconfiguration---------------------------------------------*/
RCC_Configuration();
SysTick_Configuration();
/*GPIOconfiguration------------------------------------------------------*/
GPIO_Configuration();
//printf("
\r\nUSART1printAD_value--------------------------\r\n"
);
/*DMAchannel1configuration----------------------------------------------*/
/*DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr=ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&
ADC_ConvertedValue;
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize=1;
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority=DMA_Priority_High;
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
DMA_Init(DMA1_Channel1,&
DMA_InitStructure);
//EnableDMAchannel1
DMA_Cmd(DMA1_Channel1,ENABLE);
*/
/*ADC1configuration------------------------------------------------------*/
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode=ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel=1;
ADC_Init(ADC1,&
ADC_InitStructure);
/*ADC1regularchannel13configuration*/
ADC_RegularChannelConfig(ADC1,ADC_Channel_13,1,ADC_SampleTime_239Cycles5);
/*EnableADC1DMA*/
ADC_DMACmd(ADC1,ENABLE);
/*EnableADC1*/
ADC_Cmd(ADC1,ENABLE);
/*EnableADC1resetcalibarationregister*/
ADC_ResetCalibration(ADC1);
/*ChecktheendofADC1resetcalibrationregister*/
while(ADC_GetResetCalibrationStatus(ADC1));
/*StartADC1calibaration*/
ADC_StartCalibration(ADC1);
/*ChecktheendofADC1calibration*/
while(ADC_GetCalibrationStatus(ADC1));
/*StartADC1SoftwareConversion*/
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
LCD_Initialize();
LCD_ColorSet(0);
//0为256色模式,1为4096色模式
LCD_Clear(255,0);
//清屏
addset(0,0,103,81);
//设置起止坐标,4个参数依次为开始X,开始Y,结束x,结束Y
while
(1)
AD_value=ADC_GetConversionValue(ADC1);
/*{
{for(j=0;
20;
//PrintfmessagewithADvaluetoserialportevery1second
showdian(i,65-AD_value/63,0x03,255);
delayms(100);
}*/
/*******************************************************************************
*FunctionName:
RCC_Configuration
*Description:
Configuresthedifferentsystemclocks.
*Input:
None
*Output:
*Return:
*******************************************************************************/
voidRCC_Configuration(void)
{/*RCCsystemreset(fordebugpurpose)*/
RCC_DeInit();
/*EnableHSE*/
RCC_HSEConfig(RCC_HSE_ON);
/*WaittillHSEisready*/
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
/*HCLK=SYSCLK*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/*PCLK2=HCLK*/
RCC_PCLK2Config(RCC_HCLK_Div1);
/*PCLK1=HCLK/2*/
RCC_PCLK1Config(RCC_HCLK_Div2);
/*ADCCLK=PCLK2/4*/
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
/*Flash2waitstate*/
FLASH_SetLatency(FLASH_Latency_2);
/*EnablePrefetchBuffer*/
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/*PLLCLK=8MHz*9=56MHz*/
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
/*EnablePLL*/
RCC_PLLCmd(ENABLE);
/*WaittillPLLisready*/
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
/*SelectPLLassystemclocksource*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/*WaittillPLLisusedassystemclocksource*/
while(RCC_GetSYSCLKSource()!
=0x08)
/*Enableperipheralclocks--------------------------------------------------*/
/*EnableDMAclock*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
/*EnableADC
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- stm32 内部 AD 采样 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)