我做的是一个万年历,有调整、闹钟、秒表、倒计时的功能。现在是秒表和倒计时不能用,按确定键应该可以开始秒表计时,可是就是没动静,我把相关程序发上来,求高手帮忙解决,万分感谢。
#include "SYSTEM.H"
#define KEY P2
SYSTEMTIME CurrentTime;
sbit tz=KEY^0;
sbit jia1=KEY^1;
sbit jian1=KEY^2;
sbit miaob=KEY^3;
sbit naoz=KEY^4;
sbit daojs=KEY^5;
sbit zs=KEY^6;
sbit qued=KEY^7;
sbit fmq=P1^3;
unchar slect;//调整按键次数变量
unchar bdata b;//确定按键变量(秒表模块)
unchar bdata c;//确定按键变量(倒计时模块)
unchar flag;//状态变量
unchar fanh;//返回显示时间标志位
char dshour,dsmin,dssec;
unchar timer1h,timer1l;
unchar count;//循环5ms次数
char fen,miao,ms;
char daojsh,daojsm,daojss;
/*********************************************
*名称:timer0() interrupt 1
*功能:中断5ms
*输入:无
*输出:无
**********************************************/
void timer0(void) interrupt 1
{
TF0=0;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
count++;
}
以下是Read_key()程序的一部分
if(miaob==0)//秒表状态
{
delay(10);
if(miaob==0)
{
while(!miaob);
flag=3;
lcd_pos(5,1);
prints("00:00:00");
ms=miao=fen=0;
slect=0;
}
}
if(daojs==0)//倒计时状态
{
delay(10);
if(daojs==0)
{
while(!daojs);
flag=4;
lcd_pos(5,1);
prints("00:00:00");
CurrentTime.Second=0;
CurrentTime.Minute=0;
CurrentTime.Hour=0;
slect=1;
}
}
if(qued==0)
{
delay(10);
if(qued==0)
{
while(!qued);
lcd_wcmd(0x0c);
if(flag==1)
{
stop_time(1);
DS1302_SetTime(DS1302_SECOND,CurrentTime.Second);
DS1302_SetTime(DS1302_MINUTE,CurrentTime.Minute);
DS1302_SetTime(DS1302_HOUR,CurrentTime.Hour);
DS1302_SetTime(DS1302_DAY,CurrentTime.Day);
DS1302_SetTime(DS1302_MONTH,CurrentTime.Month);
DS1302_SetTime(DS1302_YEAR,CurrentTime.Year);
DS1302_SetTime(DS1302_WEEK,CurrentTime.Week);
slect=0;
}
if(flag==2)
{
dshour=CurrentTime.Hour;
dsmin=CurrentTime.Minute;
dssec=CurrentTime.Second;
slect=0;
}
if(flag==3)
{
b=~b;
if(b==0)TR0=1;
else {TR0=0;count=0;}
}
if(flag==4)
{
daojsh=CurrentTime.Hour;
daojsm=CurrentTime.Minute;
daojss=CurrentTime.Second;
slect=0;
c=~c;
if(c==0)TR0=1;
else {TR0=0;count=0;}
}
}
}
if(count)
{
if(flag==3)
{
if(count==2)
{
count=0;
ms++;
if(ms==100)
{
ms=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
lcd_pos(5,1);
printc(fen/10+'0');
lcd_pos(6,1);
printc(fen%10+'0');
}
lcd_pos(8,1);
printc(miao/10+'0');
lcd_pos(9,1);
printc(miao%10+'0');
}
lcd_pos(11,1);
printc(ms/10+'0');
lcd_pos(12,1);
printc(ms%10+'0');
}
}
if(flag==4)
{
if(count==200)
{
count=0;
daojss--;
if(daojss==-1)
{
daojss=59;
daojsm--;
if(daojsm==-1)
{
daojsm=59;
daojsh--;
lcd_pos(5,1);
printc(daojsh/10+'0');