Ok, I don't like to post the code because it's not written very well and I am not an expert but maybe someone can help me. Here is the code:
@ DEVICE PIC16F870, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF , DEBUG_OFF, PROTECT_OFF
DEFINE OSC 20
DEFINE HSER_BAUD 2400
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_CLROERR 1
ADCON1=7
b1 var WORD 'first of 4 vars to store verified good data
b2 var WORD
b3 var WORD
b4 var WORD
in1 var WORD 'first of 4 vars to store incoming data
in2 var WORD
in3 var WORD
in4 var WORD
start var byte 'first incoming byte - should be zero
sum var WORD 'incoming checksum from the sending PIC
datasum var WORD 'used to add values of 4 incoming data bytes
errorflag var bit 'flag to indicate bad data (1 = bad or untested data)
TRISA = %00000000
TRISC = %10000000
TRISB = %00000000
TRISD = %00000000
pause 100
PORTB.0=0
PORTB.1=0
PORTB.2=0
PORTB.3=0
PORTB.4=0
PORTB.5=0
PORTB.6=0
PORTB.7=0
PORTA.0=0
PORTA.1=0
PORTA.2=0
PORTA.3=0
PORTA.4=0
PORTA.5=0
PORTA.6=0
PORTA.7=0
PORTC.0=0
PORTC.1=0
PORTC.2=0
PORTC.3=0
PORTC.4=0
PORTC.5=0
PORTC.6=0
mainloop:
IF RCSTA.1 = 1 THEN 'if USART overrun error flag OERR is set...
RCSTA.4 = 0 'clear and then set CREN bit to recover
RCSTA.4 = 1
in1 = RCREG 'read data to clear out RCREG
IF PIR1.5 = 1 THEN in1 = RCREG 'clear possible 2nd byte in RCREG
ENDIF
WHILE PIR1.5 = 0 'stay here until USART receives data
'LOW portc.3 'portc.3 has diagnostic LED
WEND
'HIGH portc.3 'data in RCREG; turn on diagnostic LED
errorflag = 1
GOSUB getdata
IF errorflag = 0 THEN 'only updates relays if data judged to be good
if b1=0 and b2=1 and b3=11 THEN GOSUB ONN1
if b1=0 and b2=1 and b3=12 THEN GOSUB OFF1
if b1=0 and b2=2 and b3=11 THEN GOSUB ONN2
if b1=0 and b2=2 and b3=12 THEN GOSUB OFF2
if b1=0 and b2=3 and b3=11 THEN GOSUB ONN4
if b1=0 and b2=3 and b3=12 THEN GOSUB OFF4
if b1=0 and b2=4 and b3=11 THEN GOSUB ONN3
if b1=0 and b2=4 and b3=12 THEN GOSUB OFF3
if b1=0 and b2=5 and b3=11 THEN GOSUB ONN5
if b1=0 and b2=5 and b3=12 THEN GOSUB OFF5
if b1=0 and b2=6 and b3=11 THEN GOSUB ONN6
if b1=0 and b2=6 and b3=12 THEN GOSUB OFF6
if b1=0 and b2=7 and b3=11 THEN GOSUB ONN7
if b1=0 and b2=7 and b3=12 THEN GOSUB OFF7
if b1=0 and b2=8 and b3=11 THEN GOSUB ONN8
if b1=0 and b2=8 and b3=12 THEN GOSUB OFF8
if b1=0 and b2=9 and b3=11 THEN GOSUB ONN0
if b1=0 and b2=9 and b3=12 THEN GOSUB OFF0
if b1=1 and b2=0 and b3=11 THEN GOSUB ONN9
if b1=1 and b2=0 and b3=12 THEN GOSUB OFF9
if b1=1 and b2=1 and b3=11 THEN GOSUB ONN11
if b1=1 and b2=1 and b3=12 THEN GOSUB OFF11
if b1=1 and b2=2 and b3=11 THEN GOSUB ONN13
if b1=1 and b2=2 and b3=12 THEN GOSUB OFF13
if b1=1 and b2=3 and b3=11 THEN GOSUB ONN12
if b1=1 and b2=3 and b3=12 THEN GOSUB OFF12
if b1=1 and b2=4 and b3=11 THEN GOSUB ONN14
if b1=1 and b2=4 and b3=12 THEN GOSUB OFF14
if b1=1 and b2=5 and b3=11 THEN GOSUB ONN16
if b1=1 and b2=5 and b3=12 THEN GOSUB OFF16
if b1=1 and b2=6 and b3=11 THEN GOSUB ONN15
if b1=1 and b2=6 and b3=12 THEN GOSUB OFF15
if b1=9 and b2=9 and b3=11 then gosub allon
if b1=9 and b2=9 and b3=12 then gosub alloff
ENDIF
goto mainloop:
getdata:
IF RCSTA.1 = 1 THEN xfer 'USART overflow error - bad data
HSERIN 40, xfer, [start, in1, in2, in3, sum]
IF start <> 0 THEN xfer 'if first byte isn't 0 assume bad data
datasum = in1 + in2 + in3 'add the 4 bytes and compare to sum
IF datasum = sum THEN errorflag = 0 'if compare is good, assume good data
xfer:
IF errorflag = 0 THEN
B1 = in1
b2 = in2
b3 = in3
ENDIF
RETURN
ONN1:
HIGH PORTB.7
goto mainloop
OFF1:
LOW PORTB.7
GOTO MAINLOOP
ONN2:
HIGH PORTB.3
goto mainloop
OFF2:
LOW PORTB.3
GOTO MAINLOOP
ONN3:
HIGH PORTB.4
goto mainloop
OFF3:
LOW PORTB.4
GOTO MAINLOOP
ONN4:
HIGH PORTA.3
goto mainloop
OFF4:
LOW PORTA.3
GOTO MAINLOOP
ONN5:
HIGH PORTB.5
goto mainloop
OFF5:
LOW PORTB.5
GOTO MAINLOOP
ONN6:
HIGH PORTA.2
goto mainloop
OFF6:
LOW PORTA.2
GOTO MAINLOOP
ONN7:
HIGH PORTC.2
goto mainloop
OFF7:
LOW PORTC.2
GOTO MAINLOOP
ONN8:
HIGH PORTC.3
goto mainloop
OFF8:
LOW PORTC.3
GOTO MAINLOOP:
ONN9:
HIGH PORTC.1
GOTO MAINLOOP
OFF9:
LOW PORTC.1
goto mainloop
ONN0:
HIGH PORTC.0
GOTO MAINLOOP
OFF0:
LOW PORTC.0
goto mainloop
ONN11:
HIGH PORTA.5
GOTO MAINLOOP
OFF11:
LOW PORTA.5
goto mainloop
ONN12:
HIGH PORTB.1
GOTO MAINLOOP
OFF12:
LOW PORTB.1
goto mainloop
ONN13:
HIGH PORTB.0
GOTO MAINLOOP
OFF13:
LOW PORTB.0
goto mainloop
ONN14:
HIGH PORTC.5
GOTO MAINLOOP
OFF14:
LOW PORTC.5
goto mainloop
ONN15:
HIGH PORTB.2
GOTO MAINLOOP
OFF15:
LOW PORTB.2
goto mainloop
ONN16:
HIGH PORTC.4
GOTO MAINLOOP
OFF16:
LOW PORTC.4
goto mainloop
alloff:
LOW PORTA.2
LOW portc.4
LOW portb.2
LOW portc.5
LOW portb.0
LOW portb.1
LOW PORTB.5
LOW porta.5
LOW portc.0
LOW portc.1
LOW portc.2
LOW portc.3
LOW porta.3
LOW portb.3
LOW portb.4
LOW portb.7
goto mainloop
allon:
PORTB.0=1
PORTB.1=1
PORTB.2=1
PORTB.3=1
PORTB.4=1
PORTB.5=1
PORTB.6=1
PORTB.7=1
PORTA.0=1
PORTA.1=1
PORTA.2=1
PORTA.3=1
PORTA.4=1
PORTA.5=1
PORTA.6=1
PORTA.7=1
PORTC.0=1
PORTC.1=1
PORTC.2=1
PORTC.3=1
PORTC.4=1
PORTC.5=1
PORTC.6=1
goto mainloop




Bookmarks