您尚未登录。

楼主 # 2021-07-14 17:26:30

tigger
Moderator
注册时间: 2021-06-18
已发帖子: 172
积分: 111

N76E003 定时器使用

#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);
}

2021-07-14_172519.png

时钟周期计算:
TIMER1_INIT  *  (1 / (16M / 12))

= 65536 * (1 / (16M / 12))
= 65536*(1/(16000000/12))
= 0.049152

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn