📄 t1.c
字号:
#include <reg52.h>
#include <stdio.h>
//------------------------------------------------
Timer 1 Interrupt Service Routine.
Set a breakpoint on 'overflow_count++' and run the
program in the debugger. You will see this line
executes every 100 clock cycles (or 10,000 Hz).
So, overflow_count is actually a 1/10,000 sec
timer.
------------------------------------------------
static unsigned long overflow_count = 0;
void timer1_ISR (void) interrupt 3
{
overflow_count++; // Increment the overflow count
}
void main (void) //MAIN C 函数
{
//定时器1模式2,计数到255
TMOD = (TMOD & 0x0F) | 0x20; //设定模式
TH1 = 256 - 100; //TL1
TL1 = TH1;
ET1 = 1; //开定时器1中断
TR1 = 1; //开定时器1
EA = 1; //开中断
//循环
while (1)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -