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 support@ccsinfo.com

problem with kbhit()

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



Joined: 04 Jun 2007
Posts: 27

View user's profile Send private message

problem with kbhit()
PostPosted: Wed Jun 13, 2007 5:38 am     Reply with quote

I have the problem that if I jump into a function - for example functionA() I want to check for another character and this only gets recognized if Im done with this functionA(). Of Course I can use another kbhit() inside the functionA() but inside a are much more other functions which for example drive a stepper motor and if i use kbhit() everywhere inside its very confusing. Sad
Is there a better way to solf this?

Code:

while(true)
{

if (kbhit()) getc(var)
else
{
if (var=='A') {functionA()}
if (var=='B') {functionB()}
if (var=='C') {functionC()}
}

}
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Wed Jun 13, 2007 6:19 am     Reply with quote

This is what interrupts are for.
You fill a buffer with incoming data in an interrupt service routine, and check the buffer's contents in the main code.
There are plenty of examples (here and elsewhere) how to do it.
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