8051 LCD, Keyboard, Stepper Motor, ADC, DAC
8051 LCD, Keyboard, Stepper Motor, ADC, DAC
INTERFACING
8051
INTRODUCTION
• Display units are the most important output
devices in embedded projects and electronics
products.
• Data register
• Command register
DATA REGISTER:
• It is for placing the data which is to be displayed.
• Data can be any character, alphabet or number.
• High logic at the RS pin will select the data
register.
• By making RS pin high and putting data in the 8
bit data line (DB0 to DB7), the LCD module
will recognize it as a data to be displayed.
COMMAND REGISTER:
• It is for placing the commands. There is a set of
commands for LCD to perform specific tasks.
• Low logic at the RS pin will select the command
register.
• By making RS pin low and putting data on the
data line, the LCD module will recognize it as a
command. Some of the instructions/commands
are given below:
Code (in Hex) Working of LCD commands
• Now read the columns, if the data read is all 1s, no key in that
row is pressed and the process continues for the next row.
• So, now ground the next row, R2. Read the columns, check for
any zero and this process continues until the row is identified.
•
CONTINUE…
• E.g. In above case we will get row 2 in which
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
FULL DRIVE MODE:
• In this mode, two coils are energized at the same time.
This mode produces more torque. Here the power
consumption is also high
• The following table is showing the sequence of input
states in different windings.
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
HALF DRIVE MODE:
• In this mode, one and two coils are energized
alternately.
• At first, one coil is energized then two coils are
energized.
• This is basically a combination of wave and full drive
mode. It increases the angular rotation of the motor
steps Winding A Winding B Winding C
Winding D
1 0 0 0
1
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0
1
Interfacing Stepper Motor with 8051
• We are using Port P0 of 8051 for connecting the stepper
motor. Here ULN2003 is used.
• This is basically a high voltage, high current Darlington
transistor array. Each ULN2003 has seven NPN Darlington
pairs.
• It can provide high voltage output with common cathode
clamp diodes for switching inductive loads.
• The Unipolar stepper motor works in three modes. The circuit
diagram is like below: We are using the full drive mode.
Assembly language program to interface stepper motor with 8051
// Wave Drive Mode
ORG 00H
MOV TMOD, #01H
MAIN:
MOV P2, #08H
ACALL DELAY
MOV P2, #04H
ACALL DELAY
MOV P2, #02H
ACALL DELAY
MOV P2, #01H
ACALL DELAY
SJMP MAIN
// To generate a delay of 200 *1 ms
DELAY:MOV R0,#200 //change this value to required delay in ms
BACK: MOV TH0,#0FCH
MOV TL0,#018H
SETB TR0
wait: JNB TF0,wait
CLR TR0
CLR TF0
DJNZ R0,BACK
RET
END
➢ RD:
• This is an input signal and is active low.
• The ADC converts the analog input to its binary equivalent and holds it in an internal
register.
• RD is, used to get the converted data out of the ADC0804 chip.
• Is “output enable” a high-to-low RD pulse is used to get the 8-bit converted data out of
ADC804.
➢ INTR:
• This is an output pin and is active low.
• It is “end of conversion” When the conversion is finished, it goes low to signal the CPU
that the converted data is ready to be picked up.
ADC804 chip:
WR:
• This is an active low input
• •It is “start conversion” When WR makes a low-to-high transition, ADC804 starts converting the
analog input value of Vin to an 8-bit digital number.
• •When the data conversion is complete, the INTR pin is forced low by the ADC0804.
➢ CS:
• It is an active low input used to activate ADC804.
➢ Steps to Be followed For Data Conversion:
• The following steps must be followed for data conversion by the ADC804 chip: o Make CS= 0 and
send a L-to-H pulse to pin WR to start conversion.
• Monitor the INTR pin, if high keep polling but if low, conversion is complete, go to next step.
• Make CS= 0 and send a H-to-L pulse to pin RD to get the data out.
• Figure 5.6 shows the timing diagram for ADC process.
ADC804 chip:
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.
;p2.6=WR (start conversion needs to L-to-H pulse)
;p2.7 When low, end-of-conversion)
;p2.5=RD (a H-to-L will read the data from ADC chip)
;p1.0 – P1.7= D0 - D7 of the ADC804
;
MOV P1,#0FFH ;make P1 = input
BACK: CLR P2.6 ;WR = 0
SETB P2.6 ;WR = 1 L-to-H to start conversion
HERE: JB P2.7,HERE ;wait for end of conversion
CLR P2.5 ;conversion finished, enable RD
MOV A,P1 ;read the data
ACALL CONVERSION ;hex-to-ASCII conversion
ACALL DATA_DISPLAY ;display the data
SETB P2.5 ;make RD=1 for next round
SJMP BACK