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

kbhit() does not work ;-(

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







kbhit() does not work ;-(
PostPosted: Thu Nov 16, 2006 4:30 am     Reply with quote

I use this code to get chars from uart buffer but the if condition is always true and cIn gets the value <0>.

It is only a test... but why is cIn not 'E' when there is no char in the input buffer ?

Code:

#INT_RDA
void RDA_isr(void)
{
   if(kbhit())
      cIn=getchar();
   else
      cIn = 'E';
}


please hlp...
Kofi
Kofi
Guest







PostPosted: Thu Nov 16, 2006 4:48 am     Reply with quote

I have forgotten to say...

I am usung hardware uart on a PIC16F876A
Code:

#use delay(clock=20000000)
#fuses NOWDT,HS, NOPUT, NOPROTECT, DEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=19200,parity=N,xmit=TX_PIN,rcv=RX_PIN,bits=8)
Ttelmah
Guest







PostPosted: Thu Nov 16, 2006 7:09 am     Reply with quote

Because INT_RDA, _will only be called_, when there _is_ a character waiting. That is the whole 'point' of the interrupt. The same code, sitting in your 'main', will work fine, since it is then being called all the time as youloop/wait etc..
'kbhit', does nothing inside the interrupt handler.

Best Wishes
Kofi
Guest







PostPosted: Thu Nov 16, 2006 8:59 am     Reply with quote

the problem was that everytime i sent data there was an edge on the RX pin i solved it with a 10K resistor to VCC.
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Nov 16, 2006 9:14 am     Reply with quote

Ttelmah wrote:
Because INT_RDA, _will only be called_, when there _is_ a character waiting.
...
'kbhit', does nothing inside the interrupt handler.


... but, if I read the ASM correctly, will always return true. Kbhit() just tests for RCIF, which should still be set when you enter INT_RDA.
Ttelmah
Guest







PostPosted: Thu Nov 16, 2006 10:39 am     Reply with quote

dbotkin wrote:
Ttelmah wrote:
Because INT_RDA, _will only be called_, when there _is_ a character waiting.
...
'kbhit', does nothing inside the interrupt handler.


... but, if I read the ASM correctly, will always return true. Kbhit() just tests for RCIF, which should still be set when you enter INT_RDA.

Exactly.

Best Wishes
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