ADC0809模数转换器
扫描二维码
随时随地手机看文章
#include< reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa,qian,bai,shi,ge;
uint temp;
sbit clock=P2^0;
sbit start=P2^1;
sbit eoc=P2^2;
sbit oe=P2^3;
sbit ale=P2^4;
sbit adda=P2^5;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
//void display(uchar bai,uchar shi,uchar ge);
void delay(uint z);
void main()
{
TMOD=0x20; //设置定时器1为工作方式2
TH1=0x216; //216
TL1=0x216; //216
EA=1; //开总中断
ET1=1; //开t1中断
TR1=1;
start=0; //复位
oe=0; //输出
adda=0;
//eoc=0;
ale=0; //关闭地址选择
while(1)
{
start=0;
///delay(10);
start=1; // 复位
ale=1; // 打开地址选择
adda=0;
///delay(10);
start=0; // 开始转换
ale=0; // 关地址
//delay(1);
while(eoc==0); // 等待eoc变为1
//delay(1);
oe=1; // 打开输出
//delay(1);
//P1=0xff;
temp=P1; // 取p1到p3
oe=0; // 关输出
temp=temp*50;
temp=temp/256;
qian=temp/1000;
bai=temp%1000/100;
shi=temp%100/10;
ge=temp%10;
P3=0x00;
P0=0xfe;
P3=table[qian];
delay(50);
P3=0x00;
P0=0xfd;
P3=table[bai];
delay(50);
P3=0x00;
P0=0xfb;
P3=table[shi];
delay(50);
P3=0x00;
P0=0xf7;
P3=table[ge];
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=1;y>0;y--);
}
void cl() interrupt 3
{
clock=!clock;
}