********************************************************************** * IRQ Interrupt Example EEL-37/4744 EMS * * * Counts up the number of IRQs that occur up to 255 on GCPU++. ********************************************************************** * EQUATEs ********************************************************************** PORTB EQU $0001 ; Output Port B DDRB EQU $0003 ; Data Direction Port B INTCR EQU $001E ; Interrupt control register (for IRQ) RAM EQU $0900 ; Start of RAM STK EQU $0900 ; User Stack RAMPROG EQU $0970 ; Program space in RAM IPV_IRQ EQU $0836 ; Pseudo-vector location for IRQ ********************************************************************** * Data Section ********************************************************************** ORG RAM CNTR8 DS.B 1 ; Could use DC.B 0, but BAD!!! ********************************************************************** * Interrupt Pseudo-Vector Initialization ********************************************************************** ORG IPV_IRQ JMP IRQ_ISR ********************************************************************** * Main Program ********************************************************************** ORG RAMPROG ********************************************************************** * Initialization Section ********************************************************************** LDS #STK ; Initialize the stack pointer, SP CLR CNTR8 ; Take the responsibility for clearing counter ********************************************************************** * Setup each hardware device ********************************************************************** LDAA #$FF ; Set PB for output port STAA DDRB ; ... * Initialize the IRQ FF to zero using the Pre-Clear input on PB0 LDAA #%00000000 ; We could have used CLRA or CLR PORTB STAA PORTB ; Set PB0=0, i.e., pre-clear the FF LDAA #%00000001 ; Turn off pre-clear input; could use INCA STAA PORTB ; FF ready for switch depression ********************************************************************** * Main program does its work here ********************************************************************** LDAA #%01000000 ; Enable the external IRQ by clearing STAA INTCR ; the (local) IRQ mask bit (bit 6) CLI ; Turn interrupt system on HERE BRA HERE ; Main program waits on interrupts * ********************************************************************** * Interrupt Service Routine(s) ********************************************************************** * Part I : Service the interrupt ********************************************************************** ORG $09C0 IRQ_ISR INC CNTR8 ; Count up each switch depression ********************************************************************** * Part II : Clear the interrupt flag ********************************************************************** LDAA #%00000000 ; Turn off PB0 to pre-clear the FF STAA PORTB ; ... LDAA #%00000001 ; Turn off pre-clear input; could use INCA STAA PORTB ; FF ready for next switch depression RTI ; Return from Interrupt Service