The example shows the connection of a 4 x 4 keyboard to a dsPIC30F6014A microcontroller. The example shows decoding the keyboard [0...15] to obtain ASCII symbols [0...9,A...F]. Also shown is a counter of the pressed keys. The value of the counter is written in the second line of an LCD module. The realization is carried out by using the mikroC compiler for dsPIC30F microcontrollers. Fig. 13-5 shows the interconnection of the keyboard and a dsPIC30F6014A microcontroller.
Fig. 13-5 Interconnection of the keyboard and a dsPIC30F6014A microcontroller
unsigned kp; void main() { ADPCFG = 0xFFFF; Keypad_Init(&PORTB); // PORTB [7..0] Uart1_Init(9600); Delay_ms(200); Uart1_Write_Char('R'); do { //--- Wait for key to be pressed do { //kp = Keypad_Key_Click(); // choose the key detecting function kp = Keypad_Key_Press(); } while (!kp); //--- Prepare value for output switch (kp) { // uncomment this block for keypad4x3 // /* case 10: kp = 42; break; // '*' case 11: kp = 48; break; // '0' case 12: kp = 35; break; // '#' default: kp += 48; */ // uncomment this block for keypad4x4 // case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 case 4: kp = 65; break; // A case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 case 8: kp = 66; break; // B case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 12: kp = 67; break; // C case 13: kp = 42; break; // * case 14: kp = 48; break; // 0 case 15: kp = 35; break; // # case 16: kp = 68; break; // D } //--- Send on UART1 Uart1_Write_Char(kp); } while (1); } //~!Also, an example is given of the clearance by the software of the errors caused by the keyborad bounsing using the same connection as shown in Fig. 13-5. The realization is carried out by using the mikroC compiler for dsPIC30F microcontrollers.
unsigned int oldstate; void main() { ADPCFG = 0xFFFF; TRISB = 0xFFFF; TRISD = 0x0000; do { if (Button(&PORTB, 0, 1, 1)) oldstate = 1; if (oldstate && Button(&PORTB, 0, 1, 0)) { LATD = ~LATD; oldstate = 0; } } while(1); }