新手上路
- 积分
- 39
- 金钱
- 39
- 注册时间
- 2015-10-15
- 在线时间
- 1 小时
|
5金钱
void Adc_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
//GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3 , ENABLE ); //????ADC1?¨???±??
RCC_ADCCLKConfig(RCC_PCLK2_Div6); //?è??ADC·????ò×?6 72M/6=12,ADC×??ó?±??????????14M
//PA1 ×÷???????¨??????????
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //????????????
//GPIO_Init(GPIOB, &GPIO_InitStructure);
ADC_DeInit(ADC3); //????ADC1
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC?¤×÷????:ADC1??ADC2?¤×÷??????????
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //????×????¤×÷?????¨??????
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //????×????¤×÷??????×???????
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //×??????í??????????????·?????
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC??????????
ADC_InitStructure.ADC_NbrOfChannel = 1; //???ò???????ò×?????ADC?¨????????
ADC_Init(ADC3, &ADC_InitStructure); //?ù??ADC_InitStruct?????¨???????????????èADCx???????÷
ADC_Cmd(ADC3, ENABLE); //???????¨??ADC1
ADC_ResetCalibration(ADC3); //??????????×?
while(ADC_GetResetCalibrationStatus(ADC3)); //??????????×??á??
ADC_StartCalibration(ADC3); //????AD??×?
while(ADC_GetCalibrationStatus(ADC3)); //??????×??á??
// ADC_SoftwareStartConvCmd(ADC1, ENABLE); //???????¨??ADC1???í??×???????????
}
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_3,10);
LCD_ShowxNum(156,130,adcx,4,16,0);//????ADC????
temp=(float)adcx*(3.3/4096);
adcx=temp;
LCD_ShowxNum(156,150,adcx,1,16,0);//??????????
temp-=adcx;
temp*=1000;
LCD_ShowxNum(172,150,temp,3,16,0X80);
LED0=!LED0;
delay_ms(250);
|
|