定时器模块
1:输出比较
定时器延时,中断点亮 led 灯
#include <hidef.h> /* common denes and macros */
#include <mc9s12db128.h> /* derivave informaon */
//void interrupt 8 aabreak(void); //此行可以注释掉*******
unsigned int %ag=0;
void main(void) {
EnableInterrupts;
TFLG1=0x01; //清中断标志位
DDRB=0x3;
PORTB=0x3; //将 B 口定义为输出,首先输出全 0
TSCR1=0x80; //定时器使能,正常工作
TSCR2=0x01; //将定时器进行 128 分频 最高位不要开********
TIE=0x01; //定时器 0 的中断使能
TIOS=0x01; //将定时器设置为输出比较状态
TCTL2=0x00; //定时器与引脚断开
TFLG1=0x01; //清中断标志位
TC0=0x00f0; //给定时器赋值
for(;;);
}
#pragma CODE_SEG NON_BANKED
void interrupt 8 aabreak(void)//中断号要正确,是中断 8 (从 0 通道开始算起的)
{
TFLG1=0x01; //清中断标志位
if(%ag==0) {
PORTB=0xaa;
%ag=1;
} else{
PORTB=0x55;
评论0