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

Need help with RS232

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



Joined: 03 May 2004
Posts: 8

View user's profile Send private message

Need help with RS232
PostPosted: Tue Jun 01, 2004 12:01 pm     Reply with quote

Hi,

I am trying to connect PIC using RS232 to a PC (using HyperTerminal to read from the PIC (18F452)).

The problem is that no matter how I set the parity and data bits with #use RS232 and no matter how I set the HyperTerminal I keep getting wrong characters in HT window. I am reading characters from the keypad and sending them to both the LCD and HyperTerminal to make sure they are the right ones. I have RxD, TxD, GND lines from PC connected to my PIC. I am only attempting transfer from the PIC for now.

Here is the code:

Code:

#include <18F452.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,WDT128,RC_IO, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN, NODEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB

#use rs232(baud=9600, XMIT=PIN_A0, RCV=PIN_A1, PARITY=N, BITS=8)

.
.
.

while(true)
   {
    k = Key_Read() ;

    if(k=='*') LCD_Clear(1);
    else if (k=='#') LCD_Clear(2);
    else
    {
     LCD_Write(k);    // send character to LCD
     putc(k);         // send character to PC
    }
   }



Characters appear fine on the LCD but in HT I am getting wrong chars. For example instead of '7' i am getting an arrow down, for '8' it erases the line etc.

Thanks,
Vlad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 12:30 pm     Reply with quote

Quote:
I have RxD, TxD, GND lines from PC connected to my PIC.

You're not using a MAX232 chip, and you're using a soft USART.
Then you need to use the INVERT option in your #use rs232
statement. You should also use a series resistor on the RS232
Rx pin on your PIC. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=19062
Vlad



Joined: 03 May 2004
Posts: 8

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 2:30 pm     Reply with quote

Thank you!

It worked. No MAX232, so I needed that INVERT.

Thanks again,
Vlad
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