I started by looking at your first code:
If GPIO.3 and GPIO.4 are both 1, then neither are being pressed when pull-up resistors are used.Code:'Then check the buttons again IF (GPIO.3=1) AND (GPIO.4=1) THEN 'Look for ENDIF near the end. 'If button are still pressed then it goes to ENCODE 'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset Encode: E_OUT=1 ' Enable transmitter (+ lights RFEN LED on demo board) PAUSEUS 25 ' Allow RF stage to stabilize ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit ' positions 0,3,5,7 to balance out the data packet being sent. DAT_OUT = %10101001 ' Get data on button inputs & invert 0's to 1's DAT_OUT.0[1]=~GPIO.3 DAT_OUT.0[2]=~GPIO.4 INTCON.0 = 0 ' Clear int on change flag ' Build checksum of 2 data bytes CHK_SUM = (DAT_OUT * 2) Transmit: SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM] PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc. ENDIF GOTO Main
I read these comments backwards to what the code does.Code:'If button are still pressed then it goes to ENCODE 'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
Personally, the technique of using 1 for OFF and 0 for ON is extremely confusing; it makes trying to follow your code extremely difficult. I always use pull-down resistors and 0=OFF / 1=ON 'cause that's how binary works as well as power switches.
EDIT: Unless it's a requirement for Sleep mode to have current ON, and the interruption signals Wake.
Otherwise, if power consumption is an issue, I'd keep the line OFF, saving power, and only applying a bit of current to Wake.




Bookmarks