The RTI can be used to generate a hardware interrupt at a fixed periodic rate. If enabled (by setting RTIE=1), this interrupt will occur at the rate selected by the RTICTL register. The RTI timer runs with OSCCLK. See Figure 40. The RTIF bit is set to one at the end of the RTI time-out period.
When coming out of reset, all the interrupts are disabled. This is done because the interrupts use the stack, so we have to set up the stack first before we should initialize the stack. We don't know when in a routine that a RTI will call the interrupt subroutine so we must have a functioning stack or else all hell will break loose.
$$RTI \; Timeout = \frac{Clock \; Speed}{1024 \cdot 2^{RTR[6:4]-1}} \bmod RTR[3:0]$$

This essentially tells the processor that you are doing something important and don't want to be interrupted. Just by setting the IRQ interrupt mask high in the CCR (Condition Control Register) will place a "Do not distrub" sign. But ocassionally there will be something so important, maybe an emergency, that can bypass the IRQ Interrupt mask, it is the XIRG Interrupt formally known as the non-maskable interrupt. Once you turn XIRQ on (high) you can't turn it off again my software, it will require a hardware reset or something.
************************************************************************* *Program counts 4 HEX-Bytes and diplays the Output on 7-Segment Display * * Program uses Real Time Interrupt for Diplay Routine * * A Common Cathode, 4 Digit LED Display is connected to Port B * *The lower 4 Bits of Port P is used to multiplex the Display (neg Logic)* * Only the Low Nibble of PORT P is written to by the Display Routine * * Written for Dragon 12 Eval Board * * Written for MiniIde Assembler, Mar. 13, 2008, by Dr. M. Giesselmann * ************************************************************************* ********************************* * 9S12 Register Equates * ********************************* PORTA EQU $00 ;Port A I/O Data Register PORTB EQU $01 ;Port B I/O Data Register DDRA EQU $02 ;Port A Data Direction Register DDRB EQU $03 ;Port B Data Direction Register CRGFLG EQU $37 ;CRG Flags Register CRGINT EQU $38 ;CRG Interrupt Enable Register RTICTL EQU $3B ;CRG RTI Control Register PTP EQU $258 ;Port P I/O Data Register DDRP EQU $25A ;Port P Data Direction Register UserRTI EQU $3E70 ;RTI RAM Interrupt Vector; see D-Bug 12 Manual DELAY EQU $0500 ;Delay loop max count ************************************ * Start (ORIGIN) of Code in Memory * ************************************ ORG $1000 ;Origin=Bottom of User RAM *********************************************** * User Code (4-Digit HEX Counter) starts here * *********************************************** Start: BSET DDRB,$FF ;Make Port B all Outputs BSET DDRP,$0F ;Make Low Nibble of Port P all Outputs BSET PTP,$0F ;Turn all Digits off RTIon: MOVW #IntRpt,UserRTI ;Setup Address for RTI Interrupt BSET RTICTL,$50 ;Set RTI Timeout BSET CRGINT,$80 ;Enable RTI CLI ;Clear Interrupt Masking Bit, Interrupts enabled InitC: LDD #$0000 ;Load $0000 into Accu D STD Count ;Store Accu D at Count CLoop: JSR TimDel ;Jump to Time Delay Subroutine LDD Count ;Load Accu D with Count ADDD #$0001 ;Increment Count STD Count ;Store Double Accu into Count BRA CLoop ;Branch back to CLoop ************************************************* * RTI Interrupt Service Routine starts here * * Purpose: Multiplexing of LED Digits * * First determine which Digit is currently on * * Then turn on the next Digit in the Sequence * * Afterwards determine the Hex Character that * * needs to be displayed on that Digit, lookup * * its Hex Code from Table & put it on Port B * ************************************************* IntRpt: LDAA PTP ;Load PORT P contents into Accu A BSET PTP,$0F ;Turn all Digits off ANDA #$0F ;Mask Out Lower Nibble CMPA #$0E ;Compare Accu A with $0E 0000|1110; Digit 4 BEQ Digit3 ;Branch to Digit3 if equal CMPA #$0D ;Compare Accu A with $0D 0000|1101; Digit 3 BEQ Digit2 ;Branch to Digit2 if equal CMPA #$0B ;Compare Accu A with $0B 0000|1011; Digit 2 BEQ Digit1 ;Branch to Digit1 if equal ;Accu A must be 0000|0111 Digit4: BCLR PTP,$01 ;Turn Digit 4 ON; 0000|1110 LDAB Count ;Load Accu B with Count LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos BRA Show ;Branch to Show Label Digit3: BCLR PTP,$02 ;Turn Digit 3 ON; 0000|1101 LDAB Count ;Load Accu B with Count ANDB #$0F ;Mask out Digit 3 BRA Show ;Branch to Show Label Digit2: BCLR PTP,$04 ;Turn Digit 2 ON; 0000|1011 LDAB Count+1 ;Load Accu B with Count+1 LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos LSRB ;Shift to Lower Nibble Pos BRA Show ;Branch to Show Label Digit1: BCLR PTP,$08 ;Turn Digit 1 ON; 0000|0111 LDAB Count+1 ;Load Accu B with Count+1 ANDB #$0F ;Mask out Digit 1 Show: LDX #SegCde ;Load start of Code Lookup table into X MOVB B,X,PORTB ;Put 7_seg Code to Port B BSET CRGFLG,$80 ;Reset RTI-Flag RTI ;Return from Interrupt ******************************************* * Time Delay Subroutine with nested Loops * ******************************************* TimDel: PSHX ;Push X onto Stack PSHY ;Push Y onto Stack LDY #DELAY ;Load Y Register with DELAY LoopX: LDX #DELAY ;Load X Register with DELAY DecX: DEX ;Decrement X Register BNE DecX ;Branch if DELAY limit has not been reached DEY ;Decrement Y Register BNE LoopX ;Branch if DELAY limit has not been reached PULY ;Restore Y from Stack PULX ;Restore X from Stack RTS ;Return from TimDel Subroutine ******************************************* * Place for Variables in Memory * ******************************************* Count: RMB 2 ;Reserve 2 Bytes of Memory for Count *Definition of symbols * 0 1 2 3 4 5 6 7 8 9 A b C d E F * - - - - - - - - - - - - * | | | | | | | | | | | | | | | | | | | | | * - - - - - - - - - - - - * | | | | | | | | | | | | | | | | | | | | | | * - - - - - - - - - - - ********************************* * Set up Symbol Table in Memory * ********************************* SegCde: FCB $3F ;$3F = Code for 0 FCB $06 ;$06 = Code for 1 FCB $5B ;$5B = Code for 2 FCB $4F ;$4F = Code for 3 FCB $66 ;$66 = Code for 4 FCB $6D ;$6D = Code for 5 FCB $7D ;$7D = Code for 6 FCB $07 ;$07 = Code for 7 FCB $7F ;$7F = Code for 8 FCB $6F ;$6F = Code for 9 FCB $77 ;$77 = Code for A FCB $7C ;$7C = Code for B FCB $39 ;$39 = Code for C FCB $5E ;$5E = Code for D FCB $79 ;$79 = Code for E FCB $71 ;$71 = Code for F
| Attachment | Size |
|---|---|
| RTI Rates.xls | 143 KB |
Comments
Post new comment