标题:
89C51 ADC0808数模转换实验
[打印本页]
作者:
madaodexs
时间:
2020-4-6 21:15
标题:
89C51 ADC0808数模转换实验
#include "reg51.h"
unsigned char code tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char dat[4];
sbit clock=P1^4;
sbit start=P1^5;
sbit eoc=P1^6;
sbit oe=P1^7;
void delay(unsigned int s){
unsigned char i;
while(s--)for(i=0;i<200;i++);
}
void display(unsigned char a)
{
unsigned char c=0x01,i;
dat[3]=tab[a%10];dat[2]=tab[a%100/10];
dat[1]=tab[a/100];dat[0]=tab[a/1000];
for(i=0;i<4;i++){
P1=0xe0|c;
P0=dat[i];
c=c<<1;
delay(2);
}
return;
}
initial(){
TMOD=0x10;
TH1=0xff;
TL1=0x9C;
ET1=1;
EA=1;
TR1=1;
}
void main()
{
initial();
while(1){
start=0;
start=1;
start=0;
while(!eoc);
oe=1;
display(P2);
oe=0;
}
}
t0_int() interrupt 3
{
TH1=0xff;
TL1=0x9C;
clock=!clock;
}
复制代码
dpj3.png
(159.04 KB, 下载次数: 19)
下载附件
2020-4-6 21:14 上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1