PDA

View Full Version : breadboard and hserout interference?



mbw123
- 7th October 2006, 16:50
I have two PIC16F628A's and I am trying to get them to communicate serially with each other. When a button is pressed, the LED on the receiving PIC should go on (similarily, when it is released the LED with go off). Unfortunately this is not working. I am wondering if the breadboard is somehow interfering with the packets...my code is below.

Any help is appreciated!

-Mike

transmitter
---------------------

' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

cmcon = 7

Main:

If (PORTA.1 = 0) then
hserout ["1"]
endif
if (PORTA.1 = 1) then
hserout ["2"]
endif
goto main
end

-----------------------
Receiver
------------------------

define HSER_CLROERR 1
define HSER_RCSTA 90h
define HSER_BAUD 2400

Msg Var BYte
cmcon = 7

Main:
hserin [Msg]
if (Msg == "1") then
high PORTA.1
endif
IF (Msg == "2") then
low PORTA.1
endif
goto main

keithdoxey
- 7th October 2006, 17:44
Try removing one of the "=" from each "IF" in your receiver program.

mister_e
- 7th October 2006, 17:50
my bet is more about possibility of a buffer overflow.
Try this one for the transmitter


Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

cmcon = 7

Main:

If (PORTA.1 = 0) then
hserout ["1"]
while PORTA.1=0 : Wend : pause 500
endif
if (PORTA.1 = 1) then
hserout ["2"]
while PORTA.1=1 : wend : pause 500
endif

goto main
end

what about your crystal speed? Config fuses? Schematic?

DynamoBen
- 7th October 2006, 18:30
To answer your question directly, I have done a lot of serial projects on breadboards and never had an issue.

Ron Marcus
- 7th October 2006, 18:31
my bet is more about possibility of a buffer overflow.
Try this one for the transmitter


Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

cmcon = 7

Main:

If (PORTA.1 = 0) then
hserout ["1"]
while PORTA.1=0 : Wend : pause 500
endif
if (PORTA.1 = 1) then
hserout ["2"]
while PORTA.1=1 : wend : pause 500
endif

goto main
end

what about your crystal speed? Config fuses? Schematic?
It sounds like you only want to send a character on the state change of the switch. Use a bit variable such as current_state for the last known state.
This way, you won't hang the program up waiting for the switch to change.

Read_switch:
if (PORTA.1= current_state) then goto main ; No change goto main program
hserout [PORTA.1 + $30] ; Make the switch value the ASCII equivelent and send it.
current_state = PORTA.1 ; Current_state = switch value
goto main ; How neat is that?!?

mister_e
- 7th October 2006, 18:42
for sure i need to sleep!

mbw123
- 8th October 2006, 20:15
Thanks for the tips guys. I try it out and get back to you on the results...

-Mike

mbw123
- 11th October 2006, 02:29
Thanks for the responses. I tested the program and it turns out that you were right. It must have been a buffer overflow. One last thing, though. Eventually I will connect Rx and Tx modules to my PIC's. To synchronize these I am trying to send synchronizing variables to balance the modules. My code must be incorrect, though, because it is not working. Here is the code for the transmitter:

Pre CON $A5
Synch CON "~"
HSEROUT [Pre,Synch,"1"]

and the receiver code,

Synch CON "~"
HSERIN [WAIT(Synch),Msg]

Thanks for the help!

-Mike

DynamoBen
- 11th October 2006, 04:04
Try this instead:

HSERIN [WAIT("~"),Msg]

mbw123
- 14th October 2006, 01:52
Thank you very much everyone for the help and patience. I finally got it working. mister_e mentioned a buffer overflow. Is that on the transmitter, receiver or both? Thanks again everyone...