Professional Documents
Culture Documents
MP Lab Report # 3
MP Lab Report # 3
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Date: Signature:
Lab 3
Interfacing Keypad with PIC18F452
Objectives:
Interfacing keypad to PIC18F452
To make students enable of controlling devices using a key press
Displaying the number pressed against the pressed key on seven segment display
Hardware:
PIC18F452
Keypad
Seven segment displays (SSDs)
Introduction:
In this experiment we will interface 8051 microcontroller to keypad. This experiment will help
you to design different applications to control different processes and actions using 8051 by just
a key press. You can design a password protected application using keypad digits or you can
provide the user with different options represented by different digits. Keypad is a specially
designed circuitry which works on row and column selection operation. When a key is pressed,
this action internally shorts a row with a column corresponding to that digit.
While using software mikroC a library of “Keypad” is included to use Keypad comfortably.
LIBRARY of Keypad:
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.
The following global variable must be defined before using keypad library
The command of Keypad_Key_Click returns (1,2...16) if some key is released after pressing. If
no key is pressed or if key is pressed but not released it will returns 0.
Procedure:
Open MikroC, make new project and perform the given tasks
Lab Task#1:
Write a code to interface the keypad with PIC18F452. Pressed button will be displayed on seven
segment display. Make connections on hardware and in proteus.
CODE:
char keypadPort at PORTB; //keypad connections
void main() {
int i;
{ loop: i=Keypad_Key_Click(); //When key is released after pressing value is stored in i else i=0
if(i==0) //If "i" is 0 it means key is not pressed or if pressed than not released
Latd=ssd1[i-1];
}}
Schematic:
Open Proteus and make schematic given below.
Lab Task#2:
Make a calculator which can perform the function of addition by taking inputs from the keypad
and display output on the seven segment display. (keep your result up to 1 decimal)
Proteus:
Hardware:
Conclusion:
In this lab we learned the code and hardware of the keypad and seven segment display. We even make
a calculator which adds up the two numbers and show the result on the seven segment display.