Jump to content
Sign in to follow this  

Problem With Pic 16f628 To Pc Rs232

Recommended Posts



I'm trying to hook up my 16F628 to my computer via RS232. I connected the TX to the RX of the pc, the RX to the TX and pin 5 the ground.

The PIC is sending something, but my pc isn't receiving it properly I think.


This is what I receive:




Port settings:




And my code:


#include <system.h>

#pragma CLOCK_FREQ 20000000

#include <system.h>

#define TX_PORT		 0x06
#define TX_TRIS		 0x86
#define TX_BIT		  2
#define RX_PORT		 0x06
#define RX_TRIS		 0x86
#define RX_BIT		  1
#define e_SPBRG		 0x99
#define e_RCREG		 0x1a
#define e_TXREG		 0x19
#define e_TXSTA		 0x98
#define e_RCSTA		 0x18
#define e_TXIF_PIR	  0x0c
#define e_RCIF_PIR	  0x0c
#define e_TXIF_BIT	  4
#define e_RCIF_BIT	  5
#define MODE			(USART_reset_wdt | USART_HW)


#define spBAUD  9600
#define FOSC 20000000L
#define fSPBCLK (FOSC)		/* UART Baud rate generator clock (high speed) */
//#define fSPBCLK (FOSC / 4)	/* UART Baud rate generator clock (low speed) */
#define SPBRG_VAL (fSPBCLK / (spBAUD * 16L)) - 1L

#define bit_time 129 

#include <rs232_driver.h>

void main()
// serial config
txsta = 00110000b;
rcsta = 10000000b;

// input serial
set_bit(trisb, 1);

// output serial
clear_bit(trisb, 2);




Is my USART setup wrong or do I need some extra hardware to connect my PIC to my PC?


Thanks in advance!

Share this post

Link to post
Share on other sites

Without looking a the code, I have one question about your hardware. Are you shifting your voltage levels as required by the RS-232 protocol?


The RS-232 protocol uses -12V as "high" and 12V as "low." (Can actually be anywhere between -15V to -3V and 3V to 15V).

UART uses 5V and 0V, respectively.


If you do not have anything shifting the voltage levels, you will not be sending 1's and 0's. You will be sending 0's and undefined's.


You need to put something like the MAX232 from Maxim-IC between the UART and the PC serial cable. I prefer the MAX233 since the required charge-pump capacitors are built in. Maxim-IC offers free samples of both of these chips.


- Bill

Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...