#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define unit unsigned int
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x90};
sbit fir=P3^0;
sbit sec=P3^1;
sbit thr=P3^2;
sbit fur=P3^3;
sbit dian=P2^7;
sbit ADO=P1^0;
sbit ADCS= P1^1;
sbit ADCLK=P1^2;
void delay(int t)
{
int x,y;
for(x=t;x>0;x--)
for(y=30;y>0;y--);
}
unsigned char TLC549ADC(void)
{
unsigned char i,num=0;
ADCLK=0;
ADO=1;
ADCS=0;
for(i=0;i<8;i++)
{
ADCLK=1;
_nop_();
_nop_();
num <<=1;
if(ADO==1) num=num+1;
ADCLK=0;
}
ADCS=1;
return(num);
}
void main()
{
int tmp;
float num,tmp1;
ADCS=1;
while(1)
{
num=TLC549ADC();
tmp1=num*100/51;
tmp=(int)tmp1;
P2=table[tmp/100];
dian=0;
fir=1;
delay(60);
fir=0;
dian=1;
P2=table[tmp%100/10];
sec=1;
delay(60);
sec=0;
P2=table[tmp%10];
thr=1;
delay(60);
thr=0;
P2=table[0];
fur=1;
delay(60);
fur=0;
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520205134101.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDI3MDE5NA==,size_16,color_FFFFFF,t_70)
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define unit unsigned int
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x90};
sbit fir=P3^0;
sbit sec=P3^1;
sbit thr=P3^2;
sbit fur=P3^3;
sbit dian=P2^7;
sbit ADO=P1^0;
sbit ADCS= P1^1;
sbit ADCLK=P1^2;
sbit led=P1^7;
void delay(int t)
{
int x,y;
for(x=t;x>0;x--)
for(y=30;y>0;y--);
}
unsigned char TLC549ADC(void)
{
unsigned char i,num=0;
ADCLK=0;
ADO=1;
ADCS=0;
for(i=0;i<8;i++)
{
ADCLK=1;
_nop_();
_nop_();
num <<=1;
if(ADO==1) num=num+1;
ADCLK=0;
}
ADCS=1;
return(num);
}
void main()
{
int tmp;
float num,tmp1;
ADCS=1;
while(1)
{
num=TLC549ADC();
tmp1=num*100/51;
tmp=(int)tmp1;
if(tmp>333)
{
led=1;
}
else
{
led=0;
}
P2=table[tmp/100];
dian=0;
fir=1;
delay(60);
fir=0;
dian=1;
P2=table[tmp%100/10];
sec=1;
delay(60);
sec=0;
P2=table[tmp%10];
thr=1;
delay(60);
thr=0;
P2=table[0];
fur=1;
delay(60);
fur=0;
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520205234374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDI3MDE5NA==,size_16,color_FFFFFF,t_70)