Below is a code that I am using to monitor inputs to a 16F870. As discussed in an earlier post, I am controlling and monitoring these inputs through a wireless link. When I activate them locally (by applying voltage right to the pin), it works well and I have no problems. When I control it with the wireless transmitter, I find that the PIC "locks" up and I have to reset it to work correctly. I found, through a lot of time experimenting, that using a nap or sleep command seems to correct the problem. I can't figure out why it's happening and I am not sure if it is hardware or software related. I don't think it's the relays because the transmitter and receiver are on seperate boards. I am suspect of the wireless transmission and I wonder if it is possible that the data or power of the transmitter is locking up the PIC. Anyhow, please take a look at my code but without the nap command at the end, it won't work correctly.

Thanks,

Chris



@ DEVICE PIC16F870, HS_OSC, WDT_On, PWRT_ON, BOD_on, LVP_OFF , DEBUG_OFF, PROTECT_OFF

DEFINE OSC 4
DEFINE HSER_BAUD 2400
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_CLROERR 1
ADCON1=7
b1 var BYTE 'first of 4 vars to store verified good data
b2 var BYTE
b3 var BYTE
b4 var BYTE
C1 var byte
C2 var byte
C3 var byte
C4 var byte
start var byte 'first incoming byte - should be zero
sum var WORD 'incoming checksum from the sending PIC
datasum var BYTE 'used to add values of 4 incoming data bytes
errorflag var bit 'flag to indicate bad data (1 = bad or untested data)

TRISA=%11111111
TRISB=%11111111
TRISC=%10111111

HIGH portb.3
PAUSE 100
MAINLOOP:


if PORTA.5=0 THEN
B1=0
ELSE
B1=1
ENDIF
if PORTA.2=0 THEN
B2=0
ELSE
B2=1
ENDIF
if PORTA.1=0 THEN
B3=0
ELSE
B3=1
ENDIF
if PORTA.0=0 THEN
B4=0
ELSE
B4=1
ENDIF
C1=(B1*1)+(B2*2)+(B3*4)+(B4*8)


if PORTB.1=0 THEN
B1=0
ELSE
B1=1
ENDIF
if PORTB.5=0 THEN
B2=0
ELSE
B2=1
ENDIF
if PORTB.4=0 THEN
B3=0
ELSE
B3=1
ENDIF
if PORTB.2=0 THEN
B4=0
ELSE
B4=1
ENDIF
C2=(B1*1)+(B2*2)+(B3*4)+(B4*8)

if PORTC.0=0 THEN
B1=0
ELSE
B1=1
ENDIF
if PORTC.1=0 THEN
B2=0
ELSE
B2=1
ENDIF
if PORTC.2=0 THEN
B3=0
ELSE
B3=1
ENDIF
if PORTC.3=0 THEN
B4=0
ELSE
B4=1
ENDIF
C3=(B1*1)+(B2*2)+(B3*4)+(B4*8)

if PORTC.7=0 THEN
B1=0
ELSE
B1=1
ENDIF
if PORTC.5=0 THEN
B2=0
ELSE
B2=1
ENDIF
if PORTC.4=0 THEN
B3=0
ELSE
B3=1
ENDIF
if PORTB.0=0 THEN
B4=0
ELSE
B4=1
ENDIF
C4=(B1*1)+(B2*2)+(B3*4)+(B4*8)
GOSUB SENDATA


GOTO MAINLOOP

SENDATA:
sum = C1+C2+C3+C4
HSEROUT [30,C1,C2,C3,C4,sum.byte0]
pause 40
nap 0

RETURN