Professional Documents
Culture Documents
Aim: To interface 4X4 matrix keypad and LCD in 4 bit mode with Atmega16
and write program to detect key pressed and display on the LCD.
16X2 LCD,
Interface diagram:
Theory:
The keypad is used as an input device to read the key pressed by the user and to process
it.4x4 keypad consists of 4 rows and 4 columns. Switches are placed between the rows
and columns. A keypress establishes a connection between the corresponding row and
column between which the switch is placed.
In order to read the keypress, we need to configure the rows as outputs and columns as
inputs.
Columns are read after applying signals to the rows in order to determine whether or not
a key is pressed and if pressed, which key is pressed.
LCD:
Liquid Crystal Display is known as LCD is an electronic display which is
commonly used in many applications such as calculators, laptops, tablets, mobile
phones etc. there are many type of LCD
Such as 16×2 character LCD module is a very basic module which is commonly
used by electronic hobbyists and is used in many electronic devices and project.
It can display 2 lines of 16 character and each character is displayed using 5×7
or 5×10 pixel matrix
16×2 LCD can be interfaced with a microcontroller in 8 Bit or 4 Bit mode. These
differs in how data and commands are send to LCD. In 8 Bit mode character data
(as 8 bit ASCII) and LCD command are sent through the data lines D0 to D7.
That is 8 bit data is send at a time and data strobe is given through E of the LCD.
But 4 Bit mode uses only 4 data lines D4 to D7. In this 8 bit data is divided into
two parts and are sent sequentially through the data lines. The idea of 4 bit
communication is introduced to save pins of microcontroller. 4 bit communication
is bit slower than 8 bit but this speed difference has no significance as LCDs are
slow speed devices. Thus 4 bit mode data transfer is most commonly used.
Here, we are going to interface the 4x4 keypad with AVR ATmega16 and will display the pressed
a key on LCD16x2.
Program
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include "Lcdlbr/lcd.h"
int main(void)
{