开发手册分析
1.
2.
3.
4.
5.
代码模块
timer0.h
#ifndef _TIMER0_H
#define _TIMER0_H
void Timer_init();
#endif
timer0.c
#include <REG52.H>
#include “Timer0.h”
#include “intrins.h”
sbit LED=P1^0;
void Timer_init()
{
TMOD=0X01;//配置定时器模式0000 0001 为模式1
TF0=0;//关闭中断溢出标志位,防止产生中断
TR0=1;//开启定时器0
TH0=0XFC;//配置定时器时间,定时1ms
TL0=0X18;
ET0=1;//开启定时器中断开关
EA=1;//开启总中断开关
PT0=1;//选择中断优先级
}
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 22;
j = 3;
k = 227;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0count;
TH0=0XFC;//配置定时器时间,定时1ms
TL0=0X18;
T0count++;
if(T0count>=1000)//定时1秒
{
LED=1;
Delay500ms();
LED=0;
Delay500ms();
}
}