main.c

来自「飞思卡尔的I/O口程序 给初学者看的」· C语言 代码 · 共 38 行

C
38
字号
#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 */
 DDRB=0xFF;//PORTB设定为输出
 PORTB=0x01;//PORTB初始化为全高
 

 TSCR1=0x80;//定时器使能且TFLG1能被自动清除

 TSCR2=0x07;//定时器预分频系数设定  Prescale Factor=128
 TIE=0x01;//定时器通道0使能
 TIOS_IOS0=1;
 TCTL2=0x00;
 TFLG1=0x01;
 TC0=0x00ff; 
 EnableInterrupts;

  for(;;) {} /* wait forever */
  /* please make sure that you never leave this function */
}
#pragma CODE_SEG NON_BANKED
void interrupt 8 ISR(void) //8为定时器通道0的中断标号
{
 DisableInterrupts;  

 PORTB++;
 TFLG1=0x01;
 TCNT=0;
}



#pragma CODE_SEG DEFAULT

⌨️ 快捷键说明

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