xs128 定时器溢出中断

 
#include "includes.h"

uint32 counter = 0;

/***********************************************************
** 名       称:void ECT_Time(void) 
** 功       能:定时器
** 入口参数:无
** 出口参数:无
** 使用说明:100ms定时
************************************************************/
void ECT_Time(void) 
{
    //定时器使能
    TSCR1_TEN = 1; 
    //定时器溢出中断使能
    TSCR2_TOI = 1;
    //128分频,80 / 128 = 625000
    TSCR2_PR = 7;  
    //100ms
    TCNT = 65535 - 62500;  
}

/***********************************************************
** 名       称:void interrupt 16 TOI_ISR(void)
** 功       能:定时器计数器溢出中断处理服务函数
** 入口参数:无
** 出口参数:无
** 使用说明:无
************************************************************/
#pragma CODE_SEG  NON_BANKED

void interrupt 16 TOI_ISR(void)
{
    //清除溢出标志
    TFLG2 = 0x80;
    TCNT = 65535 - 62500; 
    
    counter++;
    //1s
    if(counter == 10)
    {
            counter = 0;
            PORTB = ~PORTB;      
    }
}

#pragma CODE_SEG DEFAULT


你可能感兴趣的:(include)