Help with toggling interrupts on pin

Phil.Wakeman

New member
Any help appreciated. I wish to send a serial character on a pin going high (once), and then another character on same pin going low (once). Needs to be in an interrupt structure with other serin and serout stuff happening.
I thought this should work: [14M2 chip, other code including ADC seems to be ok]

interrupt:
let b1 = pinC.2
serout C.4, T9600_8, (b1,cr,lf)
pause 5
on b1 gosub int0, int1
return

int0: setint %00000100, %00000100 ;if 0 set interrupt high
return

int1: setint %00000000, %00000100 ;if 1 set interrupt low
return

But doesn't.
Thanks Phil
 

hex

Active member
That snippet of code seems OK to me, other than a missing hash sysmbol in the serout statement

My guess is that the problem is within the code not shown, or with hardware

This little test program works for me:

Code:
' random code found on forum
#picaxe 14m2
setfreq m8                                       ' change internal oscillator to 8 MHz

pause 1000                                       ' allow time for power up
serout C.4, T9600_8, ("\r\n\n08 Aug 2024\r\n")   ' build date

setint %00000100, %00000100                      ' set interrupt on pin C2 high

main:
    pause 1000                                   ' waste time

    goto main                                    ' loop forever
            
interrupt:
    let b1 = pinC.2                              ' save the button value to b1
    serout C.4, T9600_8, (#b1,cr,lf)             ' send value of button
    pause 5                                      ' button debounce time
    on b1 gosub int0, int1                       ' select subroutine according to button hi/lo
return

int0: setint %00000100, %00000100          ' if C2=0 set interrupt on pin C2 high
return

int1: setint %00000000, %00000100          ' if C2=1 set interrupt on pin C2 low
return

end
EDIT: - forgot to say.. Welcome to the forum :)
 
Last edited:

PhilHornby

Senior Member
What purpose does that serve ? (Depending on the nature of the signal on the input pin, you may miss the transition.)

In any case, the serout will take just over 3mS to execute. I think that should follow the setint for the same reason.
 
Top