View previous topic :: View next topic |
Author |
Message |
apple9 Guest
|
RS232 problem |
Posted: Sat Apr 29, 2006 10:48 pm |
|
|
Code: | #include <16F777.h>
#fuses INTRC_IO, NOWDT, NOPROTECT
#use delay (clock = 8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
void main()
{
setup_oscillator(OSC_8MHZ);
while(1)
{
output_high(PIN_A0);
delay_ms(1000);
output_low(PIN_A0);
delay_ms(1000);
printf("Hello");
}
}
|
The code is pretty simple but it doesn't work. I put an LED on pin A0 and it blinks but the rs232 does not work. I don't see anything on the screen. I am using max232 chip. I don't know what is the problem. Maybe it is because of the internal osc? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 29, 2006 11:43 pm |
|
|
It looks like it should work. What's your compiler version ?
Are you using a demo board or did you make your own board ? |
|
|
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Sun Apr 30, 2006 6:39 am |
|
|
Here are some things that could help.
1) Double check that your Tx and Rx lines are connected correctly from the PIC to the MAX232 and from the MAX232 to the PC.
2) Make sure you have the correct port selected in your PC program.
3) If you are using Hyperterminal on the PC to capture/display the RS232 data, dont. That program has caused me many hours of frustration. Try this free program called TeraTermPro. It works great.
http://hp.vector.co.jp/authors/VA002416/teraterm.html
. |
|
|
mmmm Guest
|
|
Posted: Sun Apr 30, 2006 10:37 am |
|
|
i'm using version 3.202
Is it possible that it does not work because i'm using internal osc? |
|
|
MMM2 Guest
|
|
Posted: Sun Apr 30, 2006 10:41 am |
|
|
btw, i'm using PIC16F777. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 30, 2006 2:15 pm |
|
|
I tested your program with PCM vs. 3.202. It runs OK in the MPLAB
simulator, using UART1 for output. So that means the code is able
to fetch characters ("Hello") from a ROM table and put them in the
UART's Tx register. I looked at the .LST file and the UART setup
and transmit code looks OK. The setup code does incorrectly turn on
the A/D converter. CCS has a convention of putting in setup code
to disable it at start-up. But that bug doesn't affect UART operation.
If the OSCTUNE register was written to by code, it could change the
frequency of the internal oscillator, perhaps enough to cause errors
with the RS232. But I don't see anything in the .LST file that writes
to the OSCTUNE register.
So I think it's most likely that you have a hardware problem with
the connections to the MAX232 chip. The capacitors may not be
connected correctly, or the connections between the PIC and the
MAX232 may be incorrect, or between the PC and the MAX232. |
|
|
|