//99分倒计时
#include"stc8H.h"
#include "intrins.h"
#include "daojishi.h"
#include "GPIO_init.h"
#define uint unsigned int
#define uchar unsigned char
#define ET3 0x20
#define ET4 0x40
#define T3IF 0x02
#define T4IF 0x04
sbit jiare_ge = P0^2;
sbit jiare_shi = P0^3;
sbit lenque_ge = P1^0;
sbit lenque_shi = P1^1;
sbit sajun_ge = P1^2;
sbit sajun_shi = P1^3;
//sbit LIGHT_JDQ = P3^7;
uchar count;
char sec,min;
bit flag,flag1,flag2,flag3;
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 T0_init() //5毫秒@11.0592MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初始值
TH0 = 0xEE; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
}
void T1_init() //5毫秒@11.0592MHz
{
AUXR &= 0xBF; //定时器时钟12T模式
TMOD &= 0x0F; //设置定时器模式
TL1 = 0x00; //设置定时初始值
TH1 = 0xEE; //设置定时初始值
TF1 = 0; //清除TF0标志
TR1 = 1; //定时器0开始计时
ET1 = 1; //使能定时器0中断
}
void T3_init() //5毫秒@11.0592MHz
{
T4T3M &= 0xFD; //定时器时钟12T模式
T3L = 0x00; //65536-11.0592M/12/1000
T3H = 0xEE;
IE2 = ET3; //使能定时器中断
T4T3M |= 0x08; //定时器3开始计时
}
void T4_init() //5毫秒@11.0592MHz
{
T4T3M &= 0xDF; //定时器时钟12T模式
T4L = 0x00; //65536-11.0592M/12/1000
T4H = 0xEE;
T4T3M = 0x80; //启动定时器
IE2 = ET4; //使能定时器中断
}
void jiare_display()
{
static bit i=0;
static uchar temp=0;
P2=0xff;
i=~i;
if(++temp>=200)temp=0;
if(i==1)
{
jiare_ge = 0;
jiare_shi = 1;
P2=table[min/10];
}
else
{
jiare_ge = 1;
jiare_shi = 0;
if(temp<100)
P2=table[min%10]&0xfe;//闪秒
else P2=table[min%10];
}
}
void lenque_display()
{
static bit i=0;
static uchar temp=0;
P2=0xff;
i=~i;
if(++temp>=200)temp=0;
if(i==1)
{
lenque_ge = 0;
lenque_shi = 1;
P2=table[min/10];
}
else
{
lenque_ge = 1;
lenque_shi = 0;
if(temp<100)
P2=table[min%10]&0xfe;//闪秒
else P2=table[min%10];
}
}
void sajun_display()
{
static bit i=0;
static uchar temp=0;
P2=0xff;
i=~i;
if(++temp>=200)temp=0;
if(i==1)
{
sajun_ge = 0;
sajun_shi = 1;
P2=table[min/10];
}
else
{
sajun_ge = 1;
sajun_shi = 0;
if(temp<100)
P2=table[min%10]&0xfe;//闪秒
else P2=table[min%10];
}
}
void jiare_daojishi()
{
T0_init();
while(1)
{
if(flag)
{
flag=0;
if(++count >= 200)
{
count = 0;
sec--;
if(sec < 0)
{
sec = 59;
min--;
if(min < 0)
min=99;
}
}
jiare_display();
}
}
}
void lenque_daojishi()
{
T1_init() ;
while(1)
{
if(flag1)
{
flag1=0;
if(++count >= 200)
{
count = 0;
sec--;
if(sec < 0)
{
sec = 59;
min--;
if(min < 0)
min=99;
}
}
lenque_display();
}
}
}
void sajun_daojishi()
{
T3_init();
while(1)
{
if(flag2)
{
flag2=0;
if(++count >= 200)
{
count = 0;
sec--;
if(sec < 0)
{
sec = 59;
min--;
if(min < 0)
min=99;
}
}
sajun_display();
}
}
}
void daojishi()
{
GPIO_init();
EA = 1;
T4_init();
while (1)
{
jiare_daojishi();
lenque_daojishi();
sajun_daojishi();
}
}
void TM0_Isr() interrupt 1 //5毫秒定时器0
{
TL0 = 0x00; //设置定时初始值
TH0 = 0xEE; //设置定时初始值
flag=1;
}
void TM1_Isr() interrupt 3 //5毫秒定时器1
{
TL1 = 0x00; //设置定时初始值
TH1 = 0xEE; //设置定时初始值
flag1=1;
}
void TM3_Isr() interrupt 19 //5毫秒定时器3
{
TL1 = 0x00; //设置定时初始值
TH1 = 0xEE; //设置定时初始值
flag2=1;
}
void TM4_Isr() interrupt 20 //定时器4
{
TL1 = 0x00; //设置定时初始值5ms
TH1 = 0xEE; //设置定时初始值
flag3=1; //测试端口
} |