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

3x4 Matrix mobile like keypad

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



Joined: 12 Apr 2017
Posts: 3

View user's profile Send private message

3x4 Matrix mobile like keypad
PostPosted: Wed Apr 12, 2017 4:28 pm     Reply with quote

Hi, I'm having some difficulties trying to develop a code to a mobile like keypad.

It should work like old mobile phones.
If you press the number 2 3x is should print the letter C.

I'm using the kbd_getc() function to get the inputs.

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 6:53 pm     Reply with quote

Quick code...

Once you press a key, you start a short timer.. if you don't press that key again within the 'timeout' period, you'll get the 'first' press key code( A) in your example.
If you press that key within the time period, you get the '2nd' press key code(B), and restart the timer. When the timer expires, you exit the routine.
If you press that key again, you get the '3rd' press key code ( C) and exit the routine.

As for the timer delay, I suggest you start at 100ms. For the 'key press' codes, it could be a series of 'case' statements..easy to implement or a 'matrix' array that mimics the keypad layout.

I'd have to find a 30 year old QB45 program for real code.....

Jay
springwheel



Joined: 12 Apr 2017
Posts: 3

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 8:17 pm     Reply with quote

temtronic wrote:
Quick code...

Once you press a key, you start a short timer.. if you don't press that key again within the 'timeout' period, you'll get the 'first' press key code( A) in your example.
If you press that key within the time period, you get the '2nd' press key code(B), and restart the timer. When the timer expires, you exit the routine.
If you press that key again, you get the '3rd' press key code ( C) and exit the routine.

As for the timer delay, I suggest you start at 100ms. For the 'key press' codes, it could be a series of 'case' statements..easy to implement or a 'matrix' array that mimics the keypad layout.

I'd have to find a 30 year old QB45 program for real code.....

Jay


Thanks for the heads up!
I was having some problems implementing it but I'm gonna try it again.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Apr 13, 2017 1:52 am     Reply with quote

I'd just fractionally modify the flow.

Normally the time is perhaps 0.5 to 1 second, and no key gets accepted till this expires. So it goes A B C A B C, until you stop. Then accepts the key.

Problem is that if you press once too often, as posted it'd accept the 'C' and start on the next character.
newguy



Joined: 24 Jun 2004
Posts: 1900

View user's profile Send private message

PostPosted: Thu Apr 13, 2017 6:10 am     Reply with quote

Ttelmah wrote:
I'd just fractionally modify the flow.

Normally the time is perhaps 0.5 to 1 second, and no key gets accepted till this expires. So it goes A B C A B C, until you stop. Then accepts the key.

Problem is that if you press once too often, as posted it'd accept the 'C' and start on the next character.


If you want it to be like a mobile phone, I'd suggest the flow be:

2 A B C 2 A B C
3 D E F 3 D E F
etc.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Apr 13, 2017 6:36 am     Reply with quote

Yes.
I was using a phone that has a separate numeric 'shift', but for the more common TV remote, or traditional phone, as Newguy says, it should include the numeric value as one step....
springwheel



Joined: 12 Apr 2017
Posts: 3

View user's profile Send private message

PostPosted: Thu Apr 13, 2017 3:25 pm     Reply with quote

I am having some hard time implementing the short timer.
How do I reset the timer ?
Could someone help me ?

I am trying to use a flag.

Code:
int8 i;
int1 flag;

#int_timer0
void timer0(){
   set_timer0(131-get_timer0());
   i++;
   if(i==250){
      disable_interrupts(GLOBAL | INT_TIMER0);
      i=0;
      flag=0;
   }else{
      flag=1;
   }
}

void main(){

   char c,aux;
   int8 contador=1;
   
   setup_counters(RTCC_INTERNAL, WDT_2304MS);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_32 );
   set_timer0(131);
   
   lcd_init();
   kbd_init();
   port_b_pullups(true);
   lcd_putc("\f");
   lcd_gotoxy(1,1);

   while(1){
      c = kbd_getc();
      if(c != 0){
         switch(c){
            case '1':
               if(!flag){
                  aux = c;
                  enable_interrupts(GLOBAL | INT_TIMER0);
               }
               if(flag){
                  aux = 'a';
               }
            break;
         }
         lcd_putc(aux);
      }
    }
}

Sorry for the noob question, I am new to this.
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