Interrupt Service Routines AVR8ΒΆ

\ TIMER_0 example
\
\ provides
\  timer0.tick      -- increasing ticker
\
\ older mcu's may need
\  TCCR0 constant TCCR0B
\  TIMSK constant TIMSK0

variable timer0.tick

: timer0.isr
  1 timer0.tick +!
;

: timer0.init ( preload -- )
   0 timer0.tick !
   TCNT0 c! \ preload
   ['] timer0.isr TIMER0_OVFAddr int!
;

\ some settings for 8bit timer to
\ get 1ms ticks
\ f_cpu  prescaler preload
\  16MHz   64       6
\   8MHz   64     131

: timer0.start
   0 timer0.tick !
   %00000011 TCCR0B c! \ prescaler 64
   %00000001 TIMSK0 c! \ enable overflow interrupt
;

: timer0.stop
  %00000000 TCCR0B c! \ stop timer
  %00000000 TIMSK0 c! \ stop interrupt
;

All interrupts are available for forth interrupts.

int! (and friends) uses the interrupt address from the data sheet as an index, but points to a different address in EEPROM. The index number is always identical to the interrupt number found in the data sheets.

See also

Shells And Upload to deal with the register names.