📄 timer.c
字号:
#include<reg51.h> //定时
#include<absacc.h>
#include<timer.h>
WORD count_timer1; //定时器记数变量
WORD count_timer0;
void timer1_init(WORD time_var)
{
//P1=0x0f;
count_timer1 = time_var;
EA=0; //总中断
ET1 = 1; //中断控制位,允许中断
TMOD= (TMOD|0x10); //工作方式一
TH1=(65535-10000)>>8; //12Mhz,10ms
TL1=(65535-10000)&0xff;
TR1=1; //TRO为T0的运行控制位,允许脉冲进入,TF为脉冲计数满标志
EA = 1;
}
void timer1(void) interrupt 3 using 2
{
TH1=(65535-10000)>>8;
TL1=(65535-10000)&0xff;
TF1 = 0; //clear the full flag
if(count_timer1) count_timer1--; //计时变量
}
void timer0_init(WORD time_var)
{
//P1=0x0f;
count_timer0 = time_var;
EA=0; //总中断
ET0 = 1; //中断控制位,允许中断
TMOD= (TMOD|0x01); //工作方式一
TH0=(65535-10000)>>8; //12Mhz,10ms
TL0=(65535-10000)&0xff;
TR0=1; //TRO为T0的运行控制位,允许脉冲进入,TF为脉冲计数满标志
EA = 1;
}
void timer0(void) interrupt 1 using 3
{
TH0=(65535-10000)>>8;
TL0=(65535-10000)&0xff;
TF0 = 0; //clear the full flag
if(count_timer0) count_timer0--; //计时变量
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -