Header Ads

Keypad interfacing with pic microcontroller and Mikro C

In this tutorials I will show you how to interfacing matrix keypad with PIC16F877A microcontroller. You can watch the flowing video and read the written tutorial below.




Keypad is set of button. It contain digits,symbols&alphabetical letters. It can be 4x4&4x3. 4x3 it means 3 column and 4 row.

4x4 keypad structue below.




In this tutorial I am use Mikro C pro for PIC Compiler for microcontroller programming.
The mikroC PRO for PIC provides a library for working with 4x4 keypad. The library routines can also be used with 4x1, 4x2, or 4x3 keypad.


External Dependencies of Keypad Library




Library Routine

  • Keypad_Init
  • Keypad_Key_Press
  • Keypad_Key_Click
Keypad_Init




Keypad_Key_Press


Keypad_Key_Click

Mikro C Code:
// keypad module connections
char keypadPort at PORTD;
// keypad module connection end
// Lcd module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End Lcd module connections
void main() {
Lcd_Init(); // intilize Lcd module
Keypad_Init(); // intialize keypad module
Lcd_Cmd(_LCD_CLEAR); // Clear Lcd display
Lcd_Out(1,3,"WELCOME TO");
Lcd_Out(2,1, "MINA TECHNOLOGY");
delay_ms(1000); // 1 second delay
Lcd_Cmd(_LCD_CLEAR); // Clear Lcd display
while(1){
kp = 0 ; // reset kp code variable
// wait for key to be pressed and realized
do
kp = Keypad_Key_Click(); // Store key code in kp variable
while(!kp);
// Preper value for output transfrom key it's ASCII value
switch(kp){
case 1 : Lcd_Cmd(_LCD_CLEAR); break ; // Clear Lcd display
case 2 : kp = '0' ; break ; // 0
case 3 : kp = '='; break ; // =
case 4 : kp = '+' ; break ; // +
case 5 : kp = '1' ; break ; // 1
case 6 : kp = '2' ; break ; //2
case 7 : kp = '3' ; break ; //3
case 8 : kp = '-' ; break ; // -
case 9 : kp = '4' ; break ; //4
case 10 : kp = '5' ; break ; // 5
case 11 : kp = '6' ; break ; // 6
case 12 : kp = '*' ; break ; // *
case 13 : kp = '7' ; break ; // 7
case 14 : kp = '8' ; break ; // 8
case 15 : kp = '9' ; break ; // 9
case 16 : kp = '/' ; break ; // '/'
}
Lcd_Chr_Cp(kp);
}
}
view raw gistfile1.txt hosted with ❤ by GitHub





Download here for mikro C and Proteus file. Click download button.
download
download


No comments

Theme images by 5ugarless. Powered by Blogger.