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 CCS Technical Support

getc() and kbhit()

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



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

getc() and kbhit()
PostPosted: Tue Sep 09, 2008 4:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 11:28 pm     Reply with quote

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);
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