#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar flag,a;
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
}
void delay(uint um)
{
uchar x,y;
for(x=0;x<um;x++)
for(y=0;y<110;y++);
}
void display(uchar i)
{
uchar bai,shi,ge,p;
p=((i/256)*100+(i/16)*10+(i%16));// 转化部分,但只能输入一个两位数。一旦输入三位数就显示的不正确。
bai=p%100;
shi=p%100/10;
ge=p%10;
P2=1;
P0=table[bai];
delay(5);
P0=0xff;
P2=2;
P0=table[shi];
delay(5);
P0=0xff;
P2=3;
P0=table[ge];
delay(5);
P0=0xff;
}
void main()
{
init();
while(1)
{
if(flag==1)
{
ES=0;
SBUF=a;
while(!TI);
TI=0;
// ES=1;
flag=0;
ES=1;
}
display(a);
}
}
void ser() interrupt 4
{
// uchar temp;
RI=0;
a=SBUF;
flag=1;
} |