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

Rs232

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







Rs232
PostPosted: Thu Jan 20, 2005 8:01 am     Reply with quote

Hi,

I try to make a connection pic PC to post the character on the PC but that does not work. Is what my code is false?

Thanks.


#include <18f452.h>
#fuses NOWDT, NOLVP, PUT, NODEBUG, HS
#use delay (clock=20000000)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7,PARITY=N,BITS=8,STREAM=COM_1)

void main()
{
char c;

fprintf(COM_1,"\rOK!\r\n");
fprintf(COM_1,"lire! ;-)\r\n");
while(1)
{
if(kbhit())
{
c=fgetc(COM_1);
fprintf(COM_1,"PIC a recu les charactere :'%c'\r\n",c);
fprintf(COM_1," ASCII code %d decimal ou 0x%02X hex\r\n",c,c);
}
}
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jan 20, 2005 8:38 am     Reply with quote

What does your code do wrong? Does it print anything? You may have a problem with kbhit not referring to the stream, try:

if(kbhit(COM_1))

Also tell us what compiler version number you have.

English grammar correction:
"Is what my code is false?" should probably be "Where is my code wrong?".
_________________
The search for better is endless. Instead simply find very good and get the job done.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 20, 2005 9:43 am     Reply with quote

In addition to SherpaDoug's question, what are you using for your RS232 to TTL level shifting?

Assuming a MAX232 type chip, is it wired correctly?
Are the voltages on its V+, V- pins correct?

If you aren't using a level shifting chip and just driving the PCs RS232 port then you need to add the INVERT statement to your #use RS232 command.

Another quick suggestion, use the "CODE" button when submitting code on the forum. It keeps your formating rather than left justifying all the lines which makes it a bit hard to read. Click "CODE" then copy your code into the text box and click "CODE" a second time. You should see something like
Code:
 and
bracketting your code.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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