Search code examples
arduinoatmegaforth

Execute FlashForth word when pin changes


I have a word that I wish to trigger on pin change:

: example
  ." Hello, world! "
;i

I am using External Interrupt Request 1, which is interrupt vector no. 3 according to page 65 of the datasheet and this diagram I use.

' example 3 int!
ei

When I try to change the value of a pin (pin 3 in this case), nothing happens.

Am I doing something wrong?


Solution

  • There are several things wrong with the code I posted above, but I did get it working after looking at other examples and reading the data sheet:

    \ Pin Change Interrupt 0
    4 constant pcint0
    
    \ Pin Change Mask Register 0
    $6b constant pcmsk0
    
    \ Pin Change Interrupt Control Register
    $68 constant pcicr
    
    ram variable example
    
    : example+1
      1 example +!
    ;i
    
    : int-enable
      ['] example+1 pcint0 int!
      ei
    ;
    
    int-enable
    
    %00000001 pcmsk0 mset
    %00000111 $68 mset
    
    \ Shorting pin 8 will now increment `example` variable.