Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3302197
  • 博文数量: 754
  • 博客积分: 10132
  • 博客等级: 上将
  • 技术积分: 7780
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-14 23:36
文章分类

全部博文(754)

文章存档

2012年(3)

2011年(39)

2010年(66)

2009年(167)

2008年(479)

我的朋友

分类: LINUX

2008-04-21 01:21:06

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);
}
阅读(1129) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~