To use this file copy and paste this:    // #URL-lib "http://pin1.org/forthlib/flb/Interupts/timer0-example.fth"   into BV Terminal 3 or here to download.

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Examples of using interrupts with timer 0 // T0start will begin the program // This code simply causes an interrupt evey 15 seconds and // prints a message to the console. // Use LOOK to see the interupt tables before and after using // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

// REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=99 // #URL-lib "http://pin1.org/forthlib/flb/General/decompile.flb" // #URL-lib "http://pin1.org/forthlib/flb/Interupts/interrupt.flb"

// CONSTANTS: // constants needed for this example &e0004000 constant T0IR &e0004004 constant T0TCR &e0004008 constant T0TC &e000400c constant T0PR &e0004014 constant T0MCR &e0004018 constant T0MR0


Full Contents of File

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Examples of using interrupts with timer 0
// T0start will begin the program
// This code simply causes an interrupt evey 15 seconds and
// prints a message to the console.
// Use LOOK to see the interupt tables before and after using
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

// REQUIRES:
// #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=99
// #URL-lib "http://pin1.org/forthlib/flb/General/decompile.flb"
// #URL-lib "http://pin1.org/forthlib/flb/Interupts/interrupt.flb"

// To use this type T0start, an interrupt will occur every 10 seconds

// CONSTANTS:
// constants needed for this example
&e0004000  constant  T0IR
&e0004004  constant  T0TCR
&e0004008  constant  T0TC
&e000400c  constant  T0PR
&e0004014  constant  T0MCR
&e0004018  constant  T0MR0


// This word will enable fast interrupts for timer0
// in the VIC registers, start timer 0, start it and enable
// the global interrupts which are disabled each time
// an interrupt is called
: setT0
        TIMER0  intSel      // selct
        TIMER0  intEn        // enable
        efiq        // enable irupts, at start up all disabled
;

// this is the word that gets called when the interrupt is fired
// the word MUST do the following:
// 1. clear the interrupt, in this case it is the timer0 interrupt
// 2. carry out what it needs to do
// 3. re-enable the interrupt if we want to come back here
: T0int
        1  t0IR  !        // clear interrupt
        ."  Interrupt  has  occurred"  cr
        TIMER0  intEn  // re-enable for return
;
// sets timer 1 as a counter, the values
// given makes T0TC increment every 100 us
// or every 0.1ms, in other words 1 second is
// equal to 1000 counts
// A match has been set up at every 10,000 counts (10 seconds)
// this will generate an interrupt via the T0MCR register
: T0start
        pclk  1000  / T0PR ! // sets regardless of CLK
        2  T0TCR  !              // reset
        1  T0TCR  !              // enable
        10000  t0MR0  !        // match on 10000
        3  t0MCR  !              // interrupt and reset to 0
        setT0                      // set interrupts
        // now place cfa of T0int ti interupt table
        s"  T0int"  find  drop      // get cfa of t0int
        TIMER0        // into timer slot (4)
        int>>          // do it
; 

: T0stopTIMER0  intDis  ;
: lookintr.  ;