#include <STC12C5A60S2.H>
#define ENLED P11
#define Interrupt
unsigned char code LedChar[10] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char LedBuff[6] =
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
void T0init()
{
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = 0xF5;
TR0 = 1;
EA = 1;
ET0 = 1;
TF0 = 0;
}void LED_Scan(unsigned long sec)
{
static unsigned char i = 0;
unsigned char j = 6;
while(j)
{
LedBuff[j-1] = LedChar[sec%10];
sec /= 10;j--;
}
P2 = ~0x07;
P2 |= i%6;
P0 = LedBuff[(i++)%6];
}void main()
{
T0init();
ENLED = 0;
while(1)
{
#ifndef Interrupt
void TF0_Scan();
TF0_Scan();
#endif
}
}
#ifdef Interrupt
void interrupt_Scan() interrupt 1
{
static unsigned int cnt = 0;
static unsigned long sec = 0;
TF0 = 0;
TH0 = 0xF5;
TL0 = 0x95;
cnt++;
if(cnt >=999)
{
cnt = 0;
sec++;
if(sec >9)
{
P13=0;sec=0;
}
}
LED_Scan(sec);
}
#else void TF0_Scan()
{
static unsigned int cnt = 0;
static unsigned long sec = 0;
if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xF5;
TL0 = 0x95;
cnt++;
if(cnt >= 999)
{
cnt = 0;
sec++;
if(sec > 9)
{
P13=0;
sec=0;
}
}
LED_Scan(sec);
}
}
#endif
|