PDA

View Full Version : Serin,Serout,Hserin,Hserout



Pesticida
- 25th June 2005, 13:02
Hi,I'm new here,
My Englisch is not very good but i try to write some questions?Sorry.:-)

I have a problem I want to write a code in PicBasicpro that send data to RS232.
I use Pic16F870 PortC.6 TX and PortC.7 RX.
Example:
DEFINE OSC 4
DEFINE HSER_RCSTA 90H ' Set receive status and control
DEFINE HSER_TXSTA 20H ' Set transmit status and control
Define HSER_BAUD 9600

INPUTdata VAR WORD

START:

PAUSE 1

HSEROUT ["ENTER A DECIMAL NUMBER BETWEEN 0 – 65535" ,10,13]

But the problem is I become on other software in Visual Basic on the PC this string:…Žิ…’ ม`ฤลƒ‰อมŒ ฮ•ย…’ ย…ิื……ฮ`p `v5us5
and another example is when i want from pc to send data to pic and back i receive just a one character .
I send Tony end come back to PC just T.
Example:
loop:
Serin PORTC.7, T2400, ReadIn
Serout PORTC.6,T2400,[ReadIn,10,13]
goto loop

I have search in internet and in PicBasicPro handbook but is no good explanation.

Thanks pesticida

mister_e
- 25th June 2005, 18:14
You should have a MAX232 between PIC and PC. Do you? :)

OR use SERIN/SEROUT in inverted mode... N2400 could work.

Also i've notice you use HSERIN/HSEROUT to acheive a 9600 Baud comm... by using your setting the error % will be about 7% wich is really bad.

If you change your settings to
DEFINE OSC 4
DEFINE HSER_RCSTA 90h ' Set receive status and control
DEFINE HSER_TXSTA 24h ' Set transmit status and control + BRGH=1
Define HSER_BAUD 9600

this will gives you an error % of 0.16%... far better

Bruce
- 25th June 2005, 19:19
I send Tony end come back to PC just T.
Example:
loop:
Serin PORTC.7, T2400, ReadIn
Serout PORTC.6,T2400,[ReadIn,10,13]
goto loop

Tony consists of 4 bytes. You would need to receive then send 4 bytes.

Serin PORTC.7, T2400, Char1, Char2, Char3, Char4
Serout PORTC.6,T2400,[Char1, Char2, Char3, Char4,10,13]

Or use Serin2/Serout2 with the STR modifier.

Pesticida
- 27th June 2005, 21:52
Hi all,
Thanks for the answers,Yes I have Max232,I have just try Hserout ["my text"] and this work good .I dont know why :-).
I think I must learn more about RS232 and all the little details like baud rate, inverted or not inverted :-(.


Thanks!!!
Regard Pesti

Pesticida
- 28th June 2005, 09:27
Hi,
I have use now :
DEFINE HSER_TXSTA 24h ' Set transmit status and control + BRGH=1
Define HSER_BAUD 9600

and all work very good thanks, you are the bests !

Regard Pesti.