#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#define TIMER1_INIT 65536
UINT8 u8TH1_Tmp,u8TL1_Tmp;
void Timer1_ISR (void) interrupt 3 //interrupt address is 0x001B
{
TH1 = u8TH1_Tmp;
TL1 = u8TL1_Tmp;
P06 = ~P06; //P0.3 toggle when interrupt
}
void main (void)
{
Set_All_GPIO_Quasi_Mode;
TIMER1_MODE1_ENABLE; //定时器1, 模式1, 16bit定时器, 定时器值满 0xFFFF -> 0x0000 产生中断。
clr_T1M; //T1M = 0,兼容传统 8051, TIMER1时钟 = Fsys/12 = 16M /12
//set_T1M; //T1M = 1, TIMER1时钟 = Fsys = 16M
u8TH1_Tmp = (65536 - TIMER1_INIT)/256;
u8TL1_Tmp = (65536 - TIMER1_INIT)%256;
TH1 = u8TH1_Tmp;
TL1 = u8TL1_Tmp;
set_ET1; //enable Timer1 interrupt
set_EA; //enable interrupts
set_TR1; //Timer1 run
while(1);
}
时钟周期计算:
TIMER1_INIT * (1 / (16M / 12))
= 65536 * (1 / (16M / 12))
= 65536*(1/(16000000/12))
= 0.049152
离线