Hardware Reference
In-Depth Information
Example 6.1
Assume that the IRQ pin of the HCS12DP256 is connected to a 1-Hz digital waveform and
Port B is connected to eight LEDs. Write a program to configure Port B for output and enable the
IRQ interrupt, and also write the service routine for the IRQ interrupt. The service routine for
the IRQ interrupt simply increments a counter and outputs it to Port B. This program is to be
executed on an HCS12 demo board programmed with the D-Bug12 monitor.
Solution: The program is as follows:
#include
“c:\miniide\hcs12.inc”
org
$1000
count
ds.b
1
; reserve 1 byte for count
org
$1500
lds
#$1500
; set up the stack pointer
movw
#IRQISR,UserIRQ
; set up interrupt vector in SRAM
clr
count
movb
#$FF,DDRB
; configure Port B for output
bset
DDRJ,$02
; configure PJ1 pin for output (required in Dragon12)
bclr
PTJ,$02
; enable LEDs to light (required in Dragon12)
movb
count,PTB
; display the count value on LEDs
movb
#$C0,IRQCR
; enable IRQ pin interrupt and select edge triggering
cli
;
forever nop
bra forever ; wait for IRQ pin interrupt
; ********************************************************************************
; This is the IRQ service routine.
; ********************************************************************************
IRQISR
inc
count
; increment count
movb
count,PTB
; and display count on LEDs
rti
end
6.5 Interrupt Programming in C Language
Interrupt programming in C language varies with the C compiler. In this section, we exam-
ine how interrupt programming is done in CodeWarrior, ICC12 IDE, and EGNU IDE.
6.5.1 Interrupt Programming in CodeWarrior
CodeWarrior uses the keyword interrupt to inform its C compiler that a function is an inter-
rupt service routine. Whenever the keyword interrupt appears before a function name, the Code-
Warrior C compiler generates RTI as the last instruction of the function. The template for an
interrupt service routine in CodeWarrior is as follows:
Interrupt void ISR_name (void)
{
. . .
// statements to service the interrupt
}
where ISR_name is the name of the interrupt service routine.
 
Search WWH ::




Custom Search