📄 timer.c
字号:
#include "timer.h"
#include "main.h"
#include "1602.h"
#include "KEYS.h"
unsigned char time_1s_ok=0;
unsigned int year;
volatile unsigned char week=2,second,minute=0,hour,day=6,month=6; //分别保存秒、分、时、天、月、年的变量
unsigned char counter_50ms=0; //保存多少个50毫秒的变量
unsigned char days_of_month; //保存该月多少天的变量
void Count_1_interrup(void) interrupt 3 //定时器0中断处理函数
{
EA=1; //允许定时器0中断
TL1=0xF0;
TH1=0xD8;
ScanKey();
}
void timer0_isr(void) interrupt 1 using 1 //定时器0中断处理函数
{
TL0=0xB9;
TH0=0x40; //定时器重装。定时50mS中断一次
if(++counter_50ms>=20) //1秒到
{
time_1s_ok=1;
counter_50ms=0; //清50毫秒计数
second++; //秒加1
if(second==60) //如果秒到60
{
second=0; //秒清0
minute++;
//分加1
if(minute==60) //如果分到60
{
minute=0; //分清0
hour++; //小时加1
if(hour==24) //如果小时到24
{
hour=0; //小时清零
week++;
if(week>7)
week=1;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:if(++day>31)
{
day=1;
if((++month>12)||(month==0))
{
month=1;
++year;
}
}
break;
case 4:
case 6:
case 9:
case 11:if(++day>30)
{
day=1;
if((++month>12)||(month==0))
{
month=1;
++year;
}
}
break;
case 2:
if(((year%4)==0)&&((year%100)!=0))
{
if(++day>29)
{
day=1;
if((++month>12)||(month==0))
{
month=1;
++year;
}
}
}
else
{
if(++day>28)
{
day=1;
if((++month>12)||(month==0))
{
month=1;
++year;
}
}
}
break;
default:break;
} //天置1
}
}
}
}
}
void display_time(void)
{
WriteCommandLCM(0x80,0);
LCD_printc(year/1000%10+48);
LCD_printc(year/100%10+48);
LCD_printc(year/10%10+48);
LCD_printc(year%10+48);
LCD_printc('-');
LCD_printc(month/10%10+48);
LCD_printc(month%10+48);
LCD_printc('-');
LCD_printc(day/10%10+48);
LCD_printc(day%10+48);
WriteCommandLCM(0x8c,1);
switch(week)
{
case 1:LCD_prints("Mon.");break;
case 2:LCD_prints("Tue.");break;
case 3:LCD_prints("Wed.");break;
case 4:LCD_prints("Thu.");break;
case 5:LCD_prints("Fri.");break;
case 6:LCD_prints("Sat.");break;
case 7:LCD_prints("Sun.");break;
default:break;
}
WriteCommandLCM(0x80+0x40,1);
LCD_printc(' ');//用来清除闹钟标识
LCD_printc(' ');
LCD_printc(hour/10%10+48);
LCD_printc(hour%10+48);
LCD_printc(':');
LCD_printc(minute/10%10+48);
LCD_printc(minute%10+48);
LCD_printc(':');
LCD_printc(second/10%10+48);
LCD_printc(second%10+48);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -