CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F452 and RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iKevin



Joined: 27 Mar 2008
Posts: 9

View user's profile Send private message

PIC18F452 and RS232
PostPosted: Sun Mar 30, 2008 4:17 am     Reply with quote

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 Razz
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Mar 30, 2008 8:50 am     Reply with quote

Sure you need a level translator between PC and the PIC. MAX232 or similar is suitable.
M.
iKevin



Joined: 27 Mar 2008
Posts: 9

View user's profile Send private message

PostPosted: Sun Mar 30, 2008 9:07 pm     Reply with quote

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







PostPosted: Mon Mar 31, 2008 7:23 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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