/* (C) 2005 by Richard West (rw88@cornell.edu) * Published: 25 Feb 2005 * Updated: 30 Jan 2006 * Published under GNU General Public License - http://www.linux.org/info/gnu.html * * Keypad Function Definition File * (see keypad.h for documentation) * * Hardware setup notes: * Keypad connected to Portx.0-7 (see note 2 in header) */ #ifndef _KEYPAD_C_ #define _KEYPAD_C_ #ifdef KEYPAD_USEDISPLAY #ifdef DISPLAY_USEPORTA #asm(".equ __lcd_port=0x1B") #elif defined DISPLAY_USEPORTB #asm(".equ __lcd_port=0x18") #elif defined DISPLAY_USEPORTC #asm(".equ __lcd_port=0x15") #elif defined DISPLAY_USEPORTD #asm(".equ __lcd_port=0x12") #else #error Keypad library - Please specify which port to use for the display. #endif #include // lcd library #include // for sprintf() #endif // keypad states #define KEY_RELEASE 0x00 #define KEY_DEBOUNCE_DOWN 0x01 #define KEY_PRESSED 0x02 #define KEY_DEBOUNCE_UP 0x03 #define KEY_DONE 0x04 // "private" keypad runtime global variables unsigned char keymode; unsigned char keycount; unsigned char keymaybe; unsigned char keyterminate; // only compile if using display #ifdef KEYPAD_USEDISPLAY unsigned char keydisplay; unsigned char keyposx; unsigned char keyposy; unsigned char keylcd_buffer[2]; #endif // only compile if using keypad keyboard #ifdef KEYPAD_KEYBOARD unsigned char keycapslock; unsigned char keytableoffset; #endif // if using a telephone style keypad #ifdef KEYPAD_TELPAD #define KEY_TABLE_LENGTH 16 unsigned char keysymbol_table[16] = {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'}; flash unsigned char keycode_table[16] = {0xEE, 0xDE, 0xBE, 0x7E, 0xED, 0xDD, 0xBD, 0x7D, 0xEB, 0xDB, 0xBB, 0x7B, 0xE7, 0xD7, 0xB7, 0x77}; // if using a hexadecimal style keypad #elif defined KEYPAD_HEXPAD #define KEY_TABLE_LENGTH 16 unsigned char keysymbol_table[16] = {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '0', 'F', 'E', 'D'}; flash unsigned char keycode_table[16] = {0xEE, 0xED, 0xEB, 0xE7, 0xDE, 0xDD, 0xDB, 0xD7, 0xBE, 0xBD, 0xBB, 0xB7, 0x7E, 0x7D, 0x7B, 0x77}; // if wanting to use a telephone style keypad as a keyboard #elif defined KEYPAD_KEYBOARD #define KEY_TABLE_LENGTH 80 /* 0xFF symbol represent ignored button or button combination 0xFE symbol represents shift A 0xFD symbol represents shift B 0xFC symbol represents shift C 0xFB symbol represents shift D 0xFA symbol represents the caps-lock toggle 0xF9 symbol represents the delete key 0xF8 symbol represents the clear key 0x27 symbol represents single quote (escape char has problems with CodevisionAVR) */ unsigned char keysymbol_table[80] = {'1', '2', '3', 0xFE, // none pushed '4', '5', '6', 0xFD, '7', '8', '9', 0xFC, '*', '0', '\0', 0xFB, '!', 'a', 'd', 0xFF, // A pushed 'g', 'j', 'm', 0xFA, 'p', 't', 'w', 0xF9, '.', ' ', ',', 0xF8, '?', 'b', 'e', 0xFA, // B pushed 'h', 'k', 'n', 0xFF, 'q', 'u', 'x', 0xFF, '+', '(', ';', 0xFF, 0x27, 'c', 'f', 0xF9, // C pushed 'i', 'l', 'o', 0xFF, 'r', 'v', 'y', 0xFF, '-', ')', ':', 0xFF, '"', '@', '#', 0xF8, // D pushed '$', '%', '^', 0xFF, 's', '&', 'z', 0xFF, '/', '<', '>', 0xFF}; flash unsigned char keycode_table[80] = {0xEE, 0xDE, 0xBE, 0x7E, // none pushed 0xED, 0xDD, 0xBD, 0x7D, 0xEB, 0xDB, 0xBB, 0x7B, 0xE7, 0xD7, 0xB7, 0x77, 0x6E, 0x5E, 0x3E, 0x7E, // A pushed 0x6C, 0x5C, 0x3C, 0x7C, 0x6A, 0x5A, 0x3A, 0x7A, 0x66, 0x56, 0x36, 0x76, 0x6C, 0x5C, 0x3C, 0x7C, // B pushed 0x6D, 0x5D, 0x3D, 0x7D, 0x69, 0x59, 0x39, 0x79, 0x65, 0x55, 0x35, 0x75, 0x6A, 0x5A, 0x3A, 0x7A, // C pushed 0x69, 0x59, 0x39, 0x79, 0x6B, 0x5B, 0x3B, 0x7B, 0x63, 0x53, 0x33, 0x73, 0x66, 0x56, 0x36, 0x76, // D pushed 0x65, 0x55, 0x35, 0x75, 0x63, 0x53, 0x33, 0x73, 0x67, 0x57, 0x37, 0x77}; // if using a user defined keypad #elif defined KEYPAD_USERDEF #define KEY_TABLE_LENGTH 16 #else #error Keypad library - Please specify the style of keypad you wish to use. #endif // "private" function prototypes unsigned char keypad_scan(void); unsigned char keypad_lookup(unsigned char keycode); void keypad_map_keysymbol(unsigned char old_keysymbol, unsigned char new_keysymbol) { unsigned char i; // loop through entire table for (i=0; i