登录站点

用户名

密码

MC9S12XS128 中 RTI (实时时钟中断) 的使用

1已有 1864 次阅读  2010-09-29 21:29   标签时钟  RTI  实时  飞思卡尔  MC9S12XS128 
 
 
 
写在前面的话->:
英文为datasheet 中的原文。摘自 datasheet 254  页。
The RTI can be used to generate a hardware interrupt at a fixed periodic rate. If enabled (by setting RTIE=1), this interrupt will occur at the rate selected by the RTICTL register. The RTI runs with a gated OSCCLK. At the end of the RTI time-out period the RTIF flag is set to one and a new RTI time-out period starts immediately.
A write to the RTICTL register restarts the RTI time-out period.
 
上面这段英文的意思是说: RTI 这个模块在 RTIE (RTIE 是中断使能寄存器 CRGINT 的第7位 P238 )这一位置 1 的时候,会根据 RTICTL 这个寄存器设定的时间值产生一个硬件中断。此时 Real Time Interrupt Enable Bit   CRGFLG_RTIF 这个寄存器就会 置 1 。那么在中断服务程序中可通过向CRGFLG_RTIF写 1 来清除中断。
所以 RTI 也可以当做一个定时器来用。从以上的分析可知只需要配置三个寄存器 RTICTL、CRGINT、RGFLG_RTIF
就可以使用。
/**************************以下为代码实现***********************************/
#include <hidef.h>      /* common defines and macros */
#include <MC9S12XS128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
 
byte i = 0;
/*------------RTI初始化------------*/
void RTI_Init(void)
{
   RTICTL=0X77;        //f=8*2^16/OCCLK  T=30.517578125Ms
                       //(分频系数要查表查表 Page242)      
                       //OCCLK为外部晶振的频率,这里用的是 16M                                           
   CRGINT=0X80;        //Enable the RTI  Interrupt  Page238                 
}
/*----------RTI中断服务程序------*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 7 RTI_ISR(void) // 30.517578125Ms timer overflow  
{
  i++;
  CRGFLG_RTIF=1;         //Write 1 to clear RTIF bit   237页    
}
#pragma CODE_SEG DEFAULT
/*-----------主函数中LED以1s的频率闪烁------------*/
void main(void)
{
   DDRB=0XFF;
   RTI_Init();
   EnableInterrupts;      //don't forget  
   while(1)
   {
      if(i==33)
      {
         i=0;
         PORTB=~PORTB;
      }
   }  
}
/*-------------end of file ---------------------*/

上一篇: VIVI 源码的目录结构分析 下一篇: MC9S12XS128 中 ATD 的使用

分享 举报

发表评论 评论 (1 个评论)

涂鸦板