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

Question for k=kbd_getc()

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



Joined: 14 Feb 2007
Posts: 46
Location: Greece & Cyprus

View user's profile Send private message

Question for k=kbd_getc()
PostPosted: Tue Sep 04, 2007 7:40 pm     Reply with quote

Hi
can someone tell me what is wrong in this code ? i tried to figure out for
many hours but i didn't.
The program isuck inside the
Code:

       while(k==0){
                      .....     
                          }

 

and never come out from!!
As i can see the k=kbd_getc() never return a 0 value!!!
Code:

#include <16F777.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock = 4000000)
#byte PORTC=0X07
#include "flexy_keypad_4x4.c"
#include "flex_lcd.c"



void main()
{
   char k;

   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");

   while (TRUE)
  {
      k=kbd_getc();
          if(k!=0){
           if(k=='*')
                     {
                lcd_putc('\f');
                     }
               else
                     {
                 lcd_putc(k);
                delay_ms(3000);
                     }
                  }
             while(k==0)   {                       // <---- the program stuck here and never go out
                                                        //    i belive this  expression is wrong
                         lcd_gotoxy(1,1);
                         lcd_putc("\f Please Push a button..")
                         delay_ms(300);
                         k=kbd_getc();                               
                            }
               
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 04, 2007 10:58 pm     Reply with quote

1. Do you have pull-up resistors on the Row pins for the keypad ?
You need them.

2. Are you trying to combine the LCD and keypad on the same pins ?
I don't think you can do that with these drivers.
Guest








PostPosted: Wed Sep 05, 2007 5:34 am     Reply with quote

No they are not in the same pin.
the driver are ok,when i tryed them with the ex_KBD.C EXAMPLE from ccs they work ok with this driver, shows you the key you have press on LCD.so I DONT THINK IS THE DRIVER.

When there is no button pressed on the keypad the k=kbp_putc() returns you a 0 or Null????
how can i write it a while statement so when there is no button pressed on the keypad the programm will get inside the while statement until a button will be pressed again!!!!!!
Guest








PostPosted: Wed Sep 05, 2007 5:54 am     Reply with quote

PCM programmer wrote:
1. Do you have pull-up resistors on the Row pins for the keypad ?
You need them.

2. Are you trying to combine the LCD and keypad on the same pins ?
I don't think you can do that with these drivers.


Hi again.
well I'm using the driver on PORTB with internal pull up resistor.
and the lcd on a different port, PORTD. I have used the two driver i find in this forum just modified the #DEFINE PIN_XX. Why work with examples from ccs. They don't work with my code and i don't now why???

any help it will be appreciated !!!!!!!
THANKS
spgiuliano



Joined: 01 Apr 2016
Posts: 1

View user's profile Send private message

kbd_getc()
PostPosted: Fri Apr 01, 2016 12:51 pm     Reply with quote

I've exactly the same problem. I've the keypad in portA and is working fine, but when enter a while loop kbd_getc() is not getting the keys that I'm pressing. I've checked the code a LOT of times, also with a friend but we can't find what isn't working. Also i debug the subroutine showing on the LCD each line and the problem is that after key=kbd_getc(); KEY is not changing.
If someone can help us....
Thanks!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 1:10 pm     Reply with quote

spgiuliano wrote:

I've the keypad in portA and is working fine, but when enter a while loop
kbd_getc() is not getting the keys that I'm pressing.

This post shows how to do it:
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4

Normally, the kbd_getc() must be called continuously in a loop to poll the
keypad. When you get a non-zero value back, that's the key that was
pressed. But I assume you're not doing this polling when you "enter a
while loop". That's why you miss keys. One solution to this problem
is to do the polling in a timer interrupt routine.

The sample code in the link above calls kbd_getc() in a Timer0 interrupt.
The setup parameters for Timer0 are chosen so it will interrupt once every
10 ms. So kbd_getc() is called every 10 ms, automatically, in the
background. Any keys that are pressed are read, and put into a circular
buffer that can hold up to 32 keys.

Then when you "enter a while loop" in your code, the program will not
lose any keys. They will be put into the key buffer.

If you want to check if any keys have been pressed, check the bkbhit
variable. If it's true, you have a least one key available in the buffer.
Then call bgetc() to get the key from the buffer. The code in the while(1)
loop at the end of the program shows how to do this. See the link above.
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