So between post #34 and #39, that is your entire code for both TX and RX?
And is it possible for you to connect an LCD to the RX for troubleshooting? Or at least replace those relays with LEDs.
So between post #34 and #39, that is your entire code for both TX and RX?
And is it possible for you to connect an LCD to the RX for troubleshooting? Or at least replace those relays with LEDs.
Skimask here is the entire program for both sides:
TRANSMITTER
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 dout
goto findkey
pressed:
if A= 0 then pause 10
if A= 0 then keydata = %01010110
if B = 0 then pause 10
if B = 0 then keydata = %01011001
if C = 0 then pause 10
if C= 0 then keydata = %01011010
if D = 0 then pause 10
if D = 0 then keydata = %01100101
if E = 0 then pause 10
if E = 0 then keydata = %01100110
if F = 0 then pause 10
if F = 0 then keydata = %01101001
if G = 0 then pause 10
if G = 0 then keydata = %01101010
return
dout:
gosub pressed
low dgood
pause 100
chk_sum = (address + address)
chk_sum = chk_sum + (keydata + keydata)
goto transmit
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]
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]
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
end
RECEIVER
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
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
serpin VAR porta.1
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
PAUSE 50
loop:
clear
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=%01010110 then rly1
if mydata1=%01011001 then rly2
if mydata1=%00000000 then rly2
if mydata1=%01011010 then rly3
if mydata1=%00000000 then rly3
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
if mydata1=%01011001 then high 1
if mydata1=%00000000 then low 1
goto loop
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
No LCD, I do have leds and also monitoring the pins with scope.
thanks
Quite frankly...what a cluster! You really have to work on your flow. There's too many places where you expect a value to be during one if/then, and then be there again at another if/then even though you just got done changing it.
Give me a few minutes to work it out...
Ok, for awhile, forget about your receiver...
Forget about the sync, forget about the preamble, forget about the checksum, forget about everything else. Pretend this TX is transmitting to nowhere and nowhere likes it that way...
You know how to set up your PIC, you can set the pins, etc....
You have 7 buttons, each connected to a PortB pin...
When these buttons AREN'T pressed, the pins are high, when pressed the pin is low...
Easy enough...
Write a program that does nothing but reads the state of the pins and sends that value out in a SEROUT statement of some sort.
ok, on the transmitting side after stripping everything down I am sending the data for the button that is pressed and when I release each button I send the data again and it clears that particular output on the receiver. Seems to work ok. Thanks for everyones help and I read something here on the forum about closing the post when finished so,... if so how do I do that?
Well, what I'm trying to do is show you a much better way of doing things, one that's much much easier to read thru and takes up a lot less code space, by breaking it down, and building it back up again.
Closing - I wouldn't worry about it. I think I've only ever seen a handful of threads that are closed here.
Bookmarks