View previous topic :: View next topic |
Author |
Message |
boulder
Joined: 15 Mar 2008 Posts: 53
|
getc() and kbhit() |
Posted: Tue Sep 09, 2008 4:50 pm |
|
|
From my LST file, I realize that getc() includes the function of kbhit(), but why do many people like to use kbhit() before using getc() in their? Is this because their compiler is different from mine? I am using PCM.
Code: |
.................... while(!kbhit());
0033: BTFSS PIR1.RCIF
0034: GOTO 033
.................... data = getc();
0035: BTFSS PIR1.RCIF
0036: GOTO 035
0037: MOVF RCREG,W
0038: MOVWF data
|
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 09, 2008 5:07 pm |
|
|
It's difficult to search for that line with kbhit() in it, to see how many
times it's used that way. The only CCS files that use it in that way are:
Quote: | c:\program files\picc\examples\ex_tgetc.c
c:\program files\picc\examples\ex_tgetc2.c |
Those files do it because they want to wait for a key stroke, but they
don't want to get the character at that point. They want another routine
to get it. (ie., to remove the char from the UART). |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Sep 09, 2008 11:28 pm |
|
|
In the sequence
Code: | while (!kbhit());
xx = getc(); |
the first line is simply superfluous and can be omitted without changing the code's behaviour.
The said two examples are different in this regard. In ex_tgetc.c other conditions are evaluated, here the initial wait is probably meaningful.
In contrast, in ex_tgetc2.c, the initial wait doesn't serve a purpose and the example is misleading so far.
Code: | while(!kbhit());
do
{
value=getc();
if (value)
putc(value);
} while (RS232_ERRORS); |
|
|
|
|