Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18 and keypad

Status
Not open for further replies.

yohanevindra

New Member
I have to do part of a project which consists of a PIC18F452, and interfacing it to a 12-key kaypad. we could either connect the keypad directly to the PIC which will take up more pins, and then also complicate the code, or either we could use a encoder (MM74C922N) when going through the datasheet for the encoder, there was a section detailing applications and there were 3 methods namely, "Synchronus handshake, synchronus data entry onto bus and asynchronus data entry onto bus. " which method do we use?I was tihnkin that i could use interrupts and when the interrupt is triggered then the input for the encoder is read..i could use polling, but then processor power and time is used for this.

the methods mentioned in the datasheet use circuits in addition to the encoder, like flip flops, AND gates, and inverters.

if we jus connect the encoder to the PIC and then use it is it sufficient?or do we hav to apply it like the data sheet specifies in the application section of the datasheet?

the link to the datasheet is

https://www.electro-tech-online.com/custompdfs/2009/10/88904.pdf
 

Pommie

Well-Known Member
Most Helpful Member
You could use my Serial Keypad or you could look at the code in this thread to see how to write a keypad handler in C. If you prefer asm then look at the code in the first link but it is rather unconventional.

Mike.
 

yohanevindra

New Member
thanks for that!

what about key debouncing and stuff like tht?how do I handle that?also, do i need to put some resistors in series with each key?to protect the keys or something?i remember some ppl saying somethin like that?
 

Pommie

Well-Known Member
Most Helpful Member
The serial keypad handles debounce and even repeats keys etc, same for the c code in the second link.

Mike.
 

yohanevindra

New Member
so we dont hav to implement any hardware?what about the resistors in series with each key?

also, the same basis of code will work regardless of whether i work with serial or a LCD right?
 

Pommie

Well-Known Member
Most Helpful Member
Sorry, forgot I changed that for just 4 keys. Here's the code for a 12 key keypad.
Code:
char ReadKeyPad(){
char i;
rom char KeyPad[16]="580247*169#3";
    previous=keys;
    wpub|=0x3c;
    keys=0;
    trisb|=0x3c;
    for(i=0;i<3;i++){
        keys<<=4;
        trisa|=7;
        trisa&=255-(1<<i);
        porta&=255-(1<<i);
        keys|=(portb>>2)&0x0f;
        trisa|=7;
    }
    keys^=0x0fff;
    trisb&=0xc3;
    if(keys==0)
        return(0);
    if(((keys^previous)&keys)==0){
        //repeating key
        if(--KeyCount!=0)
            return(0);
        KeyCount=KeyRepeat;
    }else{
        //must be new key
        KeyCount=KeyDelay;
        edges=((keys^previous)&keys);
    }
    i=0;
    while((edges&(1<<i))==0){
        i++;
    }
    return (KeyPad[i]);
}
The keypad has the rows connected to B2-B5 and columns to A0-A2. The routine should be called every 10mS for proper debounce etc. You may have to swap the order of keypad[] depending on how your rows and columns are connected.

Edit, the above is for BoostC, C18 will require the registers (portb etc.) to be upper case.

Mike.
 
Last edited:

yohanevindra

New Member
How would i go about implementing the MM74C922N encoder?

Would that be easier since I can use an interrupt to and also, it would give the eky direct to me?

does anyone have experience using a keypad encoder?
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top