做智能寻迹小车的时候写了一个AD转换的函数,可为什么转换的结果相同?#include#include#define uchar unsigned char #define uint unsigned int #pragma interrupt_handler ADC_average:22uchar leddata[]={ 0xC0, //"0" 0xF9, //"1" 0xA4, //"2" 0xB0, //"3" 0x99, //"4" 0x92, //"5" 0x82, //"6" 0xF8, //"7" 0x80, //"8" 0x90, //"9" 0x88, //"A" 0x83, //"B" 0xC6, //"C" 0xA1, //"D" 0x86, //"E" 0x8E, //"F" 0x89, //"H" 0xC7, //"L" 0xC8, //"n" 0xC1, //"u" 0x8C, //"P" 0xA3, //"o" 0xBF, //"-" 0xFF, //ϨÃð 0xFF //×Ô¶¨Òå };uint ADC_value;uchar convert_times=0;uint convert_sum=0;//=========================================//ADC//=========================================void ADC_init(){ADCSRA=BIT(ADEN)|BIT(ADFR)//ADCʹÄÜ£¬Á¬Ðøת»»|BIT(ADIE)|BIT(ADPS2)//ADCÖжÏʹÄÜ|BIT(ADPS1)|BIT(ADPS0);//·ÖƵÒò×ÓΪ128}void ADC_start(uchar num){//ADMUX=num|BIT(REFS1)|BIT(REFS0);//²Î¿¼µçѹΪƬÄÚ»ù×¼µçѹԴ2.56VADMUX=num;SREG|=0X80;ADCSRA|=BIT(ADSC);//¿ªÊ¼×ª»»convert_times=0;convert_sum=0;}void ADC_average(){if(convert_times==5){convert_times=0;convert_sum=0;}convert_times++;convert_sum+=ADCL+(ADCH<<8);if(convert_times==5){ADC_value=convert_sum/5;}}//==========================================================void IO_init(){DDRB=0X0F|BIT(5)|BIT(6);//motor_speed_setDDRF=0;//sensorDDRF|=BIT(1)|BIT(2);//displayPORTF=0B11110111;DDRA=0XFF;DDRC=0XFF; //ÊýÂë¹Ü¶ÎÂë¿ØÖƶ˿ÚÉèΪÊä³ö}//==========================================================void display(uint num){uint i,j,temp;temp=num;for(i=0;i<4;i++){j=temp%10;PORTC=leddata[j];PORTA=BIT(7-i);delay_ms(1);temp/=10;} }//===========================================================void delay_ms(uchar num){uint i;for( ;num!=0;num--)for(i=0;i<1000;i++){asm("nop");}}//==========================================================void sensor_test(){ uint i,j; ADC_init(); ADC_start(5); while(convert_times<5); i=ADC_value; for(j=0;j<500;j++){display(i);}for(j=0;j<500;j++){display(9999);}ADC_init(); ADC_start(5); while(convert_times<5); i=ADC_value; for(j=0;j<500;j++){display(i);}}void main(){IO_init();sensor_test();} |