📄 timer.c
字号:
#define Timer_c
#include "main.h"
//***********************
//定时器T2初始化,系统核心时钟,重要重要
void timer2_init(void)
{
TCCR2 = 0x00;//停止定时器
ASSR = 0x00;//异步时钟模式
TCNT2 = 0x10;//初始值
OCR2 = 0xF0;//匹配值
TIMSK |= 0x80;//中断允许
TCCR2 = 0x0D;//启动定时器 1024分频 33.333MS
}
//T2比较中断服务程序
//#pragma interrupt_handler timer2_comp_isr:5
//void timer2_comp_isr(void)
SIGNAL(SIG_OUTPUT_COMPARE2)
{
count50ms++;
if(count50ms==3)
{
count50ms=0;
time100ms=1;
// time100ms_n++;
count500ms++;
if(count500ms==5)
{
time500ms_n++;
count500ms=0;
time500ms=1;
count1s++;
if(count1s==2)
{
count1s=0;
time1s=1;
time1s_n++;
count3s++;
count30s++;
count1m++;
if(count3s==3)
{
count3s=0;
time3s=1;
}
if(count30s==30)
{
count30s=0;
time30s=1;
}
if(count1m==60)
{
count1m=0;
time1m=1;
count1h++;
if(count1h==60)
{
count1h=0;
time1h=1;
}
}
if(sms_t)//发送短信时,开始计时
{
count_time_out++;
if(count_time_out==15)
{
count_time_out=0;
timeout=1;
}
}
}
}
}
}
//定时器初始化
void timer (void)
{
//timer0_init();
timer2_init();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -