Thanks to mister_e and keithdoxey (and many others) I was able to make the following code that allows to PIC16F628A's to communciate serially. There are four buttons on the transmitter that turn on four pins on the receiver. The code works, but does anyone have any suggestions on making it faster and more accurate (many packets are lost and sometimes there are delays between packets)? Thanks for the help. (I need the $A5 and the "~" as a synch byte because it will eventually be hooked up to a rf link)
-Mike
Transmitter code:
-----------------
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
cmcon = 7
Current var byte
Laststate var byte
input PORTA.0
input PORTA.1
input PORTA.2
input PORTA.3
Main:
current.0 = PORTA.0
Current.1 = PORTA.1
Current.2 = PORTA.2
Current.3 = PORTA.3
if (Current <> Laststate) then
hserout [$A5,"~",Current]
Laststate = Current
endif
goto main
-------------
Receiver code
-------------
define HSER_CLROERR 1
define HSER_RCSTA 90h
define HSER_BAUD 9600
cmcon = 7
Current var byte
output PORTA.0
output PORTA.1
output PORTA.2
output PORTA.3
low PORTA.0
low PORTA.1
low PORTA.2
low PORTA.3
Main:
Hserin 20,Main,[WAIT("~"),Current]
Current = ~ Current
PORTA.0 = Current.0
PORTA.1 = Current.1
PORTA.2 = Current.2
PORTA.3 = Current.3
goto main
Bookmarks