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

📄 main.c

📁 飞思卡尔的I/O口程序 给初学者看的
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -