You are on page 1of 23

INTERFACING

LCD
DIVISION OF MECHATRONICS
DEPARTMENT OF PRODUCTION TECHNOLOGY
MIT CAMPUS
ANNA UNIVERSITY - CHENNAI

Overview

LCD display working.

LCD specs.

Concepts.

Algorithm.

Programming

Initialization in atmega16.

Display strings.

Input and output devices

Outputs:

Motors ( DC, Stepper, Servo).

LEDS.

LCD.

7 segment.

Inputs:

Sensors.

Switch.

Keypad.

LCD

LCD (Liquid Crystal Display) screen is an


electronic display module.

A16x2 LCDmeans it can display 16 characters


per line and there are 2 such lines.

LCD each character is displayed in 5x7 pixel


matrix.

LCD has two registers, namely, Command and


Data.

LCD Pin configurations

LCD pin description

RS (Register Select): When RS=0, this allow


the user to send command such as (clear
screen, go home, blink cursor). When RS=1,
this allow the user to send data.

Enable: It used to latch the information to the


data pins, this done by send a high to low pulse
(of width of 450 ns) so the LCD latches the data
presented on the data pins.

LCD Initialization (hex value)

Sending commands and


data to LCD

The following steps should be done to send the


command and data to the LCD:
1) Initialized the LCD.
2) Sending Commands to the LCD.
3) Sending data to the LCD

Initializing the LCD


For example to initialize LCD [2 lines 5*7 matrix
8bit mode] the following commands should be
used:
1.

0x38 to select the type and mode of operation

2.

0x0E to display the cursor blinking.


0x01 to clear the LCD display.

Sending commands to LCD


3.

To send commands to the LCD the following steps should be done:


1.

RS=0, RW=0.

2.

The command number should be put on the data pins (D0 to


D7).

3.

A pulse (high to low) should be sent on the Enable pin. After


each command a delay of (100us) should be placed

Sending data to LCD


To send data to the LCD the following steps should
be done: RS=1, RW=0.
1.

The data should be put on the data pins (B0 to


B7).

2.

A pulse (high to low) should be sent on the


Enable pin.

After each data a delay of (100us) should be


placed.

Interfacing LCD
Can be interfaced either in 8-bit mode or 4-bit
mode.

In 8-bit mode , all data lines are connected.


In 4-bit mode, only four data lines are
connected.

Basic c instruction set for


LCD
LCD_Init();
/* Initilize

the lcd before displaying any thing on the lcd */

LCD_DisplayString("hello, world"); /*Display "hello, world" on first line*/


LCD_GoToLineTwo()

/*Go to second line and display "good morning" */

LCD_DisplayString("good morning")

LCD initialization
void LCD_Init()
{
delay_us(5000);
LCD_CmdWrite(0x38); // LCD 2lines, 5*7 matrix
LCD_CmdWrite(0x0E); // Display ON cursor ON Blinking off
LCD_CmdWrite(0x01); // Clear the LCD
LCD_CmdWrite(0x80); // Cursor to First line First Position
}

To write a cmnd to LCD


void LCD_CmdWrite( char cmd)
{
databus=cmd; // Send the command to LCD
rs=0; // Select the Command Register by pulling RS LOW
rw=0; // Select the Write Operation by pulling RW LOW
en=1; // Send a High-to-Low Pusle at Enable Pin
delay_us(10);
en=0;
delay_ms(1);
}

To write a data to LCD


void LCD_DataWrite( char dat)
{ databus=dat; // Send the data to LCD
rs=1; // Select the Data Register by pulling RS HIGH
rw=0; // Select the Write Operation by pulling RW LOW
en=1; // Send a High-to-Low Pusle at Enable Pin
delay_us(10);
en=0;
delay_ms(1); }

INTERFACING
KEYPAD
DIVISION OF MECHATRONICS
DEPARTMENT OF PRODUCTION TECHNOLOGY
MIT CAMPUS
ANNA UNIVERSITY - CHENNAI

Matrix Keyboard Connection to ports

Keyboards are organized in a matrix of rows and


columns.

The CPU accesses both rows and columns


through ports.

Therefore, with two 3-bit ports, an 3x3


matrix of keys can be connected.

If all the rows are


grounded and a
key
is pressed, one of
the columns will
have 0 since the
key
pressed provides
the
path to ground

If no key has
been pressed,
reading the
input port will
yield 1s for all
columns since
they are all
connected to
high (Vcc)

It is the function of the microcontroller to scan


the keyboard continuously to detect and
identify the key pressed.

To detect a pressed key, the microcontroller


grounds all rows by providing 0 to the output
latch, then it reads the columns.

If the data read from columns is D3 D0 =1111,


no key has been pressed and the process
continues till key press is detected.

If one of the column bits has a zero, this means


that a key press has occurred

For example, if D3 D0 = 1101, this means that


a key in the D1 column has been pressed

After detecting a key press, microcontroller will


go through the process of identifying the key

Task
Identify the row and column of the pressed key for each of
the following.
(a) D3 D0 = 1110 for the row, D3 D0 = 1011 for the
column
(b) D3 D0 = 1101 for the row, D3 D0 = 0111 for the
column

Algorithm

To make sure that the preceding key has been


released, 0s are output to all rows at once, and the
columns are read and checked repeatedly until all
the columns are high.

When all columns are found to be high, the program


waits for a short amount of time before it goes to the
next stage of waiting for a key to be pressed.

To see if any key is pressed, the columns are


scanned over and over in an infinite loop until one of
them has a 0 on it.

Remember that the output latches connected to


rows still have their initial zeros , making them
grounded

After the key press detection, it waits 20 ms for the


bounce and then scans the columns again

(a) it ensures that the first key press detection was


not an erroneous one due a spike noise
(b) the key press. If after the 20-ms delay the key is
still pressed, it goes back into the loop to detect a real
key press.

To detect which row key press belongs to, it


grounds one row at a time, reading the columns
each time.

If it finds that all columns are high, this means that


the key press cannot belong to that row

Therefore, it grounds the next row and


continues until it finds the row the key press
belongs to

Upon finding the row that the key press belongs to,
it sets up the starting address for the look-up table
holding the scan codes (or ASCII) for that row.

To identify the key press, it rotates the column


bits, one bit at a time, into the carry flag and
checks to see if it is low.

Upon finding the zero, it pulls out the ASCII


code for that key from the look-up table

otherwise, it increments the pointer to point to


the next element of the look-up table

Flow chart
1
Start

Read all
columns
All
keys
down
??

Ground
all rows

Wait for
debounce

Read all
columns

Read all
columns

All
keys
open
??

No
Yes

N
o

All
keys
down
??
Yes
2

2
Ground
Next row

No

All
keys
down
??

Yes

Find
which key
is pressed
Get scan code
from table
Return

Thank You For


Your
Attention

You might also like