📄 main.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 + -