View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
two rs232 port problem |
Posted: Fri Aug 05, 2005 11:30 pm |
|
|
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
|
|
Posted: Fri Aug 05, 2005 11:51 pm |
|
|
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
|
|
Posted: Sat Aug 06, 2005 12:12 am |
|
|
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
|
|
Posted: Sat Aug 06, 2005 2:24 am |
|
|
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
|
RE: |
Posted: Sat Aug 06, 2005 3:33 am |
|
|
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
|
|
Posted: Sun Aug 07, 2005 9:01 pm |
|
|
the problem was with hardware, that code above works.
Nick |
|
|
Nick Guest
|
|
Posted: Sun Aug 07, 2005 9:01 pm |
|
|
the problem was with hardware, that code above works.
Nick |
|
|
|