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

kbhit problem

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



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

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

kbhit problem
PostPosted: Fri Sep 23, 2005 4:46 am     Reply with quote

Hello,

when I use kbhit() in my code after a printf() statement. I seem always to get TRUE as a result from kbhit(), even when I can't receive anything. Is that true, or is my code bugged? (I wrote it 4 times in different ways, but always get the same results....)

Can someone help me?

Code:
#device PIC16F877A *=16 ADC=10
#include <drivers/16f877.h>
#FUSES NOWDT       //No Watch Dog Timer
#FUSES HS       //High speed Osc (> 4mhz)
#FUSES NOPROTECT    //Code not protected from reading
#FUSES NOLVP       //Low Voltage Programming on B3
#FUSES NOCPD       //No EE protection
#FUSES NOWRT       //Program memory not write protected
#use delay(clock=20000000)
#use rs232(baud=9600, parity=n, bits=8, xmit=PIN_C6, rcv=PIN_C7, errors, stream=UWEAVE)

short checknetwork(int try)
// Input  : void
// Output : short - connected to network(1) or not connected(0)
// Action : connects to network
{
   short result, connected;
   int i;
   char data[80];

   i = 0;
   result = FALSE;
   connected = FALSE;
   
   lcd_gotoxy(1,1);
   printf(lcd_putc, "\fConnecting...");
   lcd_gotoxy(1,2);
   printf(lcd_putc, "try: %u", try);

   puts("ATE?");
   
   for(i = 0; ((i <= 79) && (!result)); i++)
   {
      while(!kbhit()) delay_us(10);
      data[i]=getc();
      if (i > 1)
         if ((data[i - 1] == 'O') && (data[i] == 'K'))
         {
            result = TRUE;
            connected = TRUE;
         }
      if (i > 4)
         if ((data[i - 4] == 'E') && (data[i - 3] == 'R') && (data[i - 2] == 'R') && (data[i - 1] == 'O') && (data[i] == 'R'))
            result = TRUE;
   }
   
   lcd_gotoxy(1,1);
   printf(lcd_putc, "\fdata: ", data);
   
   delay_ms(2000);
   
   return connected;
}

void main()
{
   lcd_init();

   //establish connection
   while(!checknetwork(i++));
   while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 23, 2005 11:42 am     Reply with quote

My suggestion is, get rid of all the parsing code and write a small test
program. i.e., no more than 6 lines of code inside main().
If you can demonstrate the error, then post that program and also
post the version of your compiler.
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

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

PostPosted: Mon Sep 26, 2005 2:49 am     Reply with quote

I now have it working using an interrupt.

Thanks for the advice to make a small test program first. I think I just wanted to much in once...
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