PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
KeyPad.h
Go to the documentation of this file.
1
8
9#ifndef KEYPAD_H_
10#define KEYPAD_H_
11
12#include "../Pins/Pins.h"
13#include "Core/Keys.h"
14
23inline Keys_t KeyPad_GetKeys()
24{
25 DDRC = 0xF0; // taking row pins as output and column pins as input
26 PORTC = 0x0F; // powering the row pins
27
28 uint8_t keypressed = 0; // integer for storing matrix value
29 Keys_t keys = KEYNONE;
30
31 if (PINC != 0b00001111) // if any of column pins goes high execute the loop
32 {
33 keypressed = PINC; // taking the column value into integer
34 PORTC ^= 0b11111111; // powering column pins of keypad
35 DDRC ^= 0b11111111; // making rows as inputs and columns as outputs
36 for(int i=0; i<8; i++) { asm volatile("nop"); } // wait until PORTC has new value
37 keypressed |= PINC; // taking row value and ORing it to column value
38
39 // Always returns only one key. Multiple keys not supported with this structure.
40 switch(keypressed)
41 {
42 case 0b11101110: keys = KEY7; break; // row 1 column 1
43 case 0b11101101: keys = KEY8; break; // row 1 column 2
44 case 0b11101011: keys = KEY9; break; // row 1 column 3
45 case 0b11100111: keys = KEYKILO; break; // row 1 column 4
46 case 0b11011110: keys = KEY4; break; // row 2 column 1
47 case 0b11011101: keys = KEY5; break; // row 2 column 2
48 case 0b11011011: keys = KEY6; break; // row 2 column 3
49 case 0b11010111: keys = KEYMILLI; break; // row 2 column 4
50 case 0b10111110: keys = KEY1; break; // row 3 column 1
51 case 0b10111101: keys = KEY2; break; // row 3 column 2
52 case 0b10111011: keys = KEY3; break; // row 3 column 3
53 case 0b10110111: keys = KEYMINUS; break; // row 3 column 4
54 case 0b01111110: keys = KEYLEFT; break; // row 4 column 1
55 case 0b01111101: keys = KEY0; break; // row 4 column 2
56 case 0b01111011: keys = KEYRIGHT; break; // row 4 column 3
57 case 0b01110111: keys = KEYX1; break; // row 4 column 4
58 default: break;
59 }
60
61 DDRC ^= 0b11111111; // making rows as outputs and columns as inputs
62 PORTC ^= 0b11111111; // powering row pins of keypad
63 }
64 return keys;
65}
66
67#endif /* KEYPAD_H_ */
Keys_t KeyPad_GetKeys()
Check which key of the KeyPad is pressed.
Definition KeyPad.h:23
Containing defines and functions for basic pin initialization and handling.