18
Interrupt Service Routines example code and explanations
This section includes explanations of all the different interrupts and sample code
of the function.
Real Time Interrupt:
Operation
The operation of the RTI is controlled by _H12RTICTL. Bit 7 is the Real Time
Interrupt Enable (RTIE). Writing a one to this bit will enable the RTI. The rate
at which the RTI is triggered is determined by the Real Time Interrupt Rate (RTR).
The different rates are listed in Table 6.
Table 6: RTI rate
RTR2 RTR1 RTR0
Period___
0
0
0
off
0
0
1
1.024ms
0
1
0
2.048ms
0
1
1
4.096ms
1
0
0
8.196ms
1
0
1
16.384ms
1
1
0
32.768ms
1
1
1
65.536ms
_H12RTICTL:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
RTIE
RSWAI
RSBCK
unused
RTBYP
RTR2
RTR1
RTR0
After the interrupt is triggered the ISR must clear the flag. This is done by
writing a one to the Real Time Interrupt Flag (RTIF) in _H12RTIFLG register.
_H12RTIFLG:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
RTIF
unused
unused
unused
unused
unused
unused
unused
Sample Code
This is a simple program to count the number of RTI interrupts that have occurred.
_
_mod2_
_ void RTIInt();
// function prototype
int Timecount;
// global variable
void _
_main()
{
DB12->SetUserVector(RTI,RTIInt);
// set up interrupt vector
TimeCount = 0;
_H12RTICTL=0x87;
// set up the RTI for 65.536ms
while(1)
{
DB12->out2hex(Timecount);
}
}
_
_mod2_
_ void RTIInt()
// interrupt service routine
{
Ti+;
_H12RTIFLG=0x80;
// clear the flag
}
Summary of Contents for 68HC12
Page 31: ...31 ...