L14 kb-lcd-interfacing-with-atmega328 p

20
Interfacing Keyboard and LCD Displays (Lecture-14) R S Ananda Murthy Associate Professor Department of Electrical & Electronics Engineering, Sri Jayachamarajendra College of Engineering, Mysore 570 006 R S Ananda Murthy Interfacing Keyboard and LCD Displays

Transcript of L14 kb-lcd-interfacing-with-atmega328 p

Page 1: L14 kb-lcd-interfacing-with-atmega328 p

Interfacing Keyboard and LCD Displays(Lecture-14)

R S Ananda Murthy

Associate ProfessorDepartment of Electrical & Electronics Engineering,

Sri Jayachamarajendra College of Engineering,Mysore 570 006

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 2: L14 kb-lcd-interfacing-with-atmega328 p

Linear Arrangement of Keys

MCU

PB0

PB1

PB2

PB3

Keyboard is a collection of push-buttons.Each key has an associated internal pull-up resistorenabled.In linear arrangement, number of input lines required isequal to the number of keys.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 3: L14 kb-lcd-interfacing-with-atmega328 p

Matrix Arrangement of Keys

When large number of keys are to be interfaced, lineararrangement is not preferred since the number of inputlines required will be more.In matrix arrangement, a key is connected between a rowand a column.If there are R rows and C columns, then, the maximumnumber of keys in the matrix could be N = R×C and thenumber of lines required for interfacing would be R+C andnot N.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 4: L14 kb-lcd-interfacing-with-atmega328 p

Matrix Arrangement of Keys

0123

4567

89AB

CDEF

10k 10k 10k 10k

10k

10k

10k

10k

PD4PD5PD6PD7

Input Lines

PD3

PD2

PD1

PD0

Out

put L

ines

Vcc

Only one 8-bit port is needed to interface 4×4 keyboardmatrix instead of two 8-bit ports as in linear arrangement.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 5: L14 kb-lcd-interfacing-with-atmega328 p

Steps to Identity Depressed Key

1 Poll the keyboard for any previously pressed key to bereleased.

2 Poll the keyboard for any key to be pressed.3 When any key is pressed, wait for about 20 ms to

debounce the key.4 Scan the keyboard to find which key is pressed to generate

the keycode.5 Perform the operation assigned to a key.6 Go back to Step-1.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 6: L14 kb-lcd-interfacing-with-atmega328 p

Keyboard Interface Logic

Start

Ground all rows

Read columns

All keysopen

?

No

Yes

A

A

Read columns

Any keydown

?

No

Yes

Wait for debounce

B

B

Read columns

Any keydown

?

No

Yes

A

C

Identify Key

C

Do operationassigned to key

D

D

In case of encoded keyboard, the keycode is generated byhardware.In case of un-encoded keyboard, the keycode has to begenerated by software.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 7: L14 kb-lcd-interfacing-with-atmega328 p

Identifying the Depressed Key

Ground next row

Read columns

key onin this row

?

No Yes Scan columnsto identify key

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 8: L14 kb-lcd-interfacing-with-atmega328 p

16×2 LCD Panel

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 9: L14 kb-lcd-interfacing-with-atmega328 p

Advantages of LCD Panels

LCD panels are becoming cheaper.LCD panels can display numbers, characters, and graphicsunlike LEDs which are limited to numbers and fewcharacters.Since LCDs have an in-built refreshing controller the MCUneed not refresh the display as in the case of LEDs.LCDs are easy to program since ASCII codes are used fordisplay by LCDs instead of 7-segment codes used forLEDs.LCDs consume less power.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 10: L14 kb-lcd-interfacing-with-atmega328 p

LCD Pin Descriptions

Pin Signal I/O Description1 VSS – Ground2 VCC – +5 V Supply3 VEE – Power supply to control contrast

4 RS IRS = 0 selects Command Register

RS = 1 selects Data Register

5 R/W IR/W = 0 for write operationR/W = 1 for read operation

6 E I/O High-to-low pulse latches data to LCD7-14 D0-D7 I/O Lines for sending or reading data

LCD panel sizes are specified as C ×L whereC =Characters per line and L = No. of lines.ASCII codes are used for display.8-bits or 4bits data lines can be used for interfacing to theMCU.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 11: L14 kb-lcd-interfacing-with-atmega328 p

LCD Connections using 8-bit Data Bus

10 kPot

PD0

PD7

..

..

...

Atmega328P LCD

D0

..

..

...D7

PB0PB1PB2

RS R/W E

+ 5 V

Commands to initialize the LCD panel: 0x38, 0x0E, 0x01.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 12: L14 kb-lcd-interfacing-with-atmega328 p

LCD Connections using 4-bit Data Bus

10 kPot

PD4

PD7....

Atmega328P LCD

D4

..

..

D7

PB0PB1PB2

RS R/W E

+5 V

Requires PB0, PB1, PB2 and higher nibble of Port D onwhich data is sent, higher nibble first.Initialization commands: 0x33, 0x32, 0x28, 0x0E, 0x01,0x06

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 13: L14 kb-lcd-interfacing-with-atmega328 p

LCD Connections using Only One Port

10 kPot

PD4

PD7....

Atmega328P LCD

D4

..

..

D7

PD0PD1PD2

RS R/W E

+ 5V

Requires only Port D.Initialization commands: 0x33, 0x32, 0x28, 0x0E, 0x01,0x06

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 14: L14 kb-lcd-interfacing-with-atmega328 p

LCD Command Codes

Hex Code Command to LCD Command Register01 Clear display screen02 Return home04 Shift cursor to left by one position06 Shift cursor to right by one position05 Shift display right07 Shift display left08 Display off, cursor off0A Display off, cursor on0C Display on, cursor off

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 15: L14 kb-lcd-interfacing-with-atmega328 p

LCD Command Codes

Hex Code Command to LCD Command Register0E Display on, cursor blinking0F Display on, cursor blinking10 Shift cursor position to left14 Shift cursor position to right18 Shift the entire display to the left1C Shift the entire display to the right80 Force cursor to the beginning of 1st lineC0 Force cursor to the beginning of 2nd line28 2-lines and 5×7 matrix D4-D7, 4 bits33 Go into 4-bit operating mode32 Go into 4-bit operating mode38 2-lines and 5×7 matrix D0-D7, 8 bits

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 16: L14 kb-lcd-interfacing-with-atmega328 p

Steps for Sending Commands and Data to LCD

1 Initialize LCD.2 Send any of the commands to the LCD for the required

operation.3 Send the character to be shown to the LCD.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 17: L14 kb-lcd-interfacing-with-atmega328 p

Initializing the LCD Panel

1 After power-on, wait for about 15 ms before sending theinitializing commands to the LCD panel.

2 For eg. to initialize the LCD for 5×7 matrix and 8-bitoperation, send the following commands to the commandregister of the LCD panel: 0x38, 0x0E, and 0x01.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 18: L14 kb-lcd-interfacing-with-atmega328 p

Sending Commands to the LCD Panel

Make pins RS = 0 and R/W = 0.Place the command bits on the data pins.Send a high-to-low pulse to the E pin of the panel.Wait for about 100µs before sending the next command.But in case of clear LCD (0x01) and Return Home (0x02)commands wait for about 2 ms before issuing the nextcommand.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 19: L14 kb-lcd-interfacing-with-atmega328 p

Sending Data to the LCD Panel

Make pins RS = 1 and R/W = 0.Place the data on the data lines in ASCII format. Forexample, to display A, the ASCII code to be placed on thedata lines would be 0x41.Send a high-to-low pulse to the E pin of the panel.Wait for about 100µs before sending the next data.

R S Ananda Murthy Interfacing Keyboard and LCD Displays

Page 20: L14 kb-lcd-interfacing-with-atmega328 p

License

This work is licensed under aCreative Commons Attribution 4.0 International License.

R S Ananda Murthy Interfacing Keyboard and LCD Displays