//60s倒计时
#include"stc8.h"
#include "intrins.h"
#define uint unsigned int
#define uchar unsigned char
#define SEG P1
sbit SCON1 = P3^7;
sbit SCON2 = P3^6;
sbit KEY = P3^2;
uchar count=0;
char num=60,ge,shi;
uchar flag;
uchar code table[]={
0x03,/*0*/
0x9F,/*1*/
0x25,/*2*/
0x0D,/*3*/
0x99,/*4*/
0x49,/*5*/
0x41,/*6*/
0x1F,/*7*/
0x01,/*8*/
0x09,/*9*/};
void T0_init() //5毫秒@11.0592MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x00; //设置定时初始值
TH0 = 0xEE; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1;
ET0 = 1; //使能定时器0中断
EA = 1;
}
void IO_init()
{
P3M0 = 0x00; P3M1 = 0x00;
P1M0 = 0xff; P1M1 = 0x00;
}
void TM0_Isr() interrupt 1 //5毫秒
{
TL0 = 0x00; //设置定时初始值
TH0 = 0xEE; //设置定时初始值
flag++;
if (flag=20)
{
flag=0;
num--;
if (flag=0)
{
flag=60;
}
}
}
void main()
{
IO_init();
T0_init() ;
while (1)
{
SEG=0xff;
shi=num/10;
ge=num%10;
switch (count)
{
case0:SCON1 = 0;SCON2=1; SEG = table[ge];
break;
case1:SCON1 = 1;SCON2=0; SEG = table[shi];
break;
default:
break;
}
count++;
if (count>1)count=0;
}
}
|