單片機(jī)實(shí)現(xiàn)adc0808程序
程序部分:
#include
unsigned char code dispbitcode[]={0x01,0x02,0x04,
0x08,0x10,0x20,0x40,0x80};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char dispbuf[3]={0,0,0};
unsigned char dispcount;
sbit ST=P3^2;
sbit OE=P3^0;
sbit EOC=P3^1;
unsigned char getdata;
void main(void)
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
TR0=1;
ET0=1;
EA=1;
P3_4=1;
P3_5=1;
P3_6=0;
while(1)
{
ST=0;
ST=1;
ST=0;
while(EOC==0);
OE=1;
getdata=P1;
OE=0;
dispbuf[2]=getdata/100;
dispbuf[1]=getdata%10/10;
dispbuf[0]=getdata%10;
}
}
void t0(void) interrupt 1 using 0
{static unsigned int nn;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
P2_0=0;
P0=dispcode[dispbuf[2]];
P2_0=1;
for(nn=0;nn<1000;nn++);
P2_1=0;
P0=dispcode[dispbuf[1]];
P2_1=1;
for(nn=0;nn<1000;nn++);
P2_2=0;
P0=dispcode[dispbuf[0]];
P2_2=1;
for(nn=0;nn<1000;nn++);
}
評(píng)論