try this one
Code:
@ __CONFIG _HS_OSC & _LVP_OFF
DEFINE OSC 20
INCLUDE ".\INCLUDE_ROUTINES\DT_INTS-14.bas"
INCLUDE ".\INCLUDE_ROUTINES\ReEnterPBP.bas"
;set port initializations
PORTA = %00000000
PORTE = %00000000
TRISA = %00000000 ; set port A to outputs for relays
TrisB = %00000001 ' b0 input for interrupt
TRISC = %10000000 'set 7 as input debugin
TRISD = %00000000 ; 8 button press inputs + RB0 interrupt for all off Made outputs as unused
TRISE = %00000000 ; set port E to outputs for relays
' Configure internal registers
ADCON1 = 7
CMCON = 7
DEFINE DEBUGIN_REG PORTC ' Set portC as software RX in
DEFINE DEBUG_BAUD 2400 ' Set bit rate
DEFINE DEBUGIN_BIT 7 ' Set portC bit 7
DEFINE DEBUGIN_MODE 1 ' Set Debugin mode: 0 = true, 1 = inverted
'DEFINE DEBUG_REG PORTC 'Debug pin port
'DEFINE DEBUG_BIT 6 'Debug pin bit
'DEFINE DEBUG_MODE 1 'Debug mode: 0 = True, 1 = Inverted
; initialize Interrupts
OPTION_REG.6 = 1 ; option_reg RB0 interrupt rising=1, falling=0 edge
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _keys2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
NewPayload var Byte
payload VAR byte ' data location for selecting relays
chksum var byte ' check sum calculated at the TX side and sent over RF link
INT0IF var INTCON.1
CLEAR
pause 50 ' settle time
@ INT_CLEAR INT_INT ; make sure INT0IF is cleared
@ INT_ENABLE INT_INT ; Enable Interrupt
mainloop:
; receive data packets and check sum, throwing out sync byte (255)
DEBUGIN [wait(255),NewPayload, chksum]
'DEBUG NewPayload, chksum
if chksum != newpayload then MainLoop
payload=NewPayload
goto updatePort
keys2: ; Called by Interrupt update relay
pause 20 ' small debounce delay
if !PORTB.0 then GetOut ' button up?
' If so, getout of here... no need for noise call
UpdatePort:
select case payload
case 0
PORTE = 0
PORTA = 0
CASE 1
toggle portA.0
CASE 2
toggle portA.1
CASE 4
toggle portA.2
CASE 8
TOGGLE PORTA.3
CASE 16
toggle portA.4
CASE 32
toggle portA.5
CASE 64
toggle portE.0
CASE 128
toggle portE.1
END SELECT
GetOut:
If INT0IF THEN ' called by Interrupt?
@ INT_RETURN
' - Yes, clear the flag and getout
ELSE '
GOTO MAINLOOP
' - No, return to Mainloop
ENDIF
Make sure you transmit the right way from your PC...
Bookmarks