问题如题
程序如下
#define F_CPU 8000000UL #include<avr/io.h> #include<util/delay.h> #define INT8U unsigned char #define INT16U unsigned int const INT8U SEG_CODE[]={0XC0,0Xf9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XFF}; INT8U Display_Buffer[]={0,0,0,10,}; INT8U i; void ADC_Convert() { int Result; ACSR=0X80; ADCSRA=0X00; ADCSRA=0XC6; ADCSRB=0X00; ADMUX=0XC6; _delay_us(100); if (!(ADCSRA&(ADIF<<1))) { Result=ADCH*110/1023; Display_Buffer[0]=Result/100; Display_Buffer[1]=Result%100/10; Display_Buffer[2]=Result%10; for(i=0;i<4;i++) { PORTD=0xff; PORTB=_BV(i); PORTD=SEG_CODE[Display_Buffer]; if(i==0) PORTD&=0X7f; _delay_ms(4); } ADCSRA|=ADIF<<1; } } int main() { DDRD=0XFF;PORTD=0XFF; DDRB=0X0F;PORTB=0X00; _delay_ms(256); while(1) { ADC_Convert(); } }
电路如下 仿真时候总是显示0.00
|