Continue to Site

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.

  • 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.

16F627 serial port help

Status
Not open for further replies.

stef

New Member
I have a 16F627 circuit with a 232 chip (HIN232CP) connected to the onboard USART. I'm using async mode 9600 baud with 4Mhz crystal.

I got the comms working with the circuit connected to the PC serial port, but the ASCII I send from the PIC does not come through as the correct symbol on Hyper Terminal ie the zero digit (30Hex ; 48 dec) will come through as a Greek type of symbol (theta or something to that effect).

When I debugged with PICstart Plus, the correct value was loaded in TXREG.

Could it be the 232 chip or the 4Mhz crystal or my software perhaps??
 
There may be two problems.
1) Either baud rate of your PC (hyper terminal) and PIC are different or
2) The font in hyper terminal is not proper. Set it to "Courier New" for best results.
 
I seem to always say the same thing.... but here it goes one more time.... :lol:
Check as mention before the baudrate....
Then see if you are sending in an inverted or true mode. Are you using assembler, PICBasic, C?

In true mode a 1 is represented as a 5V,since you are using a MAX232 that is the way you want to do it. In inverted mode a 1 is represented by a 0. The MAX232 wil invert your output and make it the right voltage levels :wink:

Ivancho
 
Found the problem. As I double checked my settings to quote in the reply I was going to post, I found that I loaded SPBRG with D'64' in stead of D'25'. :oops: :oops:

I looked in the 10Mhz table on the data sheets. The 4Mhz data is the table below that one :lol: :lol: So much for saving time... should have done the damned calculation :lol: :lol:

Thanks for the tip!!
 
also check bit TXIF of register PIR1 is set before you load your value into TXREG. It is a bit that tells you the usart is ready to send new data.
 
hi stef,

i am working on a similar assignment... but i am using a PIC16F877 . but i suppose it is the same as your pic.. i am using the in-built USART in the asyn mode. and i also using HIN232CP.

can u please help me...

1. How do i connect the pic to pc ? i only have a rough idea... am i correct in doing the following: i connect my PIC's 'TRANSMIT' to the TTL input on the HIN232, then the HIN232's RS232 output to the serial port's pin 2 (RECEIVE pin). is that all ?? what about the other pins on the serial port???

2. how do i use hyper terminal to test if my PIC is connected to the pc?? if connected, how do i make hyper terminal to be 'ALWAYS WAITING' for data from the PIC (ie. no time out)??

thanks a million
 
OK, U R right on the money with your connections; TX goes to TTL in & RX to TTL out.
The corresponding RS232 output goes to pin 2 on the DB9 connecting to the PC & RS232 Input to pin3.

You also have to connect the signal GND wire (pin5) on the DB9 to GND pin on the HIN232CP (pin 15). Don't worry about the handshaking lines. As long as you don't send large amounts of data at high baud rates you should be OK.

Also try to select a baud rate that yield the lowest error preferably less than 1%. Some peripherals and computer ports are a bit sensitve. Consult your data sheets; there should be baud rate tables for different OSC frequencies under "USART" section.

If you sometimes get jibberish or part of your string are missing on HT, use a 4ms time delay like for an LCD.

To test with Hyper Terminal, just create a new session. In properties under the "Phone number" tab select the com port you want to use. Click "configure" & choose the same baud rate you selected for the PIC. Data bits = 8 Stop bit = 1 no parity no flow control. Under the settings tab select "Ansi" emulation. Make sure under "ASCII setup" that "force incoming data to 7 bit ASCII" is unchecked.
Click "OK" everywhere you need to, to get back to the terminal window.

Any incoming data from your PIC will now be displayed as it is sent. Anything you type will be sent to the PIC.

If you are using assembler, I can help you with your code; haven't tried C yet :oops:

Hope it helps
 
Assembly code for Serial Port communication with PC

This looks like an old thread, but I will try anyways. I have just gotten into programming the 16f627 and would like to set up a way to communicate with the processor over the serial line. I would very much appreciate an code examples that can guide me.

Thanks
John
 
John_Mac said:
This looks like an old thread, but I will try anyways. I have just gotten into programming the 16f627 and would like to set up a way to communicate with the processor over the serial line. I would very much appreciate an code examples that can guide me.

Thanks
John

So why post in a thread over four years old?, why not just read the 'sticky' at the top of this forum?. My tutorials do what you need - as mentioned in the sticky!.
 
OK, U R right on the money with your connections; TX goes to TTL in & RX to TTL out.
The corresponding RS232 output goes to pin 2 on the DB9 connecting to the PC & RS232 Input to pin3.

You also have to connect the signal GND wire (pin5) on the DB9 to GND pin on the HIN232CP (pin 15). Don't worry about the handshaking lines. As long as you don't send large amounts of data at high baud rates you should be OK.

Also try to select a baud rate that yield the lowest error preferably less than 1%. Some peripherals and computer ports are a bit sensitve. Consult your data sheets; there should be baud rate tables for different OSC frequencies under "USART" section.

If you sometimes get jibberish or part of your string are missing on HT, use a 4ms time delay like for an LCD.

To test with Hyper Terminal, just create a new session. In properties under the "Phone number" tab select the com port you want to use. Click "configure" & choose the same baud rate you selected for the PIC. Data bits = 8 Stop bit = 1 no parity no flow control. Under the settings tab select "Ansi" emulation. Make sure under "ASCII setup" that "force incoming data to 7 bit ASCII" is unchecked.
Click "OK" everywhere you need to, to get back to the terminal window.

Any incoming data from your PIC will now be displayed as it is sent. Anything you type will be sent to the PIC.

If you are using assembler, I can help you with your code; haven't tried C yet :oops:

Hope it helps
Hi Stef! can you please explain & help me a 16F627 circuit with a 232 chip (HIN232CP) connected to the onboard USART. how do i configure the 4Mhz to produce an async mode 9600 baud. and how to communicate with the 16F627 & PC i.e displaying help on the help on the LCD(send from the computer key board to the LCD connected to the PIC)

your immediate response will enable me to effectively understand how to us RS232 and hyper link.

nkwanyana
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top