|
|
View previous topic :: View next topic |
Author |
Message |
Kofi Guest
|
kbhit() does not work ;-( |
Posted: Thu Nov 16, 2006 4:30 am |
|
|
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
|
|
Posted: Thu Nov 16, 2006 4:48 am |
|
|
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
|
|
Posted: Thu Nov 16, 2006 7:09 am |
|
|
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
|
|
Posted: Thu Nov 16, 2006 8:59 am |
|
|
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
|
|
Posted: Thu Nov 16, 2006 9:14 am |
|
|
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
|
|
Posted: Thu Nov 16, 2006 10:39 am |
|
|
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 |
|
|
|
|
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
|