View previous topic :: View next topic |
Author |
Message |
Tuga
Joined: 21 Aug 2007 Posts: 6
|
Time limit for rs232 |
Posted: Fri Aug 31, 2007 10:50 am |
|
|
Hello,
I'm using the pic18f4455 with module ethernet tibbo em202, but i'dont know when i loose the connection ethernet.
How i can detect if the connection rs232 is failed or interrupt receiving data if the time is so longer?
Thanks |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Sep 01, 2007 9:02 am |
|
|
V4 include new RS232 features that would be useful in this case, for example:
int mygetc(char *c, int n=500);
This function waits n milliseconds for a character over RS232 and return accordingly
TRUE or FALSE.
Humberto |
|
|
Guest
|
|
Posted: Tue Sep 04, 2007 11:53 am |
|
|
It's works. Thanks for your help. |
|
|
Tuga
Joined: 21 Aug 2007 Posts: 6
|
|
Posted: Tue Sep 04, 2007 12:52 pm |
|
|
lol
i use the version 4, and my compiler show this message: Undefined identifier mygetc
Code: | #use rs232(baud=38400, xmit=pin_d1, rcv=pin_d0)
void putnet( char c )
{
putc(c);
}
char getnet()
{
return(getc());
}
int getnett(char c, int time)
{
int valor=0;
valor=mygetc(&c, 200);
return valor;
} |
it's necessary use other library?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 04, 2007 1:09 pm |
|
|
Here is a demo program for the new getc() timeout feature in Vs. 4 of
the compiler. The timeout is specified in the #use rs232 statement
as shown below. In this example it's set for 5000 ms (5 seconds).
Here is the output of the program. If you press a key in your terminal
window within 5 seconds, the program will get the key and display it.
If it doesn't get a keypress within 5 seconds it will display "Timed out".
Quote: |
Timed out
Timed out
Received: a
Received: a
Received: a
Received: a
Timed out
|
Code: |
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, TIMEOUT=5000)
//====================================
void main()
{
char c;
while(1)
{
c = getc();
if(c == 0)
printf("Timed out \n\r");
else
printf("Received: %c \n\r", c);
}
} |
This was tested with PCM vs. 4.053 on a PicDem2-Plus board. |
|
|
Tuga
Joined: 21 Aug 2007 Posts: 6
|
|
Posted: Tue Sep 04, 2007 2:23 pm |
|
|
Thanks, it's work now, but i need change the pins for time limit work's:
d1->c6 and d0->c7, |
|
|
|