程序说明,定时器0按工作模式1工作,初值为10ms。
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"
UINT8 u8TH0_Tmp,u8TL0_Tmp;
//初始化配置函数
void Init_Timer0(void)
{
CKDIV=0X0C;
TIMER0_MODE1_ENABLE; //Timer 0 and Timer 1 mode configuration
clr_T0M;
u8TH0_Tmp =TIMER_DIV12_VALUE_10ms>>8; //12分频初值
u8TL0_Tmp =TIMER_DIV12_VALUE_10ms; //
TH0 = u8TH0_Tmp;
TL0 = u8TL0_Tmp;
set_ET0; //enable Timer0 interrupt
set_EA; //enable interrupts
set_TR0; //Timer0 run
CKDIV=0X00;
}
void main (void)
{
Init_Timer0(); //定时器0初始化
while(1)
{
//填入你的代码
}
}
//-------定时器0中断服务程序---------
void Timer0_isr(void) interrupt 1
{
//重装初值
TH0 = u8TH0_Tmp;
TL0 = u8TL0_Tmp;
time_ms++;
if(time_ms>=1000) //时间定时10s测试,初值10ms
{
//填入你的代码
}
}
|