C:Documents and Settingscui桌面#include<avr/io.h>
#include<util/delay.h>
int tab[]={0x3c,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x00};
void see()
{int a,qw,bw,sw,gw;
a=(int)(ADC*5000.0/1024.0);
qw=a/1000;
bw=(a%10)/100;
sw=(a%100)/10;
gw=(a%1000);
PORTD=0x00;PORTC=tab[qw];PORTC&=0x7F;
PORTD=0x02;PORTC=tab[bw];
PORTD=0x04;PORTC=tab[sw];
PORTD=0x06;PORTC=tab[gw];
}
int main()
{DDRC=0xFF;PORTC=0x00;
DDRD=0xFF;PORTD=0x00;
DDRA=0x00;PORTA=0x00;
ADCSRA=0xE6;ADMUX=0x40;
_delay_ms(10);
while(1);
{PORTC=0x00;
see();_delay_ms(1);}
}
此帖出自
小平头技术问答
一周热门 更多>