//99分倒计时
#include"stc8.h"
#include"intrins.h"
#define uint unsigned int
#define uchar unsigned char
uchar A1,A2,count,second,min;
sbit ge = P1^1;
sbit shi = P1^0;
sbit LIGHT_JDQ = P3^7;
uchar code table[]={
0x03,/*0*/
0x9F,/*1*/
0x25,/*2*/
0x0D,/*3*/
0x99,/*4*/
0x49,/*5*/
0x41,/*6*/
0x1F,/*7*/
0x01,/*8*/
0x09,/*9*/};
//sbit a = P2^7;
//sbit b = P2^6;
//sbit c = P2^5;
//sbit d = P2^4;
//sbit e = P2^3;
//sbit f = P2^2;
//sbit g = P2^1;
//sbit h = P2^0;
//sbit LED_com = P3^1;
void IO_init();
void delay(uchar i);
void T0_init();
void display(uchar sh_c,uchar g_c);
void IO_init()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
}
void delay(uchar n)
{
uchar j,k;
for(j=n;j>0;j--)
for(k=125;k>0;k--);
}
void T0_init()
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xD7; //设置定时初始值50us
TH0 = 0xFD; //设置定时初始值
TR0 = 1; //启动定时器
ET0 = 1; //使能定时器中断
EA = 1;
}
void display(uchar sh_c,uchar g_c)
{
P2=0;
P2=table[sh_c];
ge = 0;
shi = 1;
delay(5);
P2=0;
P2=table[g_c];
shi = 0;
ge = 1;
delay(5);
}
void main()
{
IO_init();
T0_init();
while(1)
{
if(count = 0)
count = 20;
second--;
if(second = 0)
second = 60;
min--;
if(min = 0)
min=99;
A1=min/10;
A2=min%10;
display(A1,A2);
}
}
void TM0_Isr() interrupt 1
{
TL0 = 0xD7; //设置定时初始值50us
TH0 = 0xFD; //设置定时初始值
count--;
}
|