OK...here it is. The stuff in the mainloop is waiting for serial data to update the port bits which each control the activation of a relay (8 relays). The interrupt port RB0 is tied to 8 button inputs, the idea is to push any of the 8 buttons and interrupt out of the DEBUGIN to decode key presses. It goes through the interrupt, loads payload in the interrupt (it works). Where it is not working is in the CALL outside of the interrupt. It does NOT toggle the port bits. I saw something strange that I could not replicate, when it did toggle it undid the logic of any bits that were set high. Anyway...here it is, I would appreciate the help!

Nick


INCLUDE "Modedefs.Bas"
@ device HS_OSC, LVP_OFF, WDT_OFF
; @ Device pic16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF

DEFINE OSC 20



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 INTHAND myint ' Setup interrupt handler button presses




; initialize Interrupts
OPTION_REG.6 = 1 ; option_reg RB0 interrupt rising=1, falling=0 edge
INTCON = %10010000 ; Enable INTE RB0 interrupt $90


;set ports to input
TRISD = %11111111 ; 8 button press inputs + RB0 interrupt for all off


;set ports to output
TRISA = %00000000 ; set port A to outputs for relays
TRISE = %00000000 ; set port E to outputs for relays

;set port initializations
PORTA = %00000000
PORTE = %00000000

' Configure internal registers

wsave VAR BYTE $70 system ' Saves W
ssave VAR BYTE bank0 system ' Saves STATUS
psave VAR BYTE bank0 system ' Saves PCLATH
fsave VAR BYTE bank0 system ' Saves FSR

payload VAR byte bank0 system ' data location for selecting relays
payload1 var byte bank0 system ' previous good data
chksum var byte bank0 system ' check sum calculated at the TX side and sent over RF link


payload = 0



goto mainloop


asm

; Save W, STATUS and PCLATH registers, if not done previously
myint
; bsf INTCON, 1
movwf wsave ; these commands are necessary to preserve registers to prevent
swapf STATUS, W ; corruption
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave


movf portd, w ; 8 momentary button press value
movwf payload ; move portd value into payload to handoff to update_keys2
call _keys2

; Restore saved registers
bsf porte,0
movf psave, W ; reload system register to previous values before interrupt was called
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
retfie ; Return from interrupt

endasm




keys2: ; called by interrupt to update relay
if payload = 0 then
portE = 0
portA = 0
endif
if payload = 1 then
toggle portA.0
endif
if payload = 2 then
toggle portA.1
endif
if payload = 4 then
toggle portA.2
endif
if payload = 8 then
toggle portA.3
endif
if payload = 16 then
toggle portA.4
endif
if payload = 32 then
toggle portA.5
endif
if payload = 64 then
toggle portE.0
endif
if payload = 128 then
toggle portE.1
endif

return


mainloop:
INTCON = %10010000 ; Enable INTE RB0 interrupt $90
; receive data packets and check sum, throwing out sync byte (255)
debugin [wait (255),payload,chksum]
if chksum != payload then ; verify good packets by comparing check sums
goto mainloop ; check sum does not match transmitted data
endif

update_keys:

if payload = 0 then
portE = 0
portA = 0
endif
if payload = 1 then
toggle portA.0
endif
if payload = 2 then
toggle portA.1
endif
if payload = 4 then
toggle portA.2
endif
if payload = 8 then
toggle portA.3
endif
if payload = 16 then
toggle portA.4
endif
if payload = 32 then
toggle portA.5
endif
if payload = 64 then
toggle portE.0
endif
if payload = 128 then
toggle portE.1
endif

goto mainloop