|
|
View previous topic :: View next topic |
Author |
Message |
Dude Guest
|
KBHIT PROBLEM |
Posted: Tue Apr 04, 2006 8:47 am |
|
|
I have this code for my RS-232 receiver. My transmitter program sends
( A,10| ) with no braket but when I use kbhit I receive only ( A, ). If I remove ( if kbhit()==1 ) I receive ( A,10| ). Can anyone help finding out why there is only ( A, ) in the buffer when I use kbhit?
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
if(kbhit()==1)
{
for(i=0;Lecture[i-1]!='|';i++)
{
Lecture = getc();
}
Lecture[i]='\0';
lcd_gotoxy(21,1);
printf(LCD_PUTC,"%s",Lecture);
}
Thanks. |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Wed Apr 05, 2006 7:47 am |
|
|
The kbhit() function returns the following ...
Quote: | 0 (or FALSE) if getc() will need to wait for a character to come in,
1 (or TRUE) if a character is ready for getc() |
Note that it states *a* character, not *some* characters.
Therefore, you will need to perform a kbhit() check for each incoming character. |
|
|
Ttelmah Guest
|
|
Posted: Wed Apr 05, 2006 8:33 am |
|
|
Though true, that is not the problem. Once he is 'inside' the fetch loop, he stays there till the required character is detected for the end of string, and getc, will wait for each character in turn.
As I have posted to another thread, the problem is probably that the test fails on the first 'for' loop, when testing Lecture[0-1], which is outside the array, and could return anything. The addition of kbhit, probably results in some of the RAM containing different values, and 'shows up' this logic fault.
Best Wishes |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Wed Apr 05, 2006 8:36 am |
|
|
Code: | for(i=0;Lecture[i-1]!='|';i++) |
Nice one ... can't believe I didn't spot it !! |
|
|
|
|
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
|