• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

urgent!! interfacing the pic16f877 to the pc serial port

Status
Not open for further replies.

foosm

New Member
hi all, lets say i have a pic16f877 with some 9 bit data stored in its registers... can i send these data to a PC running windows OS through the serial port... i have to use C++ pogramming on the PC side...

how do i go about it....?? any tutorials or even ready templates i can use...???

thanks a million
 

Nigel Goodwin

Super Moderator
Most Helpful Member
foosm said:
hi all, lets say i have a pic16f877 with some 9 bit data stored in its registers... can i send these data to a PC running windows OS through the serial port... i have to use C++ pogramming on the PC side...

how do i go about it....?? any tutorials or even ready templates i can use...???

thanks a million
Check my PIC tutorials at http://www.winpicprog.co.uk, I have tutorials for using RS232 in both hardware and software.

If you really want to transfer 9 bits, you will probably need to do it as two bytes - a single byte is normally only 8 bits, although you could use non-standard methods.
 

TheAnimus

New Member
By 9bit data do u mean 8bit + parity?

rs232 is an 8bit "data-space" protocol, you could do something clever with the parity bit, but most computers have hardware USART decoders, and you might find it automatically discards the "deffective" parity bit.
 

StupidDum

New Member
serial is the simplest interfacing to PC
well.. i just connect 3 wires, Ground, Transmit, Receive
handshaking is not necessary

hmm... now i'm interested to interface parallel port..
ehh... but kind of lazy to do some study..
besides 8 data pin, what other necessary pin i need to connect from parallel port to PIC?? ignore those Out of Paper pin..etc..
 

Exo

Active Member
If you want to use the parallel port in SPP mode (standard mode, least programming hassle) then those 8 data bits are only output, for input into the pc you can use the other signals like out of paper, online, ...

do a search on google, comes up with lots ot results about pinout and the right registers to adress
 

foosm

New Member
i realsie the 16f877 had got built in USART capabilities...

now i wanna use the asyn. mode....mainly to transmit data out of my pic to a pc...here are my questions:

1. if i had loaded the data into the TXREG register, can i proceed to carry out other instructions? will the transmitting carry out in the background, or do i have to wait till the byte is transmitted b4 carrying on?

2. the pic16f877 has both transmit and receive pins....are they independent of each other?

3. i f i wanna interface to a pc serial port, is it necessary to setup handshaking ??

4. anyone can help me with C++ serial port prggramming ?? like wat functions are available??...i dun need the GUI... just running in MSDOS shell would be fine....

thanks again.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
foosm said:
i realsie the 16f877 had got built in USART capabilities...

now i wanna use the asyn. mode....mainly to transmit data out of my pic to a pc...here are my questions:

1. if i had loaded the data into the TXREG register, can i proceed to carry out other instructions? will the transmitting carry out in the background, or do i have to wait till the byte is transmitted b4 carrying on?

2. the pic16f877 has both transmit and receive pins....are they independent of each other?

3. i f i wanna interface to a pc serial port, is it necessary to setup handshaking ??

4. anyone can help me with C++ serial port prggramming ?? like wat functions are available??...i dun need the GUI... just running in MSDOS shell would be fine....

thanks again.
1. Yes you can carry on doing other things, once initiated the transmission of a byte is automatic.

2. As far as I know yes, you can use either or both.

3. Handshaking is completely optional, only needed is you are sending large quantities of data very fast - in which case you need to pause the transmitter while the receiving end catches up. If you are writing both ends of the link it's no problem at all, simply send the data in smallish packets - initiated by the receive end.

4. No idea, I don't use C or C++ - if you want Turbo Pascal serial port help, I'm your man!.
 

foosm

New Member
hi all, can i just connect my PIC pins to the serial port directly ??? is the voltage levels compatiable ??

if i can connect them directly, do i connect my TX (PIC) to RX (PC) and RX (PIC) to TX (PC).... and lastly, the GND(PC) to a common gnd with the PIC ??

thanks
 

Nigel Goodwin

Super Moderator
Most Helpful Member
foosm said:
hi all, can i just connect my PIC pins to the serial port directly ??? is the voltage levels compatiable ??

if i can connect them directly, do i connect my TX (PIC) to RX (PC) and RX (PIC) to TX (PC).... and lastly, the GND(PC) to a common gnd with the PIC ??

thanks
No, you can't connect them directly - a PIC works at 0-5V and RS232 works at +/-12V. If you consult my tutorial link I posted earlier it gives examples of both hardware and software for PIC to RS232.

A MAX232 is a common chip used to convert from RS232 (and is the one used in my tutorial), but you can do it crudely with a couple of resistors, this is how the BASIC Stamp does it!.
 

ivancho

New Member
Although the RS232 levels are different fromt he 0-5V level that the PIC uses you can connect the PIC to the serial port. One thing is that the connection might not be standard, for debugin purposes is perfect.

The lenght of the cable can't be too long, the longest I have used is about 5-6 feet. No trouble what so ever. The highest baudrate I have used is 19200.

Your connection should have a limiting resistor, a 2.2K will be good... I normally just connected straight, without any trouble.

It works because of the clampind diodes of the PIC, that allows to read the -12v to +12V swing. The serial port even in my 486 laptop recognize the 5-0V levels.... one thing to have in mind to send serially with the PIC connected to the PC you have to send the data inverted..... if you use a MAX232 you send the data no-inverted (true mode).

Ivancho
 

BronzeG3

New Member
The MAX232 and the DS275 go both ways. One set of pins will go from RS232->TTL and another set will go from TTL-> RS232.

As for software to capture serial information, I like using Real Term http://realterm.sourceforge.net/. It looks complex but you can ignore 80% of the settings.
 

petrv

New Member
Yes you can use USB if (a few possibilities, choose one) :

a) use USB to RS-232 adapter.
b) use USB to RS-232 chip (like the one from FTDI)

c) use a PIC micro with USB support (PIC18F2455, PIC18F4550 .... etc)

Petr
 

BronzeG3

New Member
petrv said:
Yes you can use USB if (a few possibilities, choose one) :

a) use USB to RS-232 adapter.
b) use USB to RS-232 chip (like the one from FTDI)

c) use a PIC micro with USB support (PIC18F2455, PIC18F4550 .... etc)

Petr
If you end up using a USB-> RS232 adapter, you will still need to use a level conversion chip unless you hack the adapter open.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top