#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,second,tab1[2],TOH = 0,TOL = 0;
bit flag = 0;
unsigned char code Tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
void display( )
{
static uchar i = 0;
P0 = 0xff;
P2 = ~(0x01 << i);
P0 = Tab[tab1[i]];
if ( i< 1)
i++;
else
i = 0;
}
//定時函數
void Timer( uchar t)
{
unsigned long temp;
temp = 11059200 / 12;
temp = (temp * t) / 1000;
temp = 65536 - temp;
TOH = (uchar)(temp >> 8);
TOL = (uchar)temp;
TH0 = TOH;
TL0 = TOL;
TMOD &= 0XF0;
TMOD |= 0X01;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void main(void)
{
Timer(1); //定時一毫秒
second=60;
tab1[0] = second / 10;
tab1[1] = second % 10;
while(1)
{
if(flag) //一秒鐘就減一次
{
flag = 0;
second--;
tab1[0] = second / 10;
tab1[1] = second % 10;
if (second == 0)
second = 60;
}
}
}
void timer0(void) interrupt 1
{
static unsigned int num = 0;
TH0 = TOH;
TL0 = TOL;
display();
num++;
if(num>= 1000) //一秒鐘就減一次
{
num = 0;
flag = 1;
}
}
|