\ ****************************************************************************** 
\ Clignotement LED géré par interruptions 
\ Material: ARDUINO MEGA 2650 R3 
\ Forth version: Flash Forth (http://flashforth.com/)  
\ author: M PETREMANN 
\ Creation:     14 june 2019 
\ Modification: 14 june 2019 
\ ****************************************************************************** 
 
 
\ Disable interrupt before removing the interrupt code 
irqOvf3Dis 
 
-msectimer 
marker -msectimer 
 
\ Port Register Definitions 
$24 constant DDRB       \ Direction Data Register PORT B 
$25 constant PORTB      \ data in PORT B 
 
%10000000 constant pLED \ mask for LED connector 13 (onboard LED) 
 
: toggleLed   ( --- )    \ toggle LED off if LED is on, and inverse... 
  PORTB c@              \ get LED status 
  pLED xor              \ invert bit x0000000 
  PORTB c!              \ turn ON or OFF led 
; 
 
\ this part, Author: Mikael Nordman - adaptation M. PETREMANN 
\ Disable interrupt before removing the interrupt code 
irqOvf3Dis 
 
$91 constant TCCR3B     \ Timer/Counter3 Control Register B 
$71 constant TIMSK3     \ Timer/Counter3 Interrupt Mask Register 
36 constant ovf3Ivec 
 
\ Counter for timer overflows 
variable counter 
 
\ The interrupt routine 
: t3OverflowIsr ( ---) 
    1 counter +!                    \ increment counter 
    counter @ 500 > 
    if     
        0 counter ! 
        toggleLed 
    then 
;i 
 
: irqOvf3Init ( ---) 
    ['] t3OverflowIsr ovf3Ivec int! \ Store the interrupt vector 
    1 TCCR3B mset                   \ Activate counter 3 
    1 TIMSK3 mset                   \ Activate timer3 overflow interrupt 
; 
 
: irqOvf3Dis ( ---)                 \ Disable interrupt 
  1 TIMSK3 mclr 
; 
 
$80 DDRB c! 
irqOvf3Init