include "regs12.lib" 'Declare the RTI ISR, used to generate timed delays. declare tRtiDelay 'delay counter declare wPeriodIncrement declare ch const CHANGE_RATE = 50 const PRINT_RATE = 2000 interrupt $fff0 'RTI ISR pokeb rtiflg, $80 'clear RTI flag if tRtiDelay <> 0 'if not done yet... tRtiDelay = tRtiDelay - 1 'count this tick endif end interrupt $ffee pokeb tflg1,$01 ' Acknowledge interrupt poke tc0,peek(tc0)+wPeriodIncrement end Main: pokeb copctl,0 pokeb rtictl, $81 ' Turn on the RTI ' Enable serial port poke sc0bdh, 26 ' Set for 19200 baud pokeb sc0cr2,$0c ' Enable transceiver print "intr1.bas started" pokeb tscr,$80 ' Enable the timer subsystem pokeb tctl2,$01 ' TC0 toggles when compares happen pokeb tios,$01 ' TC0 is now output compare pokeb tmsk1,$01 ' TC0 can generate interrupts poke tc0,8192 wPeriodIncrement = 8192 interrupts on 'allow interrupts do tRtiDelay = PRINT_RATE do ch = inkey() ch = ch AND $FF select ch case 'd' wPeriodIncrement = wPeriodIncrement + CHANGE_RATE endcase case 'u' wPeriodIncrement = wPeriodIncrement - CHANGE_RATE endcase endselect loop while tRtiDelay <> 0 print "Still Running The Program!" print "Notice how the frequency doesn't change even while this is printing is" print "being done. The printing takes a very long time to process, but the" print "interrupt driven routines are doing a nice job of handling the work in" print "the background!" loop end