Unit - 5 8051 Interfacing Andapplications Interfacing of 8051with: Analog Sensors, Keypad & LCD Display, ADC, DAC, DC Motor. LCD Interfacing
Unit - 5 8051 Interfacing Andapplications Interfacing of 8051with: Analog Sensors, Keypad & LCD Display, ADC, DAC, DC Motor. LCD Interfacing
LCD INTERFACING:
➢ We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive
information’s.
➢ The busy flag id D7 and can be read when R/W=1 and RS=0, as follows: if R/W=1,
RS=0.
➢ When D7=1 (busy flag =1), the LCD is busy taking care of internal operations and will
not accept any new information.
LED+ & LED-:
➢ LED+ is the anode of the back light LED and this pin must be connected to Vcc through
a suitable series current limiting resistor.
➢ LED- is the cathode of the back light LED and this pin must be connected to ground.
LCD initialization
➢ The steps that has to be done for initializing the LCD display is given below and these
steps are common for almost all applications.
o Send 38H to the 8 bit data line for initialization
o Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
ORG 0
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
MOV A,#’N’ ;display letter N
ACALL DATAWRT ;call display subroutine
READY:
SETB P1.7 ;make P1.7 input port
CLR P2.0 ;RS=0 access command reg
SETB P2.1 ;R/W=1 read command reg
;read command reg and check busy flag
BACK: SETB P2.2 ;E=1 for H-to-L pulse
CLR P2.2 ;E=0 H-to-L pulse
JB P1.7,BACK ;stay until busy flag=0
RET
END
LCD Interfacing Using MOVC Instruction:
ORG 0
MOV DPTR,#MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ SEND_DAT
SJMP C1
SEND_DAT:
ORG 300H
MYCOM: DB 38H,0EH,01,06,84H,0 ; commands and null
MYDATA: DB “HELLO”,0
END
KEYBOARD INTERFACING:
➢ At the lowest level, keyboards are organized in a matrix of rows and columns.
➢ The CPU accesses both rows and columns through ports; therefore, with two 8-bit ports,
an 8 x 8 matrix of keys can be connected to a microprocessor.
➢ When a key is pressed, a row and a column make a contact; otherwise, there is no
connection between rows and columns
Scanning and identifying the key
➢ Figure 5.3 shows a 4 x4 matrix connected to two ports.
➢ The rows are connected to an output port and the columns are connected to an input
port.
➢ If no key has been pressed, reading the input port will yield 1s for all columns since they
are all connected to high (Vcc).
➢ 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.
➢ It is the function of the microcontroller to scan the keyboard continuously to detect and
identify the key pressed, How it is done is explained next.
➢ D0-D7:
• D0-D7 are the digital data output pins.
• These are tri-state buffered and the converted data is accessed only when CS =0
and RD is forced low.
• To calculate the output voltage, use the following formula
Figure 5.8 8051 Connection to ADC0804 with Clock from XTAL2 of the 8051
Example:
Write a program to monitor the INTR pin and bring an analog input into register A. Then call a
hex-to ACSII conversion and data display subroutines. Do this continuously.
ADC0808:
➢ While the ADC0804 has only one analog input, this chip has 8 of them.
➢ The ADC0808/0809 chip allows us to monitor up to 8 different analog inputs using only a
single chip.
➢ Notice that the ADC0808/0809 has an 8-bit data output just like the ADC804.
➢ The 8 analog input channels are multiplexed and selected according to Table 5.5 using
three address pins, A, B, and C.
Table 5.5 Channel Selection in ADC0808
➢ In the ADC0808/0809, Vref (+) and Vref.(-) set the reference voltage.
➢ If Vref(-) = Gnd and Vref (+) = 5 V, the step size is 5 V/256 = 19.53 mV.
➢ Therefore, to get a l0 mV step size we need to set Vref (+) = 2.56 V and Vref.(-) = Gnd.
➢ From Figure 5.9, notice the ALE pin.
➢ We use A, B, and C addresses to select.IN0 - IN7, and activate ALE to latch in the
address.
➢ SC is for start conversion.
➢ SC is the same as the WR pin in other ADC chips.
➢ EOC is for end-of-conversion, and OE is for output enable (READ).
➢ The EOC and OE are the same as the INTR and RD pins respectively.
➢ Table 5.6 shows the step size relation to the Vref voltage.
➢ Notice that there is no Vref/2 in the ADC0808/0809 chip.
➢ The sensors of the LM34 series are precision integrated-circuit temperature sensors
whose output voltage is linearly proportional to the Fahrenheit temperature.
➢ It also internally calibrated.
➢ It outputs 10mV for each degree Fahrenheit temperature.
Signal Conditioning and Interfacing the LM35 to the 8051
➢ The above figure 5.10 shows the steps involved in acquiring data from analog world.
➢ Signal conditioning is widely used in the world of data acquisition.
➢ The most common transducers produce an output in the form of voltage, current,
charge, capacitance, and resistance.
➢ However, we need to convert these signals to voltage in order to send input to an A-to-D
converter.
CONVERSION:
MOV B,#10
DIV AB
MOV R7,B
MOV B,#10
DIV AB
MOV R6,B
MOV R5,A
RET
DATA_DISPLAY:
MOV P0,R7
ACALL DELAY
MOV P0,R6
ACALL DELAY
MOV P0,R5
ACALL DELAY
RET
DAC0808:
➢ The digital inputs are converter to current (Iout), and by connecting a resistor to the Iout
pin, we can convert the result to voltage.
➢ The total current provided by the Iout pin is a function of the binary numbers at the D0-D7
inputs of the DAC0808 and the reference current (Iref), and is as follows
Example 3:
Verify the values given for the following angles: (a) 30º (b) 60º
Solution:
(a) Vout = 5V+(5V * sin30) =7.5V
DAC input values = 7.5V * 25.6 = 192 (Decimal)
(b) Vout = 5V+(5V * sin60) =9.33V
DAC input values = 9.33V * 25.6 = 238 (Decimal)
Example 4:
Write an ALP to generate a sine waveform.
Vout= 5V(1+sinθ)
Solution:
Calculate the decimal values for every 10 degree of the sine wave. These values can be
maintained in a table and simply the values can be sent to port P1. The sine wave can be
observed on the CRO.
Example 5:
Write an ALP to generate a triangular waveform.
Reference:
• Muhammed Ali Mazidi, Janice Gillispie Mazidi and Rolin D.McKinlay, “The 8051
Microcontroller and Embedded Systems: Using Assembly and C”