#include "registers.asm" ; Defines TOI, #include "vectors.asm" ; Defines VTOF org $2000 ; Nice safe location in RAM *---------------------------------------------- * This main routine turns on the timer overflow * interrupt and then just waits for interrupts. *---------------------------------------------- main: bsr resetTOF ; Reset timer overflow flag, so we don't get an interrupt right away. bsr enableTOI ; Now we can safely enable the timer overflow interrupt. cli ; Enable interrupts globally. loop: wai ; Wait for interrupts bra loop ; Keep waiting forever *---------------------------------------------- * enableTOI: This subroutine enables the timer * overflow interrupt. It takes care not to * disturb the state of other bits in TMSK2. * (LDAA #TOI, STAA TMSK2 would not do this.) *---------------------------------------------- enableTOI: ldx #TMSK2 ; Select Timer interrupt Mask reg. 2. bset 0,x TOI ; Set Timer Overflow Interrupt (bit 7) rts *---------------------------------------------- * resetTOF: This subroutine resets the timer * overflow flag. It takes care to ONLY reset * the single flag that we want to reset. * (BSET would not work for this!) *---------------------------------------------- resetTOF: ldaa #TOF ; Select mask for Timer Overflow Flag (bit 7) staa TFLG2 ; Kick just that one flag down to 0. rts *---------------------------------------------- * myISR: On each timer overflow, increment a * counter. When it gets to MAX_COUNT ($F), * copy from PORTC to PORTB. *---------------------------------------------- myISR: bsr resetTOF ; Reset the timer overflow flag. ldaa count ; Load old counter value. inca ; Increment it. cmpa #MAX_COUNT ; At MAX_COUNT yet? blt skip ; If still less, skip the job. ldab PORTC ; Load a byte from port C. stab PORTB ; Store byte to port B. clra ; Reset counter to 0. skip: staa count ; Store new counter value. rti ; Return from Interrupt count: fcb 0 ; Counter (initially 0) MAX_COUNT equ $F *---------------------------------------------- * Set up the TOF interrupt vector so myISR will * be called to handle timer overflows. *---------------------------------------------- org VTOF ; Vector for Timer OverFlow: fdb myISR ; Pointer to my Int. Svc. Rout.