求80C51单片机将模拟量通过A⼀D转换成数字量,并显示在数码管上的程序??

2024-12-04 14:22:20
推荐回答(1个)
回答1:

//0809 CLK接总线ALE
#include
#define uint unsigned int
#define uchar unsigned char
void delay(uint x);
void duxie();
sbit CS=P3^0;
sbit W=P3^6;
sbit R=P3^7;
uchar getdata;
uchar code duankong[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xd8,0x80,0x90};
uchar code weikong[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar df[3];
void msec(unsigned int x); //延时子程序

main()
{
uchar k;
CS=1;
while(1)
{ duxie();
for(k=0;k<=2;k++)
{
P1=duankong[df[k]];
P2=weikong[k];
delay(100) ;
}
}
}

void delay(uint x)
{
uchar j;
while ((x--)!=0)
{
for(j=0;j<2;j++)
{}
}
}
void duxie()
{ uchar j;
CS=0;
W=0; //开始转换
delay(100);
W=1;
delay(100);
R=0;
delay(100);
R=1;
delay(100);
getdata=P0;
df[2]=getdata/100;
df[1]=getdata%100/10;
df[0]=getdata%10;
for(j=0;j<8;j++) ;
}