Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING
EXPERIMENT: 03

Lab Title: . Interfacing keypad with MikroC PRO for PIC


Student Name: ABDUL MOEED, HASSAN ZEB, UMAIR-UL-HASSAN

Reg. No:190378, 190570, 190538

Objective: To recognize the working of Mikro-C and SmartPro 500u burner.

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes (5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

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

Char keypadPort at PORTX;

Command Syntax Description

Keypad_Init keypad_init(); Initializes port for working with keypad.


Reads the key from keypad when key gets
Keypad_Key_Press aa = Keypad_Key_Press(); pressed.
Reads the key from keypad when key gets
Keypad_Key_Click aa = Keypad_Key_Click(); pressed and released.

The command of Keypad_Key_Press returns (1,2...16) if some key is pressed. If no key is


pressed it will returns 0.

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() {

unsigned short int ssd1[16]={198,192,134,146,249,164,176,191,153,146,130,140,248,128,144,161};

int i;

Trisd=0; //Make portD output


LatD=255; //Just to turn off all leds of SSD as it is common anode

keypad_init(); //Initialize keypad

while(1) //Infinite loop

{ loop: i=Keypad_Key_Click(); //When key is released after pressing value is stored in i else i=0

delay_ms(10); //Just to add some delay of 10ms to stabilize

if(i==0) //If "i" is 0 it means key is not pressed or if pressed than not released

goto loop; //So in this case go back to loop statement

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.

You might also like