main.c

来自「一个基于mc9s12dg128b」· C语言 代码 · 共 39 行

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


static int waittime = 0;

void main(void) {
 DisableInterrupts;
   DDRB=0xff;
   PORTB=0;
   
   TSCR2_PR   = 7;  //prescale factor is 8, bus clock/128=8Mhz/8
   //TSCR2_TOI  = 1;  //timer overflow interrupt enable
   TIOS       =0x01;//0 output
   TC0        =0x00FF;//channel 0 output compare
   TCTL2      =0x02;	 //output  low level
   TSCR1_TFFCA=1;  	 // if set, TFLG1 can be cleared auto, manual clear is useless
   TIE=0x01;  //Timer0 Interrupt enable 
   TSCR1_TEN  = 1;              //Timer enable
   

  /* put your own code here */
  

  for(;;) {EnableInterrupts;} /* wait forever */
  /* please make sure that you never leave this function */
  
}
interrupt void Timer0(void){
  unsigned int m;
  DisableInterrupts;
  m=TCNT;
  TC0=m+0x8000;
    waittime++;
  if(waittime>=200) waittime=0;
  PORTB = waittime;
 
}

⌨️ 快捷键说明

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