Example 14 Real-time Interrupts Lecture L6.1
Register Stacking for Interrupts
MC9S12DP256B Interrupt Vectors
void interrupt 7 handler(){ << you C code goes here >> } Writing interrupt service routines in C and setting the interrupt vector Vector number for real-time interrupt void interrupt 7 handler(){ << you C code goes here >> }
Real-Time Interrupt Registers $0037
$0038
Real-time Interrupts $003B
; Real-time interrupt ; RTI_init(); RTI_init: sei ;disable interrupts ldaa #$59 staa RTICTL ;set rti to 10.24 ms ldaa #$80 staa CRGINT ;enable rti cli ;enable interrupts rts ; clear_RTI_flag(); clear_RTI_flag: ldaa #$80 staa CRGFLG ;clear rti flag rts
// Example 14: Real-time interrupt #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void half_sec_delay(void); unsigned short ticks, ticks0; // RTI interrupt counts // RTI Interrupt Service Routine void interrupt 7 handler(){ ticks++; clear_RTI_flag(); }
void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); RTI_init(); while(1) { seg7dec(8); // display 8 on 7seg display half_sec_delay(); seg7_off(); // turn off 7seg display } void half_sec_delay(void){ // delay for 0.5 seconds ticks0 = ticks; while((ticks-ticks0)<49) {