Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Scanning of Keypad (4x4) using timer

Status
Not open for further replies.

ecaits

Member level 4
Joined
Jan 16, 2014
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
579
Hello Friends,

I have interface keypad (4x4) with PIC16F877 using Hi-tech C compiler.
Now I want to scan the keypad to know that is any key pressed or not???

How can I use timer to scan the keypad so that I did not need to scan the keypad every time in program code???

I think I can use timer to scan the keypad but I dont know how to use it..

Please suggest me.... Thank you in advance...

Nirav
 

Set up the timer to produce an interrupt at whatever rate you want each scan to run. In the ISR, set a flag to say "it's time to scan" then in the main program check for it. When the flag is set, reset it again then do your usual keypad scan routine.

I would not recommend you do the scan in the ISR itself as the process is slow, especially if you debounce the keys and it could delay the exit from the ISR long enough that other interrupts get missed.

Brian.
 

Hello!

Here is my implementation (in pseudo code). For a 4x4 pad, you need 4 outputs
and 4 inputs. You power the output and you check if any input is high. In my case,
I power the column and I check which line is high. Let's say that you use portA
lower bits in output and higher bits in input.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int8 column = 0;
int8 keyindex;
 
void main(void) {
    PAADIR = 0x0F;              //  Set the low its in output.
    ConfigTimer(20);            //  Configure the timer (ex. 20 ms).
    SleepAndWaitInterrupts();   //  That's it, the main program is over.
}
 
 
void TimerISR() {
    column++;                   //  Next column
    if(column == 4) column = 0; //  Back to 0 if more than 3
    PAOUT = 1 << column;
}
 
void PortAISR {
    uint8 line = PAIN;          //  Get thevalue of theinterrupt into line
    // Now you can calculate a unique number between 0 and 15
    // which can be used to identify which key has been pressed.
    switch(line) {
    case 1:
        keyindex = column   
    case 2:
        keyindex = column + 4;
    case 4:
        keyindex = column + 8;
    case 8:
        keyindex = column + 12
    }
    ProcessKey();
}
 
void ProcessKey() {
    //  Do whatever you want with your key index.
}



That's it.

Dora
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top