Microprocessor Systems & Interfacing EEE-342: Comsats University
Microprocessor Systems & Interfacing EEE-342: Comsats University
Microprocessor Systems & Interfacing EEE-342: Comsats University
Name
Registration Number
TOOLS:
SOFTWARE TOOLS:
AVR Studio/ Atmel Studio
Proteus ISIS
AVRDUDESS
HARDWARE TOOLS:
Arduino Nano - 1
4X4 Keypad - -
Resistors 100Ω 8
PRE-LAB TASK:
4X4 MEMBRANE KEYPAD:
The Keypad 4x4 features 16 push buttons arranged in 4x4 matrix to form standard
alphanumeric keypad. It provides a useful human interface component for microcontroller
projects.Matrix keypads uses a combination of four rows and four columns to provide
button states to the microcontroller. Underneath each key is a pushbutton, with one end
connected to one row, and the other end connected to one column. These connections are
shown in figure 6.1.
KEY SPECIFICATIONS
Maximum Rating: 24 VDC, 30 mA
Interface: 8-pin access to 4x4 matrix
Operating temperature: 32 to 122 °F (0 to 50°C)
Dimensions: Keypad, 2.7 x 3.0 in (6.9 x 7.6 cm) Cable: 0.78 x 3.5 in (2.0 x 8.8 cm)
This keypad can be used in Security systems, Menu selection, Data entry for embedded
systems and various other applications.
WORKING OF KEYPAD:
From Figure 6.11 it can be seen that if one of the 16 buttons are pressed, a pair of pins are
connected together. We will used this feature to detect with button was pressed. Under
normal conditions, the switch (key) is open. In order for the microcontroller to determine
which button is pressed, following steps are followed:
1) Create a look-up table filled with 16 entries for all keys of the keypad.
2) Four microcontroller pins should be defined as outputs, and other four pins should be
defined as inputs.
3) Connect columns of the keypad to input port and rows to the output port. Pull up the
input port and then read the value of columns.
4) Now connect rows of the keypad to input port and columns to the output port. Pull up
the input port and then read the value of rows.
5) If no key is pressed, the value of rows and columns will be 0000. If any key is pressed,
the value of rows and columns can be 0000,0001,0010,0100,1000 (1,2,4,8).
6) If no key is pressed, return 0. If a key is pressed, find its location in the keypad look-
up table and return the key pressed.
IN-LAB TASKS:
INTERFACING ATMEGA 328P WITH KEYPAD: CONNECT A KEYPAD TO THE
MICROCONTROLLER. SCAN THE KEYPAD FOR KEY PRESS AND DISPLAY
THE PRESSED KEY ON THE SERIAL MONITOR USING SERIAL
COMMUNICATION.
TASK 1- CODE:
#include <inttypes.h> //Used for type casting
#include <avr/io.h> //Basic I/O definitions
#define F_CPU 16000000UL //XTAL Frequency
#include <util/delay.h> //to generate delays
#include "debug_prints.c"
#define BAUD0 9600 // Baud Rate for UART
#define MYUBRR (F_CPU/8/BAUD0-1) // U2X = 1
//************* Definitions for Keypad Interfacing **********/
//Rows are connected to PORTB, Columns to PORTD
#define KEYPAD_DDR_ROWS DDRB
#define KEYPAD_PORT_ROWS PORTB
#define KEYPAD_PIN_ROWS PINB
#define KEYPAD_DDR_COLS DDRD
#define KEYPAD_PORT_COLS PORTD
#define KEYPAD_PIN_COLS PIND
int main()
{
unsigned char key_pressed = 0;
PROTEUS SIMULATION
HARDWARE IMPLEMENTATION
TASK 1 OUTCOMES:
The given code scans the keypad for key press and display the pressed key on the serial
monitor using serial communication. The provided code was tested on Atmel/AVR studio
and a hex file that was burned in the microcontroller. Afterwards, a simulation on proteus
was done to aid the hardware implementation.