INCLUDE "bs2defs.bas"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F628a, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628a, MCLR_ON
' Master Clear Options (Internal)
@ DEVICE pic16F628a, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
serpin VAR porta.1 'serial input pin
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
PAUSE 50 ' settle time

loop:
clear 'Do I really need to do this? I tried to make sure everything is back to 0
gosub loop1 'After button is released on tx mydata1=%00000000
CheckSum = (address1 + address2) 'address sent %00000001 added together in this case this = 10
CheckSum = CheckSum + (mydata1 + mydata2) '10 + (%00000000 +%00000000)= 10
IF checksum != chk_sum THEN loop 'checksum = chk_sum because of above
IF (mydata1) != (mydata2) THEN loop '(mydata1) = (mydata2)
IF (address1) != (address2) THEN loop '(address1) != (address2)
'Since everything should be a match We move on
if mydata1=%01010110 then rly1 'this works so I will go to the next one

if mydata1=%01011001 then rly2 '1st case will turn portb.1 on
if mydata1=%00000000 then rly2 '2nd case appears to do nothing but as I stated above the check
'should be correct and mydata1=%00000000
if mydata1=%01011010 then rly3 'I will skip the rest of this area because it
if mydata1=%00000000 then rly3 'behaves the same as rly2 the rly6 rly7 ok.

if mydata1=%01100101 then rly4
if mydata1=%00000000 then rly4

if mydata1=%01100110 then rly5
if mydata1=%00000000 then rly5

if mydata1=%01101001 then rly6
if mydata1=%01101010 then rly7

rly1:
if mydata1=%01010110 then pause 10
if mydata1=%01010110 then toggle 0
pause 10
goto loop
rly2:
if mydata1=%01011001 then pause 10 'Down here the fun begins
if mydata1=%01011001 then high 1 '1st case will turn portb.1 on
if mydata1=%00000000 then low 1 'Since the checksum is correct why didn't I get here
'mydata1=%00000000 so this should go low but doesn't
goto loop 'here we go back to loop so I will goto loop1
rly3:
if mydata1=%01011010 then pause 10
if mydata1=%01011010 then high 2
if mydata1=%00000000 then low 2
goto loop
rly4:
if mydata1=%01100101 then pause 10
if mydata1=%01100101 then high 3
if mydata1=%00000000 then low 3
goto loop
rly5:
if mydata1=%01100101 then pause 10
if mydata1=%01100110 then high 4
if mydata1=%00000000 then low 4
goto loop
rly6:
if mydata1=%01101001 then pause 10
if mydata1=%01101001 then TOGGLE 5
pause 10
goto loop
rly7:
if mydata1=%01101010 then pause 10
if mydata1=%01101010 then TOGGLE 6
pause 10
GOTO loop


loop1:
SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return
'loop1 receives the following
'transmit:

' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
' if keyin = nokey then pause 10
' if keyin = nokey then x2
' goto findkey

'x2:
' high dgood
' keydata = %00000000
' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
' goto findkey

'on the GOSUB loop1 after the tx button is released I should move on to x2
'x2 sends the preamble, and I am still getting my synch plus address,data an chk_sum
'so I should pass through the checksum area of my receiver code and on to the rest of
'my program. When the program arrives at "if mydata1=%00000000 then rly2 " it should
'ask "if mydata1=%00000000 then low 1" and respond and portb.0 should go low but it
'never seems to get there. I switch from the If/Then/Else to make it simpler for me
'to break it down.

'I've been over the tx side and I feel confident everything there is working correctly

' Am I heading in the right direction?