| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Foppie 
 
 
 Joined: 16 Sep 2005
 Posts: 138
 Location: The Netherlands
 
 
			          
 
 | 
			
				| kbhit problem |  
				|  Posted: Fri Sep 23, 2005 4:46 am |   |  
				| 
 |  
				| 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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Sep 23, 2005 11:42 am |   |  
				| 
 |  
				| 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
 
 
			          
 
 | 
			
				|  |  
				|  Posted: Mon Sep 26, 2005 2:49 am |   |  
				| 
 |  
				| 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...
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |