PDA

View Full Version : troubles with serial communication



lopgar71
- 9th August 2013, 04:12
hello all, I have problems with this code, do not know why it does not work,


compiles fine without errors. I appreciate any help,


this is the code:


'P16f88_Tx


INCLUDE "modedefs.bas"
DEFINE OSC 4
ansel =% 00000000
Led var PORTB.4
Var BotonA PORTB.1


led high
pause 500
led low


transmit:
if botona = 0 then Send 1
led low
goto transmit




Send 1:
led high
serout PORTB.0, T1200, ["A"]
goto transmit
End




'P16f88_Rx


INCLUDE "modedefs.bas"
DEFINE OSC 4
ansel =% 00000000
VAR leda PORTB.1
var data byte


high leda
pause 250
leda low




receive:
PORTB.0 serin, T1200, [data]
pause 500
if data = "A" then one
leda low
goto receive


one:
high leda
goto receive
end


regards!

HenrikOlsson
- 9th August 2013, 06:14
Hi,


compiles fine without errors. I appreciate any help,
You're got to be kidding me, does THAT code really compile without errors?
I see at least 8 errors (that's about one error every 4th line of code) preventing it from compiling without errors, for example:


Var BotonA PORTB.1 - should be BotonA VAR PortB.1
led high - should be high led
PORTB.0 serin, T1200, [data] - should be Serin PortB.0, T1200, [data][/i]


/Henrik.

rsocor01
- 9th August 2013, 14:23
Make sure you configure PORTB.0 as an output port with the TRISB register.

LinkMTech
- 9th August 2013, 20:38
compiles fine without errors.

I saw too many errors then would not compile without too many errors.

I fixed the reported errors until it compiled without any, but did not test your code.
Compare them and test.


'P16f88_Tx


INCLUDE "modedefs.bas"
DEFINE OSC 4
ansel = %00000000
Led var PORTB.4
BotonA Var PORTB.1


high led
pause 500
low led


transmit:
if botona = 0 then Send_1
low led
goto transmit




Send_1:
high led
serout PORTB.0, T1200, ["A"]
goto transmit
End

'--------------------------------

'P16f88_Rx


INCLUDE "modedefs.bas"
DEFINE OSC 4
ansel = %00000000
leda VAR PORTB.1
RX_data var byte


high leda
pause 250
low leda




receive:
serin PORTB.0, T1200, [RX_data]
pause 500
if RX_data = "A" then one
low leda
goto receive


one:
high leda
goto receive
end

rsocor01
- 10th August 2013, 03:09
Also, the TRISB register should be set properly.

aratti
- 11th August 2013, 09:57
In addition to Louie's correction you need to set the oscillator register and Port register. Add the following Lines of code:

CMCOM = 7 ' comparator off

OSCCON = %01100010 ' oscillator @ 4 MHz

TrisB =%00000010 'for Tx device ' pin B.1 is an input all other outputs

TrisB =%00000001 'for Rx device ' pin B.0 is an input all other outputs

Cheers

Al.

lopgar71
- 12th August 2013, 23:39
hello, thank you very much for responding, proves and tell you how I was.
regards!

lopgar71
- 12th April 2014, 23:49
thank you all, sorry for so late to respond, the program I worked perfectly.
Greetings!