1. 程序实现
5.1 Timer0 初始化程序
void INT_Timer_Initialize(void)
{
/*++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* */
/* Fout(s)=[(prescaler+1)*(TCNTB+1)]/[pclk*divider]=40ms */
/* */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++ +*/
rTCFG0=0x64; //prescaler0 100
rTCFG1=0x01; //divide value 1/4
rTCNTB0=5000; //TCNTB=5000
rTCON=0x0a; //auto load, invert off, manual update, stop timer
/*INTIALIZE THE INTERRUPT*/
rINTMOD=0x0; //all irq
rINTMSK=0xffffffff; //disable all interrupt source
rINTSUBMSK=0xffff; //disable all sub interrupt source
}
5.2 开启timer0中断
/* open the interrupt timer0 and eint0 */
void ENABLE_INTERRUPT(void)
{
rINTMSK=~(BIT_TIMER0);
rTCON=0x09;
}
5.3 测试主函数
int Main()
{
SetClockDivider(1, 1);
SetSysFclk(DFT_FCLK_VAL);
Port_Init();
Uart_Select(0);
Uart_Init(0, UART_BAUD);
//timer0初始化
INT_Timer_Initialize();
//建立中断向量表
pISR_TIMER0=(unsigned)timer0Handler;
//开中断
ENABLE_INTERRUPT();
Uart_Printf("the main is running\n");
while(1);
}
5.4 timer0中断服务子程序
void __irq timer0Handler(void)
{
printf("timer0 is running.\n");
ClearPending(BIT_TIMER0);
}
阅读(1187) | 评论(0) | 转发(0) |