#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit aa=P2^0;
sbit bb=P2^1;
sbit cc=P2^2;
uint sec=0;
uchar cnt=0;
uchar i=0;
signed char k;
uchar code smgchar[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar smgbuf[]={0xff,0xff,0xff,0xff};
uchar buf[4];
void smgdisplay();
void main()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
while(1)
{
smgdisplay();
}
}
void smgdisplay()
{
if(cnt>=20)
{
cnt=0;
sec++;
buf[0]=sec%10;
buf[1]=sec/10%10;
buf[2]=sec/100%10;
buf[3]=sec/1000%10;
for(k=4;k>=1;k--)
{
if(buf[k]==0)
{
smgbuf[k]=0xff;
}
else
break;
}
for(;k>=0;k--)
{
smgbuf[k]=smgchar[buf[k]];
}
}
P0=0x00;
switch(i)
{
case 0 :aa=1;bb=1;cc=1;i++;P0=smgbuf[0];break;
case 1 :aa=0;bb=1;cc=1;i++;P0=smgbuf[1];break;
case 2 :aa=1;bb=0;cc=1;i++;P0=smgbuf[2];break;
case 3 :aa=0;bb=0;cc=1;i=0;P0=smgbuf[3];break;
default:break;
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
cnt++;
}
|