Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial port interface help

Not open for further replies.


Advanced Member level 1
May 5, 2004
Reaction score
Trophy points
Activity points
#elif defined(__PCH__)
#include <18F458.h>
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#byte port_b=6

void main() {


I get garbage output in hyperterminal. The baud rate was set to 9600, 8 bits, flow control non and no parity.

Is there anything wrong with my code? The c code above is for PIC C compiler/CCS C

garbage usually means a baud rate mismatch. Did you change the baudrate in hyperterm? I believe there is a bug that requires that you restart hyperterm to get the baudrate change to take effect.

If that's not it, try switching baud rates.

I don't know CCS but is that for bit banged serial I/O?

By the way, I don't see a PIC18F458 listed on the microchip site.


One more thing you should check is if the GND line is connected at you communication cable, i had this problem once and it solved the problem.


check the crystal oscillator of your controller,crystal oscillator of your controller should be equal to that seen by your compiler.

my connection is good and my baud rate on the MCU agrees with hyperterminal.

I'm using an 8Mhz crystal but I don't know the cap values. I just connect it to the mcu without the caps. could that change the speed?

yes, you will need caps. try 22 pf though anything bewteen 12 and 40 pf should work with some frequency error but probably not enough to screw up your baudrate. the crystal's datasheet should tell you what cpas to use. the crystal leads connect to osc1 and osc2 and then caps go from the osc1 to gnd and ocs2 to gnd.

you are using a an rs232 driver like a max232, right?

try putc instead of the printf... printf is always buggy in CCS C...

anyway... i would suggest tht u use the interrupt method n use a button so u dont hav to press MCLR (for ur code) when u wanna check the msg from ur PIC...

use putc wth interrupt then when button pressed, send the msg to ur pc...

another prob mayb is tht when after the MCLR u press for ur msg to display the msg on ur pc... the pic might not stable yet... is it posible?


I tried putc and it doesn't work. Anymore suggestion? I'm not using max232 but from what i've read it should work without problems.


I have not done serial programming with PIC but I have connected a few different 8051 and AVR's to PC using serial . This is my experience.

If you fail at 9600 try connecting at the lowest baud rate that both Hyperterminal and PIC can support this will take care of minor mis-match in baud rate etc. Since you can see garbage it means your connections are correct.

what circuit are you using to replace max232 ? Once due to the requirement of opto-isolated circuit I had to design without max232 but I made sure that the signal levels were near +12 and -12 though without any extra power supply.

try the example codes from the pic list they have a lot of working codes examples in that website

I added "INVERT" to the #use RS232 and it worked. NO more garbage. I had to remove rcv=PIN_C7 though or else it won't compile. Why??

edit: problem solved. I used max232 and everything worked out. I don't get why sometime u don't have to use it. I guess it depends on the pc.

may be u are facin the problem with <cr> or baudrate mismatch. try changing the baudrate. may be that will help u. else see to it that you get proper <cr> end of string. i have a vb base html which will help u.

Not open for further replies.

Part and Inventory Search

Welcome to