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

two rs232 port problem

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







two rs232 port problem
PostPosted: Fri Aug 05, 2005 11:30 pm     Reply with quote

connections are one rs232 from the pic->device the other goes pic->max chip-> computer

here is the code, i'm trying to use the pic as a msg forwarder (i know i could connect the computer directly to the device, but i dont want to). so what i type in hyperterminal is sent to the pic then sent to the device and what is sent from the device is sent pic and forwarded to the computer.

Code:


#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B5)

void print_to_a(char * text)
   {
   printf("%s\n\r",text);
   }
void put_to_a( char c ) {
   putc(c);
}

char get_from_a( ) {
   return(getc());
}

boolean kbhit_from_a() {return kbhit();}


#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)



functions

Code:



int duel_rs232_terminal(void)
   {
   while(1)
   {
   if (kbhit()) put_to_a(getc());
   if (kbhit_from_a()) printf("%c",get_from_a( ));
   }
   
   }



any help would be great.
thanks,
Nick
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 05, 2005 11:51 pm     Reply with quote

Tip #1: Use streams.

Streams have been around for a long time. From the versions page:
Quote:
3.069 RS232 functions now allow stream IDs.
Nick
Guest







PostPosted: Sat Aug 06, 2005 12:12 am     Reply with quote

i'm using this code to test the communication between the pic and device. so its more of an experiement than to test those communication lines. so if you see a problem with the code please let me know.

Thanks,
Nick
Ttelmah
Guest







PostPosted: Sat Aug 06, 2005 2:24 am     Reply with quote

The reply given is right. Use streams, they are simpler to code, and less likely to cause problems.
You do not post enough of the code you are trying to use, to actually show what the problem is, but normally when using 'embedded' user RS232 statements, you have to ensure that the _program_ flow encounters the one required. As written, you have put the use statements outside the program flow. You also do not need to repeat the delay statement.

Best Wishes
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE:
PostPosted: Sat Aug 06, 2005 3:33 am     Reply with quote

Hi,

Make sure you specify HS as crystal type instead of XT...

I sometimes noticed that XT worked with some crystals , but with most other crystalzs it did not.

arunb
Nick
Guest







PostPosted: Sun Aug 07, 2005 9:01 pm     Reply with quote

the problem was with hardware, that code above works.

Nick
Nick
Guest







PostPosted: Sun Aug 07, 2005 9:01 pm     Reply with quote

the problem was with hardware, that code above works.

Nick
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