|
|
View previous topic :: View next topic |
Author |
Message |
iKevin
Joined: 27 Mar 2008 Posts: 9
|
PIC18F452 and RS232 |
Posted: Sun Mar 30, 2008 4:17 am |
|
|
This is the code that I have:
Code: | #include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4mhz)
#use rs232(baud=9600, bits=8, parity=N, stop=1, ERRORS, xmit=PIN_C6, rcv=PIN_C7)
void main(void) {
char c;
while(1)
{
c = getc();
putc(c);
}
} |
On the hyperterminal, I select 9600, 8bits, odd parity and 1 stop bit.
I connect the following pins:
Code: |
PC's D-Sub 9 PIC18F452
pin 2 RX <------------ pin 25 RC6/TX
pin 3 TX ------------> pin 26 RC7/RX
GND -------------- GND
|
It doesn't work so I wonder if I need the IC MAX232 in between PC and PIC18F to convert voltage levels because I thought PIC18F converted them automatically |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sun Mar 30, 2008 8:50 am |
|
|
Sure you need a level translator between PC and the PIC. MAX232 or similar is suitable.
M. |
|
|
iKevin
Joined: 27 Mar 2008 Posts: 9
|
|
Posted: Sun Mar 30, 2008 9:07 pm |
|
|
Thanks meereck. It kinda works now but I still have one problem:
Code: | #include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4mhz)
#use rs232(baud=9600, bits=8, parity=N, stop=1, xmit=PIN_C6, rcv=PIN_C7)
void output(void);
void main(void) {
output();
}
void output(void) {
delay_ms(1000);
printf("Line1\r");
delay_ms(1000);
printf("Line 2\r");
delay_ms(1000);
printf("The end!\r");
} |
At the computer I receive:
Code: | Line1
Line1
Line1
Line1
Line1
Line1
Line <0>
Xhe end |
How come "Line1" is printed 4 times and there are so many errors on the transmission?
Here is another result:
Code: |
Line11Line 2
Lin¨1
Line1
Line1
Line 2
Line1
Line 2
Line1
Line 2
Line1
Line 2
The end
|
I only want to transmit once for each line with a delay of 1 sec each transmission. |
|
|
Ttelmah Guest
|
|
Posted: Mon Mar 31, 2008 7:23 am |
|
|
What have you got in the way of supply smoothing at the PIC?.
It actually looks as if the chip must be resetting multiple times when the data is sent. You are losing the last couple of characters in the program as posted, since the code will drop 'off the end', and go to sleep, before these have been sent.
Restarting like this, suggests:
1) Supply rail not adequately smoothed at the PIC.
2) MCLR connection not properly pulled up.
The garbage 'in line', could be from the same cause, or an oscillator problem.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|