可以参考一下这个程序。自己写的一个用定时器0产生中断跑马灯。可以运行
main函数:
#include /* common defines and macros */
#include /* derivative information */
#define TICK_CNTS 50000
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
int counter;
void interrupt TimerOverflow(void) {
/* This function changes the LEDs bargraph display */
counter++;
if (counter > 8) counter=0;
if (counter == 8) PORTB = 0x7e; /* LEDs' lightshow */
if (counter == 7) PORTB = 0xbd;
if (counter == 6) PORTB = 0xdb;
if (counter == 5) PORTB = 0xe7;
if (counter == 4) PORTB = 0xe7;
if (counter == 3) PORTB = 0xdb;
if (counter == 2) PORTB = 0xbd;
if (counter == 1) PORTB = 0x7e;
TFLG1=0x01;
TC0=TCNT + TICK_CNTS;
}
void main(void)
{
TSCR1 = 0x80; /* enable timer TCNT */
TSCR2 = 0x07; /* TCNT prescaler setup */
counter = 0;
TIOS |= 0x01; /* Make channel an output compare */
TC0 = TCNT + TICK_CNTS ; /* Set TC0 to present time + OS_TICK_OC_CNTS */
TCTL1 |= 0x01; /* set timer control reg */
TIE |= 0x01;
DDRB=0xff; /* PTB as output */
PORTB=0xff; /* LEDs off */
asm{
nop
}
EnableInterrupts;
for(;;) {;} /* wait forever */
}
再只要在prm文件最下面里面添加一句
VECTOR ADDRESS 0xEFEE TimerOverflow |