Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 14th October 2009, 06:02 AM   #1
Default PIC18 and keypad

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

www.farnell.com/datasheets/88904.pdf
yohanevindra is offline  
Old 14th October 2009, 06:55 AM   #2
Default

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.
Pommie is online now  
Old 14th October 2009, 09:07 AM   #3
Default

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?
yohanevindra is offline  
Old 14th October 2009, 09:21 AM   #4
Default

The serial keypad handles debounce and even repeats keys etc, same for the c code in the second link.

Mike.
Pommie is online now  
Old 14th October 2009, 09:37 AM   #5
Default

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?
yohanevindra is offline  
Old 14th October 2009, 01:21 PM   #6
Default

Just read the links. Then explain what you dont understand.

Mike.
Pommie is online now  
Old 14th October 2009, 08:26 PM   #7
Default

the C code you hav is only for 4 keys right?or is it for a keypad?

also, do you know how to implement a keypad encoder?
yohanevindra is offline  
Old 15th October 2009, 04:27 AM   #8
Default

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 by Pommie; 15th October 2009 at 04:36 AM.
Pommie is online now  
Old 15th October 2009, 11:47 AM   #9
Default

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?
yohanevindra is offline  
Reply

Tags
keypad, pic18

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Pic18 in C and Parallax GPS zBusterCB87 Robotics Chat 1 13th October 2009 04:48 PM
about PIC18 assembly code fengshao Micro Controllers 13 8th May 2009 01:58 PM
Wireless controller using PIC18 tuanvoi Micro Controllers 8 24th April 2009 12:18 AM
PIC18 Grounding col_implant Micro Controllers 3 26th February 2008 04:59 PM
Battery consumption of Pic18 janetsmith2000@yahoo.com Micro Controllers 1 11th February 2004 12:33 AM



All times are GMT. The time now is 03:33 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker