📄 time.c
字号:
#include "reg52.h"
#include "myopt.h"
#include "time.h"
unsigned int Count1msInc;
unsigned char Count1ms,Count10ms,Count1s;
unsigned char TimeSecond,TimeMinute;
/******************************************************************************
**timer0 init
**Value:
**Return Value:
**Parameters:
******************************************************************************/
void TIME0_Init()
{
Count10ms=10;
Count1s=0;
TMOD |= 0x01; /*16Bit 方式1 16位计数器/定时器*/
TR0 = 0;
TH0 = (-SYSCLK/1000/12) >> 8; /* set Timer0 to overflow in 1ms*/
TL0 = -SYSCLK/1000/12;
TR0 = 1;
IE|= 0x2;
}
/******************************************************************************
**timer0_interrupt interrupt 1
**Value:
**Return Value:
**Parameters:: 1ms overtime
******************************************************************************/
void timer0_interrupt(void) interrupt 1 /*1ms 溢出*/
{
TH0 = (-SYSCLK/1000/12) >> 8;
TL0 = -SYSCLK/1000/12;;
if (Count1ms) Count1ms--;
Count1msInc++;
if (Count10ms) Count10ms--;
else
{
Count10ms=10; /*10ms*/
GREEN =1;
if (Count1s) Count1s--;
else
{
GREEN =0;
Count1s=100; /*1s*/
TimeSecond++;
if (TimeSecond>=60)
{
TimeSecond=0; /*1min*/
TimeMinute++;
if (TimeMinute==60) TimeMinute=0;
}
}
}
}
/*just end*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -