main.c

来自「环境CodeWarrior4.6. freescale 9s12dg128实时」· C语言 代码 · 共 58 行

C
58
字号
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"



void main(void) 
{
  /* put your own code here */
  
  
  /********PLL make 8M to 24M********************************/
 /* CLKSEL=0;                 //system clocks are from OSCCLK
  PLLCTL_PLLON=1;           //turn on pll
  SYNR=23;                  
  REFDV=15;                 //pllclk=2*osc*(SYNR+1)/(REFDV+1)=2*8*24/16= 24 MHz
  while(CRGFLG_LOCK==0);     //wait untile pll is steady
  CLKSEL_PLLSEL=1;                 //system clocks are from PLLCLK  */
  /*********************************************************/
  
  /*****实时中断。默认8M总线频率**********************/     
  RTICTL=0x7f;     //RTR[6:4]=111, RTR[3:0]=1111
                   //溢出周期T=1/(foscclk/1024/64)*(16)= 0.131(s)
  CRGFLG=0;                      
  CRGINT_RTIE=1;        //enabel Real-time-Interrupt
  /****************************************************/ 
  
  EnableInterrupts;
  
  PORTK=0XFF;           
  for(;;) 
  {
    //加入工作代码   
  } /* wait forever */
  /* please make sure that you never leave this function */
  
}








/**********中断服务程序***********************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 7 void RTI_ISR(void)
{
  
  CRGFLG_RTIF=1;             //清除实时中断标志
  DDRK= 0XFF;
  
  PORTK_BIT0=~PORTK_BIT0;    //点亮或熄灭小灯。显示。
  //可在此加入标志,用以完成指定工作
  
}
/**********中断服务程序***********************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?