0% found this document useful (0 votes)
36 views27 pages

Led 7 Seg Keypad

The document discusses interfacing LEDs, seven segment displays, LCDs, and keyboards with a microcontroller. It provides details on connecting and programming these components, including examples of blinking LEDs, driving seven segment displays, initializing and writing to LCDs, and reading button presses from a keyboard matrix.

Uploaded by

Venkat Balaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views27 pages

Led 7 Seg Keypad

The document discusses interfacing LEDs, seven segment displays, LCDs, and keyboards with a microcontroller. It provides details on connecting and programming these components, including examples of blinking LEDs, driving seven segment displays, initializing and writing to LCDs, and reading button presses from a keyboard matrix.

Uploaded by

Venkat Balaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

26-03-2024

BECE204L
Microprocessors and Microcontrollers
Module 5
I/O interfacing with Microcontroller 8051

Module:5
I/O interfacing with Microcontroller 8051
LCD, LED, Keypad, Analog-to-Digital Convertors, Digital-to-
Analog Convertors, Sensor with Signal Conditioning Interface.

7 hours

1
26-03-2024

Light Emitting Diodes (LED)


• Simplest display element.
• Available in wide varieties of shapes and colors.
• Used to indicate the status of the device like powered on,
running, waiting, error, etc.
• Commonly used as indicator in majority of the electronic
appliances like televisions, audio/video systems, printers,
washing machines, disk drives, control panels, etc.
• The color of an LED is determined by the semiconductor
material used for it. The most common colors are green,
red, yellow, orange, blue and white.

LED

2
26-03-2024

LED
• When the anode of an LED is made positive with respect
to the cathode, it will be forward-biased (ON) and will
emit the light.

LED
• The pin P1.0 is connected to a buffer (inverter).
• When P1.0 is high, output of an inverter is low causing the
current to flow through the LED and it will glow.
• When P1.0 is low, output of an inverter is high, and no
current flows through the LED and will stop emitting light.
• The inverter in the circuit acts as a current buffer and
prevents the port pins from current loading, the current
flows between the inverter and the 5 V supply.
• The resistor R limits the current through the LED and
protects it from damage.

3
26-03-2024

LED Interfacing methods


LED
• Method 1:The port pin will source the current when the port pin is
high for configuration.
• Method 2:The LED will glow when the pin is made low, where it sinks
the current, a current limiting resistor should be connected as shown
to protect the LED as well as port circuits.

8051 interfacing with LED

4
26-03-2024

Delay calculation for 0.5 seconds delay


• 8051 crystal frequency is 12MHz
• Clock frequency 12MHz/12 = 1MHz
• Time period for 1 clock = 1/1MHz = 1µs
• DJNZ will take 2 Machine cycles
• For 0.5s delay
MC×TP×N(loop) = 2×1µs×N = 0.5
N = 250000= 250× 250× 4

Problems
• Write a ALP to blink LED connected on Port 2

5
26-03-2024

Problems

Problems
• Write an ALP to blink one led connected on P1.0

6
26-03-2024

Problems

Problems
• Interface eight LEDs and eight pushbutton switches to Port 3 and Port 2 of
89C51 respectively. Write a program to monitor the status of all switches
and display it on the corresponding LEDs, i.e. LED 0 should glow when switch
0 is pressed and so on.

7
26-03-2024

Problems
• Write a ALP to read the status of a switch connected on P0.0 and turn the led
connected on P2.0 on/off as per switch position

Problems

8
26-03-2024

Problems
• write a program to glow LEDS one by one in a sequence continuously.

Seven segment display


• Seven (8th LED may be used for Decimal point) LED’s in
the form of figure 8.
• Types
– Common Anode
– Common Cathode

9
26-03-2024

Seven segment display

Seven segment display

10
26-03-2024

Seven segment display

Seven segment display

11
26-03-2024

Seven segment display

Seven segment display

12
26-03-2024

To display 2021

Liquid Crystal Display


• An LCD is electronically modulated optical device shaped into a
thin, flat panel.
• Made up of No. of color or monochrome pixels filled with liquid
crystals.
• LCD is finding widespread use replacing LEDs
– The declining prices of LCD.
– The ability to display numbers, characters, and graphics.
– Incorporation of a refreshing controller into the LCD,
thereby relieving the CPU of the task of refreshing the LCD.
– Ease of programming for characters and graphics.

13
26-03-2024

Types of LCD
• Depending on No. of characters and No. of Rows.
1×16 2×16

4×16 4×20

Pin Details

14
26-03-2024

Interfacing LCD with 8051

LCD Command Codes


• To send any of the commands to the
LCD, make pin RS=0.
• For data display, make RS=1.
• Then send a high-to-low pulse to the E
pin to enable the internal latch of the
LCD.

15
26-03-2024

Initialization Comments

• 38H Setup 2 line 5×7 matrix display.


• 0FH Display ON Cursor ON Cursor blinking.
• 01H Clear the Display.
• 06H Cursor increment mode (left to right)
• 80H Force Cursor Home (line 1, Position 1)

Checking (Reading) busy flag


• Some time (Delay) is required for the LCD to successfully
process the command or data.
• This delay can be provided either with a delay loop with
execution time more than that of LCD process time or we can
read the busy flag, which is recommended.
• The reason to use busy flag is that delay produced is almost
equal to the time which LCD need to process the command.
• This busy flag is best suited for almost every applications.

16
26-03-2024

Steps to read busy flag


• when we send the command, the BF or D7th bit of the LCD
becomes 1 and as soon as the command is processed the BF = 0.
• Following are the steps to be kept in mind while reading the Busy
flag.
– Select command register
– Select read operation
– Send enable signal
– Read the flag

Problem

17
26-03-2024

Problem

Problems
Write a ALP to display Hello VITV on port 2.
509 V
508 T
507 I
506 V
505
504 O
503 L
502 L
501 E
500 H

18
26-03-2024

Keyboard
• Keyboard – array of switches
• Types
– Mechanical
– Membrane
– Capacitors
– Hall-effect
• Mechanical switches are popular.
• Contact bounce problem- switch contacts do not come to rest
immediately.
• Human cannot type more than 50 keys per second

Keyboard

19
26-03-2024

Keyboard

Keyboard

20
26-03-2024

Keyboard
• Row – output, Column - Input

4×4 Matrix Keypad


• Row – output (00H), Column – Input(0FH)

21
26-03-2024

Keypad Interfacing
• Port 1 –output -00H (0000 0000)
• Port 2- input – 0FH (0000 1111)
• Key pressed, which key, KEY to seven segment

0 0

1 1

7 segment display

22
26-03-2024

Problems

Problems

23
26-03-2024

Switch Bouncing

24
26-03-2024

De-bouncing Solutions
• Hardware debouncing
• Software debouncing
• RC debouncing
• Using debouncing IC’s

Hardware debouncing
• Hardware debouncing uses an SR latch to avoid bounces in the
circuit along with the pull up resistors

SW B A Q
OFF 1 0 0
ON 0 1 1

25
26-03-2024

RC debouncing
• Uses capacitor to filter out quick changes in the switch signal

SW B out
OFF 1 0
ON 0 1

Debouncing IC’s
• MAX6816, MAX6817, MAX6818, MC 14490, LogiSwitch LS118

26
26-03-2024

Software debouncing
• Adding delay force the controller to stop for a particular time
period
• Using delay, not a good solution, it pauses the program and
increase the processing time
• Use interrupt

27

You might also like