Thanks Joe for the example, I did try it but it locks up, let me explain. On the receiver I have read and reread what I have written, but I added a datagood LED that way I can see what is going on the the variable mydata1. When the momentary output stays on, datagood is also on so I don't think the mydata1 is %00000000 so what is your opinion. I removed the other outputs from the program to reduce the space here. Here is the receiver:
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ 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
'do I need vrcon=0 ?
datagood VAR porta.2
serpin VAR porta.1 'serial input pin
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
PAUSE 50
loop:
mydata1=%00000000
gosub loop1
CheckSum = (address1 + address2)
CheckSum = CheckSum + (mydata1 + mydata2)
IF checksum != chk_sum THEN loop
IF mydata1 != mydata2 THEN loop
IF address1 != address2 THEN loop
IF (mydata1>0) && (checksum = chk_sum) THEN
datagood = 1
else
datagood = 0
endif
if mydata1=%01010110 then loop2
if mydata1=%10101111 then loop2
if portb.0=1 then loop3
goto loop
loop2:
if mydata1=%10101111 then high 0 'master relay turn on
pause 50
if mydata1=%01010110 then portb=0 'master relay turn off
pause 50
goto loop
loop3:
if mydata1=%01011001 then
high 1 'portb.1 is on
else
low 1 'portb.1 is off
endif
GOTO loop
loop1:
SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
Return
And here is the tx:
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_ON
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
define osc 4
CMCON=%00000111
trisb = %11111111
trisa = %00010111
chk_sum var byte
dgood var porta.2
serpin var porta.3
nokey con %11111111
synch con 254
address con %00000001
keyin var portb
keydata var byte
E VAR PORTB.0
D VAR PORTB.1
G VAR PORTB.2
A VAR PORTB.3
B VAR PORTB.4
C VAR PORTB.5
F VAR PORTB.6
na VAR PORTB.7
PreAmble CON $A5 ' 10100101 preamble
findkey:
if keyin != nokey then pressed
goto findkey
pressed:
if A = 0 and B = 0 then p3
if A = 0 then p1
if B = 0 then p2
goto findkey
p1:
if A = 0 then keydata = %01010110
gosub validate
gosub transmit
goto findkey
p2:
if B = 0 then keydata = %01011001
gosub validate
gosub transmit
pause 250
if B = 1 then pause 10
if B = 1 then keydata=%00000000
gosub validate
gosub transmit
goto findkey
p3:
if A = 0 && B = 0 then keydata = %10101111
gosub validate
gosub transmit
goto findkey
validate:
chk_sum = (address + address)
chk_sum = chk_sum + (keydata + keydata)
return
transmit:
serout serpin,N2400,[$55,$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,$AA,sy nch,address,address,keydata,keydata,chk_sum]
return
Thanks again
Bookmarks