/* (C) 2005 by Richard West (rw88@cornell.edu) * Published: 25 Feb 2005 * Published under GNU General Public License - http://www.linux.org/info/gnu.html * * Keypad test program * * Hardware setup notes: * Keypad connected to PortA.0-7 * LCD connected to PortC.0-7 */ // Mega32 compiler directive #include // LCD compiler directives #asm(".equ __lcd_port=0x15") #include // keypad compiler direcive //#define KEYPAD_TELPAD // using a telephone style keypad #define KEYPAD_HEXPAD // using a hexadecimal style keypad //#define KEYPAD_KEYBOARD // using a telephone style keypad as a keyboard #define KEYPAD_USEPORTA // wish to connect keypad to PortA #define KEYPAD_USEDISPLAY // wish to use and LCD for display #include "keypad.h" // runtime global variables unsigned char count; unsigned char keypad_time; // function prototype void init(void); // timer0 overflow interrupt service routine interrupt [TIM0_OVF] void tim0_ovf_isr(void) { // decrement and check count if(!(--count)) { // increment time and reset count count = 62 + (++keypad_time%2); } } void main(void) { // map keypad buttons #ifdef KEYPAD_TELPAD keypad_define_terminator('#'); keypad_map_keysymbol('*','.'); #endif #ifdef KEYPAD_HEXPAD keypad_define_terminator('E'); keypad_map_keysymbol('F','.'); #endif lcd_init(16); // initialize LCD init(); // initialize MCU // quick welcome message lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("#"); #ifdef KEYPAD_USEDISPLAY // setup keypad display options keypad_set_display(KEYPAD_ECHODISPLAY); keypad_gotoxy(0,0); #endif // release the keypad keypad_release(); while(1) { // check keypad_time if (keypad_time >= 30) { // reset keypad_time keypad_time = 0x00; // get keystring keypad_get_string(); } if (keystring_ready) { // display keystring on LCD lcd_clear(); lcd_gotoxy(0,1); lcd_puts(keystring); // reset the keypad #ifdef KEYPAD_USEDISPLAY keypad_gotoxy(0,0); #endif keypad_release(); } } } void init(void) { // initialize ports DDRA = 0x00; // set portA as input // setup timer0 // 16 MHz system clock // prescaler = 1 -> 16 MHz timer TIMSK = 0x01; // enable the timer0 overflow interrupt TCCR0 = 0x01; // set timer0 to system clock // enable interrupts #asm("sei") }