//—————————–
功用: ADC0809完成8路模拟信号轮番转化,而且
在数码管上显示出来;
1、P1口作为数码管的段码操控端,
P2口作为数码管的位码操控端,
2、P2。7口作为转化发动信号
0809的RD,WR别离与8051的相应端衔接,
当它有用时,写时写的是地址,
读时读的是数据;
3、0809的A0,A1,A2和D0–D1都接在P0口。
#include
#define uint unsigned int
#define uchar unsigned char
sbit start=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar num1,num2,num3,flag;
uchar aa,bb;
void delay();
void disp();
void ad0809();
void main()
{
SMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
uchar ad[8]={};
while(1)
{
if(flag==1)
{
ad0809();
flag=0;
}
disp();
}
}
//===================
void delay(uint z)
{
uint x;
uchar y;
for(x=0;x
}
//=====================
void disp()
{ uchar i;
for(i=0;i<8;i++)
{
P1=table[i];
P2=0x7e;
delay(5);
P1=0;
delay(1);
P1=table[10];
P2=0x7d;
delay(5);
P1=0;
delay(1);
P1=table[ad[i]/100];
P2=0x7b;
delay(5);
P1=0;
delay(1);
P1=table[ad[i]%100/10];
P2=0x77;
delay(5);
P1=0;
delay(1);
P1=table[ad[i]%10];
P2=0x6f;
delay(5);
P1=0;
delay(1);
}
}
//===================
void ad0809()
{
uchar j;
for(j=0;j<8;j++)
{
start=0;
P1=j;
start=1
delay(1);
start=0;
P1=ad[j];
start=1;
delay(1);
start=0;
}
}
//=======================
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{
aa=0;
flag=1;
}
}