PDA

View Full Version : PIC to RS232 interface



thon
- 15th January 2004, 02:54
Hi can anyone give me some tips or links where to find some samples on PIC16f877 to RS232 interface. I have a project that displays the output at the LCD. I want to connect my PIC to my PC via RS232 to display the output there using a GUI program maybe I'll be using Visual Basic 6.0 at the PC side.

Can anyone give show me how to do this?

thon
- 16th January 2004, 03:49
I am using PIC Basic Pro at the PIC side and VB6 at the PC side. Im using MAX232 for the serial interface. can anyone help me with this I dont know how to start.

mat janssen
- 16th January 2004, 07:19
When I use this I do:
for 2400 baud

DEFINE SER2_BITS 8

pinin VAR PORTC.7
pinout VAR PORTC.6

SerOut2 pinout,396,[B1]

SerIn2 pinin,396,[B1]

or

SerIn2 pinin,396,50,verdr,[WAIT ("X"),B1]

depents on the application look at page 132(5.72) and further.

And in the pc I programm in qbasic(7.1)

and this works always.

bobthebud
- 23rd January 2004, 15:56
Here are some working code snippets. This is from a standalone monitor which records the data into eprom and downloads to a Pocket PC when requested. it can also work live online to a standard PC. Unfortunately I do not have the VB code for the PC's as this is kept by my software guy. Embedded code is the territory of the hardware engineer.

set registers:-

INTCON=$80 '# sets global interrupt
OPTION_REG=$C0 '# sets RB.0 interrupt to positive edge
TXSTA=$24 '# sets transmit status register
RCSTA=$90 '# sets receive staus register
SPBRG=$81 '# sets baud rate register for 9600 baud
PIE1=$20 '# enables usart receive intertupt

rs232: '# This is the RS232 comms protocol

INTCON=$80

hserin 100,commerr2,[commin1]

if (commin1="*") then goto rigdata

if (commin1="=") then

hserin 20,answer,[commin1]

if (commin1<>"$") then goto commerr2

answer:

hserout ["OK",carret,newlin]

hserin 2000,commerr2,[commin1]

if (commin1="$") then

hserout [serial1,serial2,dec serial3,carret,newlin]

hserin 2000,commerr2,[commin2]

if (commin2="+") then

The registers are at the top of the code check the book for values. The remainder is the first part of the comms protocol. Here the decision is made as to what type of host is connected and the correct action taken(reroute for online(rigdata). In the case of the Pocket PC download the unit replies with its serial number, the rest of the code covers some classified stuff but what I have given you should put you on the right path. NOTE that I am setting the interrupt register directly as there can be latency problems using the PBP ENABLE INTERRUPT and DISABLE
INTERRUPT commands.

Best of luck and happy coding.

Bob

gpersha
- 12th February 2004, 03:01
I have always had trouble using Visual Basic to communicate via a RS-232 interface to my company's PIC devices. Perhaps, if I was a better programmer it might be different. About a year ago, I switched to Liberty Basic and never looked back. It interfaces to the COM port like a dream - never loose a byte now. The $30 US cost doesn't hurt either.

Jerry