#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
uchar num[4];
uchar temp,result;
sbit OE=P3^7;
sbit EOC=P3^2;
sbit CLK=P3^5;
sbit ST=P3^6;
sbit P17=P1^7;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x01;
TH0=(65536-200)/256;
TL0=(65536-200)%256;
EA=1;
ET0=1;
TR0=1;
}
void display()
{
P2=0xfe;
P1=table[num[3]];
delayms(5);
P2=0xfd;
P1=table[num[2]];
P17=1;
delayms(5);
P2=0xfb;
P1=table[num[1]];
delayms(5);
P2=0xf7;
P1=table[num[0]];
delayms(5);
}
void main()
{
init();
while(1)
{
ST=0;
OE=0;
ST=1;
ST=0;
while(EOC==0);
OE=1;
temp=P0;
OE=0;
result=temp*1.0/255*500;
num[0]=result%10;
num[1]=result/10%10;
num[2]=result/100%10;
num[3]=result/1000;
display();
}
}
void time0()interrupt 1
{
TH0=(65536-200)/256;
TL0=(65536-200)%256;
CLK=~CLK;
}
不是很懂 你可以帮我解释下这个式子?谢谢