MP MC Module-5
MP MC Module-5
MICROCONTROLLERS
MODULE-5
I/O interfacing with
Microcontroller 8051
• LCD
• LED
I/O • Keypad
interfaci • Analog-to-Digital Convertors,
ng with • Digital-to-Analog Convertors
Microco •
ntroller Sensor with Signal Conditioning
8051 Interface.
When light from a backlight source is emitted and allowed to fall on the
vertical polarizer. Then the unpolarized light by the source gets
vertically polarized.
16x2
LCD
MODULE-5 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 6
LIQUID CRYSTAL DISPLAY (LCD)
In 16x2 LCD, 2 represents number of lines and 16 represents number of
characters displayed in each line. It supports all the ASCII characters and
provides the provision to display the custom characters by creating the
pattern. Each character in LCD is displayed in a matrix of 5x7 pixels.
ORG 0000H
MOV A, #38H ; INITIALIZE 2x16 LCD
ACALL COMNWRT ; call command
subroutine
ACALL DELAY ; give LCD some time
MOV A, #0EH ; display on, cursor on
ACALL COMNWRT ; call command
subroutine
MODULE-5 ACALL DELAY ; give LCD some time
BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 10
LIQUID CRYSTAL DISPLAY (LCD)
MOV A, #01 ; clear LCD
ACALL COMNWRT ; call command
subroutine
ACALL DELAY ; give LCD some time
MOV A, #06H ; shift cursor right
ACALL COMNWRT ; call command
subroutine
ACALL DELAY ; give LCD some time
MOV A, #84H ; cursor at line 1, pos. 4
ACALL COMNWRT ; call command
subroutine
ACALL DELAY ; give LCD some time
MOV A, #’V’ ; display letter N
ACALL DATAWRT ; call display
subroutine
ACALL DELAY ; give LCD some time
MOV A, #’I’ ; display letter O
ACALL DATAWRT ; call display
subroutine
ACALL DELAY ; give LCD some time
MODULE-5 MOV A, –#’T’
BECE204L MICROPROCESSORS ;AND
display letter O
MICROCONTROLLERS 11
LIQUID CRYSTAL DISPLAY (LCD)
COMNWRT: MOV P1, A ; send command to LCD by
coping reg A to port 1
CLR P2.0 ; RS=0 for command
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
DATAWRT: MOV P1, A ; write data to LCD by coping reg
A to port 1
SETB P2.0 ; RS=1 for data
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
DELAY: MOV R3, #50 ; 50 or higher for fast CPUs
HERE2: MOV R4, #255 ; R4 = 255
HERE: DJNZ R4, HERE ; stay until R4 becomes 0
DJNZ R3, HERE2 ; stay until R3 becomes 0
MODULE-5 RETBECE204L – MICROPROCESSORS AND MICROCONTROLLERS 12
LIQUID CRYSTAL DISPLAY (LCD)
EXAMPLE-2
Write an 8051 assembly language program to display the message “HELLO” on
LCD display using DPTR. Assume ; P1.0-P1.7=D0-D7, P2.0=RS, P2.1=R/W,
P2.2=E.
ORG 0000H
MOV DPTR, #MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT
ACALL DELAY
INC DPTR
JZ SEND_DAT
SJMP C1
Exercise: Write an 8051 assembly language program to display “Your Reg. No” on first line of
the LCD and “Your name” on the second line of the LCD using DPTR.
16
ORG 0030H
START: MOV P0,#0FFH ;MAKE P0 AN
INPUT PORT
ACALL LCD_INITIALIZE
MATCH: CLR A
MOVC A,@A+DPTR
ACALL LCD_DATA
;GET CODE FROM LOOK-UP TABLE
LJMP K1
;LOOP
Types of ADC:
Parallel - 8 or more pins for the binary data. Ex:
MODULE-5
0804, 0808 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 32
ANALOG TO DIGITAL CONVERTER (ADC)
The higher resolution ADC provides high accuracy by having a smaller
step size. Step size is smallest change that can be detected by an
ADC.
Vref/2:
It is used for the reference voltage
If this pin is open (not connected), the analog input voltage is in the range of
0 to 5 volts (the same as the Vcc pin)
If the analog input range needs to be 0 to 4 volts, Vref/2 is connected to 2
volt
MODULE-5 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 35
ANALOG TO DIGITAL CONVERTER (ADC)
D0-D7:
The digital data output pins and these are tri-state buffered
The converted data is accessed only when CS =0 and RD is forced low
To calculate the output voltage, use the following formula
Where, Dout= digital data output (in dec.), Vin= analog voltage, and step size
(resolution) is the smallest change
The ADC804 has 8-bit resolution with a maximum of 256 steps and
the LM35 (or LM34) produces 10 mV for every degree of temperature
Change
Most commonly used DAC is R/2R method due to high precision. DAC
resolutions (in bits): 8, 10, and 12 bits
ORG 0000H
SAWTOOTH: MOV A, #00H
BACK: MOV P1,A
INC A
CJNE A,#255, BACK
MOV A,#00
SJMP SAWTOOTH
RET
47