仿照正点原子的ADC实验,请问一下我采集传感器信息,在AD值在LCD显示和通过串口查看,结果会不一样的?如AD显示为2203,串口才输出1987?(串口输出代码)
[mw_shl_code=c,true]int main(void)
{
u16 adcx;
float temp;
u16 adcx1;
float temp1;
float temperature1;
float temperature2;
u16 te1;
u16 te2;
delay_init(); //???±??????????
NVIC_Configuration(); //?è??NVIC????·?×é2:2??????????????2???ì????????
uart_init(9600); //?®??????????9600
LED_Init(); //LED??????????
Adc_Init(); //ADC??????
while(1)
{
//ADC1 ?????¨??????PA1
adcx=Get_Adc_Average(ADC_Channel_1,10);
temperature1=(float)((adcx-1833.632)/6.842);
temperature1=temperature1*1000;
te1=temperature1;
printf("temperature1:%d",te1); //?????????? ?¨?à????1000?©
printf("C\r\n");
printf("ADC_CH1_VAL:%d",Get_Adc_Average(ADC_Channel_1,10)); //??????????
printf("L\r\n");
temp=(float)adcx*(3.3/4096);
temp=temp*1000;
adcx=temp;
printf("ADC_CH1_VOL:%d",adcx); //???????????¨?à????1000?©
printf("V\r\n");
//ADC1 ?????¨??????PA2
adcx1=Get_Adc_Average(ADC_Channel_2,10);
temperature2=(float)((adcx1-1833.632)/6.842);
temperature2=temperature2*1000;
te2=temperature2;
printf("temperature2:%d",te2);
printf("C\r\n");
printf("ADC_CH2_VAL:%d",Get_Adc_Average(ADC_Channel_2,10));
printf("L\r\n");
temp1=(float)adcx1*(3.3/4096);
temp1=temp1*1000;
adcx1=temp1;
printf("ADC_CH2_VOL:%d",adcx1);
printf("V\r\n");
LED0=!LED0;
delay_ms(250);
}[/mw_shl_code]
LCD显示AD代码
[mw_shl_code=c,true]int main(void)
{
u16 adcx;
float temp;
u16 adcx1;
float temp1;
float temperature1;
float temperature2;
u16 te1;
u16 te2;
delay_init(); //???±??????????
NVIC_Configuration(); //?è??NVIC????·?×é2:2??????????????2???ì????????
uart_init(9600); //?®??????????9600
LED_Init(); //LED??????????
LCD_Init();
Adc_Init(); //ADC??????
POINT_COLOR=RED;//?è??×??????ì??
LCD_ShowString(60,50,200,16,16,"WarShip STM32");
LCD_ShowString(60,70,200,16,16,"ADC TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2012/9/7");
//?????á??????
POINT_COLOR=BLUE;//?è??×?????????
LCD_ShowString(60,130,200,16,16,"ADC_CH1_VAL:");
LCD_ShowString(60,150,200,16,16,"ADC_CH1_VOL:0.000V");
LCD_ShowString(60,170,200,16,16,"temperature:00.000C");
//?????á??????
POINT_COLOR=RED;//?è??×??????ì??
LCD_ShowString(60,190,200,16,16,"ADC_CH2_VAL:");
LCD_ShowString(60,210,200,16,16,"ADC_CH2_VOL:0.000V");
LCD_ShowString(60,230,200,16,16,"temperature:00.000C");
while(1)
{
POINT_COLOR=BLUE;//?è??×?????????
adcx=Get_Adc_Average(ADC_Channel_1,10);
temperature1=(float)((adcx-1833.632)/6.842);
te1=temperature1;
LCD_ShowxNum(156,170,te1,2,16,0);//??????????
temperature1-=te1;
temperature1*=1000;
LCD_ShowxNum(180,170,temperature1,1,16,0X80);
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);
POINT_COLOR=RED;//?è??×??????ì??
adcx1=Get_Adc_Average(ADC_Channel_2,10);
temperature2=(float)((adcx1-1833.632)/6.842);
te2=temperature2;
LCD_ShowxNum(156,230,te2,2,16,0);//??????????
temperature2-=te2;
temperature2*=1000;
LCD_ShowxNum(180,230,temperature2,1,16,0X80);
LCD_ShowxNum(156,190,adcx1,4,16,0);//????ADC????
temp1=(float)adcx1*(3.3/4096);
adcx1=temp1;
LCD_ShowxNum(156,210,adcx1,1,16,0);//??????????
temp1-=adcx1;
temp1*=1000;
LCD_ShowxNum(172,210,temp1,3,16,0X80);
LED0=!LED0;
delay_ms(250);
}
}
[/mw_shl_code]
|