PDA

View Full Version : Serial com: in need of help



mbw123
- 15th October 2006, 20:03
This code that runs on two 16F628A's is not working. There are four buttons on the transmitter that control the five pins on the receiver. A packet is sent out for each change in the button state. Please help!
Thanks.

-Mike

Transmitter code
----------------
define HSER_TXSTA 20h
define HSER_BAUD 2400

cmcon = 7

sone var byte
sone = 0
stwo var byte
stwo = 0
sthree var byte
sthree = 0
sfour var byte
sfour = 0
Synch var byte
Synch = "~"
Pre var byte
Pre = $A5

Main:

if (PORTA.0 = 0 && sone = 0) then
hserout [Pre,Synch,"1"]
sone = 1
pause 200
endif
if (PORTA.0 = 1 && sone = 1) then
hserout [Pre,Synch,"2"]
sone = 0
pause 200
endif


if (PORTA.1 = 0 && stwo = 0) then
hserout [Pre,Synch,"3"]
stwo = 1
pause 200
endif
if (PORTA.1 = 1 && stwo = 1) then
hserout [Pre,Synch,"4"]
stwo = 0
pause 200
endif


if (PORTA.2 = 0 && sthree = 0) then
hserout [Pre,Synch,"5"]
sthree = 1
pause 200
endif
if (PORTA.2 = 1 && sthree = 1) then
hserout [Pre,Synch,"6"]
sthree = 0
pause 200
endif


if (PORTA.3 = 0 && sfour = 0) then
hserout [Pre,Synch,"7"]
sfour = 1
pause 200
endif
if (PORTA.3 = 1 && sfour = 1) then
hserout [Pre,Synch,"8"]
sfour = 0
pause 200
endif

goto Main

Receiver code
-------------
define HSER_CLROERR 1
define HSER_RCSTA 90h
define HSER_BAUD 2400

Msg Var BYte
cmcon = 7

Main:
hserin [WAIT("~"),Msg]


if (Msg = "1") then
high PORTA.0
goto main
endif
if (Msg = "2") then
low PORTA.0
goto main
endif

if (Msg = "3") then
high PORTA.1
goto main
endif
if (Msg = "4") then
low PORTA.1
goto main
endif

if (Msg = "5") Then
high PORTA.2
goto main
endif
if (Msg = "6") then
low PORTA.2
goto main
endif

if (Msg = "7") Then
high PORTA.3
goto main
endif
if (Msg = "8") then
low PORTA.3
endif
goto main

-------------------

Thanks again!

mister_e
- 16th October 2006, 15:01
Some IF THEN statement are weird to me

if (PORTA.0 = 0 && sone = 0) then

Should be

if (PORTA.0 = 0) AND (sone = 0) then

OR

if (PORTA.0 = 0) && (sone = 0) then

There's few missing info.
Config Fuse setting.
Internal OSC or external?
wich speed?
Schematic?