C program to use timer over interrrupt and real time interrupt
/* Increment Port A using TOF interrupt, and
* decrement Port B using RTI interrupt */
#include "hc12.h"
main()
{
DDRA = 0xff; /* Make Port A output */
PORTA = 0x00; /* Clear Port A */
TSCR = 0x80; /* Turn on timer */
TMSK2 = 0x84; /* Enable TOF interrupt, overflow */
/* every 131 ms */
TFLG2 = 0x80; /* Clear timer interrupt flag */
DDRB = 0xff; /* Make Port B output */
PORTB = 0x00; /* Clear Port B */
RTICTL = 0x87; /* Enable RTI interrupt; rate = 65 ms */
RTIFLG = 0x80; /* Clear RTI flag */
enable(); /* Enable interrupts (clear I bit) */
while (1)
{
_asm("wai") ; /* Do nothing - go into low power mode */
}
}
@interrupt void toi_isr(void)
{
PORTA = PORTA + 1; /* Increment Port A */
TFLG2 = 0x80; /* Clear timer interrupt flag */
}
@interrupt void rti_isr(void)
{
PORTB = PORTB - 1; /* Decrement Port B */
RTIFLG = 0x80; /* Clear RTI flag */
}
/* INTERRUPT VECTORS TABLE 68HC12
*/
void toi_isr(); /* Timer overflow ISR */
void toi_isr(); /* Real Time Interrupt ISR */
/* Vectors at 0xFFD0 on standard HC12; remapped to 0x0B10 with D-Bug 12 */
void (* const _vectab[])() = {
0, /* BDLC */
0, /* ATD */
0, /* reserved */
0, /* SCI0 */
0, /* SPI */
0, /* Pulse acc input */
0, /* Pulse acc overf */
toi_isr, /* Timer overf */
0, /* Timer channel 7 */
0, /* Timer channel 6 */
0, /* Timer channel 5 */
0, /* Timer channel 4 */
0, /* Timer channel 3 */
0, /* Timer channel 2 */
0, /* Timer channel 1 */
0, /* Timer channel 0 */
rti_isr, /* Real time */
0, /* IRQ */
0, /* XIRQ */
0, /* SWI */
0, /* illegal */
0, /* cop fail */
0, /* cop clock fail */
(void *)0xff80, /* RESET */
};