本文主要是介绍NY8A051F例程Timer Interrupt_WDT Interrupt,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
NY8A051F例程Timer Interrupt_WDT Interrupt
使用单片机内核:NY8A051F SOP-8
*项目:定时器中断和WDT中断
*文件:main.c
*描述:设置定时器0、定时器1、WDT中断
*1.FINST=4MHz/4T(I_HRC)
*2.定时器0溢出中断标志位将每2048us设置一次,然后切换PB0输出状态(2048us=1us*256*8)
*3.定时器1下溢中断标志位将每1024us设置一次,然后切换PB1输出状态(1024us=1us*256*4)
*4.WDT超时中断标志位将每3.5ms设置一次,然后切换PB2输出状态
*4.1设置项目选项:WDT时基=3.5ms
#include <ny8.h>
#include "ny8_constant.h"
#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")//! interrupt service routine
void isr(void) __interrupt(0)
{if(INTFbits.T1IF){ PORTB ^= (1<<1); // PB1 ToggleINTF= (unsigned char)~(C_INT_TMR1); // Clear T1IF flag bit }if(INTFbits.T0IF){ PORTB ^= 1; // PB0 ToggleINTF= (unsigned char)~(C_INT_TMR0); // Clear T0IF flag bit }if(INTFbits.WDTIF){ PORTB ^= (1<<2); // PB2 ToggleINTF= (unsigned char)~(C_INT_WDT); // Clear WDTIF flag bit } }void main(void)
{
unsigned char R_shift_regl = 0xFF;
//;Initial GPIO IOSTB = C_PB5_Input | C_PB4_Input | C_PB3_Input; // Set PB0 & PB1 to input mode,others set to output modePORTB = 0x07; // PB0、PB1 & PB2 are output HighDISI();
//;Initial Timer0PCON1 = C_TMR0_Dis; // Disable Timer0TMR0 = 0; // Load 0x00 to TMR0 (Initial Timer0 register)T0MD = C_PS0_TMR0 | C_PS0_Div8 ; // Prescaler0 is assigned to Timer0, Prescaler0 dividing rate = 1:8,clock source is instruction clock//;--Initial WDT (if WDT needs prescaler0 dividing rate )--------------------------------------------------
// T0MD = C_PS0_WDT // Prescaler0 is assigned to WDT, Prescaler0 dividing rate = 1:2 (WDT select interrupt)
//;-------------------------------------------------------------------------------------------------------- //;Initial Timer1 TMR1 = 0xFF; // Load 0xFF to TMR1 (Initial Timer1 register)T1CR1 = C_TMR1_Reload | C_TMR1_En; // Enable Timer1, Initial value reloaded from TMR1, Non-stop mode T1CR2 = C_TMR1_ClkSrc_Inst | C_PS1_Div4; // Enable Prescaler1, Prescaler1 dividing rate = 1:4, Timer1 clock source is instruction clock//;Setting Interrupt Enable Register INTE = C_INT_WDT | C_INT_TMR1 | C_INT_TMR0; // Enable Timer0、Timer1、WDT overflow interrupt//;Initial Power control registerPCON = C_WDT_En | C_LVR_En; // Enable WDT , Enable LVR//;Enable Timer0 & Global interrupt bit PCON1 = C_TMR0_En; // Enable Timer0ENI(); // Enable all unmasked interrupts while(1);
}
更多关于NY8A051F的例程,请留言联系!
这篇关于NY8A051F例程Timer Interrupt_WDT Interrupt的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!