![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 | |
| |
| | #2 |
|
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. | |
| |
| | #3 |
|
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? | |
| |
| | #4 |
|
The serial keypad handles debounce and even repeats keys etc, same for the c code in the second link. Mike. | |
| |
| | #5 |
|
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? | |
| |
| | #6 |
|
Just read the links. Then explain what you dont understand. Mike. | |
| |
| | #7 |
|
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? | |
| |
| | #8 |
|
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]);
}
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. | |
| |
| | #9 |
|
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? | |
| |
|
| 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 |