Hi,

I have a strange behavior and can’t explain.
The ATmega328P supports two external interrupts which are individually enabled 
by setting bits INT1 and INT0 in the External Interrupt Mask Register (EIMSK)
The address is $1d. When I look to the documentation te bits 0 and 1 are R/W 
and the other bits are only Read (With a initial value of 0)

When I do the command $1d c@ . I get a value of 0001000. How is that possible? 
Or do I something wrong?


This code I are try to do in AmForth:

\ PD2_interrupt
\ Rotary switch is connected to pin 2 and 4

marker --pd2_interrupt--

PORTD 2 portpin: ROTARYPA
PORTD 4 portpin: ROTARYPB
ROTARYPA pin_input
ROTARYPB pin_input

$69 constant EICRA \ External Interrupt Control Register A
$1d constant EIMSK \ External Interrupt Mask Register
0   constant ISC00
0   constant INT0  \ Interrupt on port PD2
1   constant INT1  \ Interrupt on port PD3

0 variable rotaryCount
0 variable lastRotaryCount

: << lshift ;

: rotaryTurn
  \ Interupt service routine for change to Rotary encoder pin A
  \  ROTARYPB pin_high? if -1 rotaryCount +! else 1 rotaryCount +! then
;


: pd2_interrupt.init ( -- )
    -int
    EICRA c@ 1 ISC00 << or EICRA c! \ set INT0 to trigger on ANY logic change
    EIMSK c@ 1 INT0  << or EIMSK c! \ Turns on INT0, PD2
    +int                            \ turn on interrupts

;

: pd2.start
    ['] rotaryTurn INT0Addr int!
    pd2_interrupt.init
;


When I start I get this error:

amforth 6.7 ATmega328P Forthduino
>
 ok
> pd2.start
 ?? -4 -21248
>
 ok
>
 ok
>
 ok
>
 ok
>
 ok
>
 ok
>
 ok
>
 ok
>
 ok
>
 ?? -13 -21425
>
 ?? -13 -22213
>
 ok
>
 ok
>
 ok
>
 ?? -13 -21241
>
 ?? -13 -21052
>
 ok
>
 ?? -13 -21103

and more and more


Cheers,

Jan



And this is the code in AVR Assembler

ATmega168/328 Code:
#include <avr/io.h>
#include <avr/interrupt.h>


int main(void)
{
    DDRD &= ~(1 << DDD2);     // Clear the PD2 pin
    // PD2 (PCINT0 pin) is now an input

    PORTD |= (1 << PORTD2);    // turn On the Pull-up
    // PD2 is now an input with pull-up enabled



    EICRA |= (1 << ISC00);    // set INT0 to trigger on ANY logic change
    EIMSK |= (1 << INT0);     // Turns on INT0

    sei();                    // turn on interrupts

    while(1)
    {
        /*main program loop here */
    }
}



ISR (INT0_vect)
{
    /* interrupt code here */
}

_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to