⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个基于mc9s12dg128b
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -