Embedded System - Interfacing With 8051
Embedded System - Interfacing With 8051
By
Dr. Supratim Gupta
Part-1: Interfacing Keys
Keyboard Configuration
Lead-per-Key
Matrix Keypad
Coded Keyboard
Keyboard Configuration: Lead-per-Key
Keyboard Configuration: Matrix
Keyboard Configuration: Coded Keyboard
Robust Keyboard Operations: Human Factors
To guard against multiple & simultaneous key press and release in arbitrary
sequence
Schmitt Trigger
De-bounce/Accidental Key hit: To wait until a time interval –longer than the
manufacturer’s specification –lapses during both key press & release.
Multiple Key press: To use only a valid key patterns –all other patterns will be
ignored; the first valid key patterns will be accepted
Key Hold: To identify valid key press if the same valid pattern exists after the
de-bounce delay
Rapid Key hit: Keys are scanned at a rate faster than human reaction time
The Algorithm for keyboard Interface
Step 3: Check if same switch is remained pressed else return to main routine
Step 4: Check if valid key pattern is pressed else return to main routine
Key scanning via polling: May sluggish, but usable for small keypad & less
number of multi-task environment
Key scanning via interrupt: CPU will scan keys when interrupted; Optimal for
large key board & larger number of multi-tasking environment
Robust Keyboard Operations: Embedded Solution
To ADC Channel
Pre-conditioning Circuit
DAC Interfacing: DAC0808
20
= + + …+ = + + …+
2 4 256 2 4 256
DAC Interfacing: DAC0808
21
= + + …+
2 4 256
= + + …+
2 4 256
= + + …+
2 4 256
DAC Interfacing: Bipolar output signal
22
I0
DAC0809
LCD Display
7-Segment Display
7-Segment Display: Single Unit
Common Anode/Cathode
Step 3: Use index addressing –Base address + index (the nibbles of BCD no.) –
to a look up table for fetching code for 7-Segment LEDs
Step 4: Send the code to Port where the unit(s) is (are) connected
LCD Interface with 8051
LCD Interface with Microcontroller
RS R/W Operation
fOSC is
Instruction RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Description 270
kHz)
Sets interface data length (DL),
Function set 0 0 0 0 1 DL N F — — number of display lines (N), and 37 m s
character font (F).
fOSC is
Instruction RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Description 270
kHz)
Write data 37 m s
Writes data into DDRAM or
to CG or 1 0 Write data tADD =
CGRAM.
DDRAM 4 m s*
Read data 37 m s
Reads data from DDRAM or
from CG or 1 1 Read data tADD =
CGRAM.
DDRAM 4 m s*
Instructions for LCD Driver
I/D = 1 Increment DDRAM: Display data RAM
= 0 Decrement CGRAM: Character generator RAM
F = 1 5 ´ 10 dots, F = 0: 5 ´ 8 dots
= 1 Internally operating
BF
= 0 Instructions acceptable
Character Generator ROM Access
The Algorithm for LCD Display
Step 3: Send next instruction or data and repeat the process for other data
Alternatively DB7 can be connected to external interrupt pin and Step 1 & three
can be placed in the interrupt service routine
Example of LCD Display
Statement:
;Run part
acall lcd_disp ;call function for LCD display
stop: sjmp stop ;Run in infinite loop
The Algorithm for LCD Display
;__Second instruction to set display on/off, cursor on/off, and blinkin of cursor on/off_______
clr RS ;clear RS to send instruction
clr RW ;Clear RW for writing
mov P1,#0Fh ;send instruction (0 0 0 0 1 D C B) for display on,
;cursor on, and blinking on
setb Enb
clr Enb
lcall wait_lcd
The Algorithm for LCD Display
;__Third instruction to set cursor move direction, set displayshift on/off_______
clr RS ;clear RS to send instruction
clr RW ;Clear RW for writing
mov P1,#06h ;send entrymode instruction (0 0 0 0 0 1 I/D S) for display on,
;cursor on, and blinking on
setb Enb
clr Enb
lcall wait_lcd
;__First data_____________________________________________________________________
setb RS ;set RS to send data
clr RW ;Clear RW for writing
mov P1,#'H' ;send ascii value of H,
setb Enb
clr Enb
lcall wait_lcd
;__Second data____________________________________________________________________
setb RS ;set RS to send data
clr RW ;Clear RW for writing
mov P1,#'i' ;send ascii value of i,
setb Enb
clr Enb
lcall wait_lcd
The Algorithm for LCD Display
;Special Character from CGRAM
;__Third data____________________________________________________________________
setb RS ;set RS to send data
clr RW ;Clear RW for writing
mov P1,#3Bh ;send ascii value of semicolon obtained from character code and character pattern table of datasheet,
setb Enb
clr Enb
lcall wait_lcd
ret
Parallel communication implies sending a whole byte (or more) of data over
multiple parallel wires
Serial communication implies sending data bit by bit over a single wire
Add: Start, Stop, Parity Bits Remove: Start, Stop, Parity Bits
Transmitter + – Receiver
Data
Shifts the parallel data onto the Extracts the data using its own clock
serial line using its own clock
Converts the serial data back to the
Also adds the start, stop and parallel form after stripping off the
parity check bits start, stop and parity bits
Asynchronous Serial Communication
Start Bit Parity Bit 1 or 2 Stop Bits
D0 D1 D2 D3 D4 D5 D6 D7
1 Asynchronous Byte
Statement: