#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
离线
准备用新塘N76E003替换stm8有没有坑要注意的?
离线
注意一下TA寄存器, 仅只有4个时钟周期的窗口,如果优化基本太高,可能导致后面的指令大于4个周期, 从而操作无效。同理注意xdata赋值给TA保护的寄存器也要考虑时钟周期的问题
离线
注意一下TA寄存器, 仅只有4个时钟周期的窗口,如果优化基本太高,可能导致后面的指令大于4个周期, 从而操作无效。同理注意xdata赋值给TA保护的寄存器也要考虑时钟周期的问题
要选小模式编译,这样效率才高,手动指定变量存储地方,这样即可大内存,又有高效率
离线