C HAPTER 3: 8051 I NTERFACING
AND A PPLICATIONS
O BJECTIVE
To know the importance of different peripheral
devices and their interfacing with
microcontrollers
To know the interfacing of stepper motor, liquid
crystal display, seven segment display
LCD INTERFACING
Pin diagram
LCD Commands
Program
F EATURES
Low current consumption
The declining prices of LCDs
The ability to display numbers, characters and
graphics
Ease of programming for characters and graphics
LCD D ISPLAYS
16 X 2 LCD S PECIFICATIONS
P IN C ONFIGURATION
P IN CONFIGURATION
There are two internal registers of LCD
Instruction command register
Data register
RS pin is used to select one of these two registers
If RS=0, the instruction command code register is
selected
If RS=1, the instruction Data register is selected
R/W pin is used to read or write to LCD
R/W=1 when reading
R/W=0 when writing
When data is supplied to data pins, a high to low pulse
must be applied to this pin in order to latch the data
present on data lines
LCD I NTERFACING
LCD COMMANDS
LCD COMMANDS
LCD P ROGRAMMING S TEPS
P ROBLEM S TATEMENT
P ROBLEM S TATEMENT
P ROBLEM STATEMENT
Design a microcontroller based system to interface
LCD with 8051 and display message ‘NO’
MOV A,#38H // Use 2 lines and 5x7 matrix
ACALL CMND
MOV A,#0FH // LCD ON, cursor ON, cursor blinking ON
ACALL CMND
MOV A,#01H //Clear screen
ACALL CMND
MOV A,#06H //Increment cursor
ACALL CMND
MOV A,#80H //Cursor line one , first char
ACALL CMND
ACALL DEALY give time for LCD
MOV A,#’N’H Display Letter N
ACALL DATWRT
ACALL DEALY
MOV A,#’0’H
ACALL DATWRT
ACALL DEALY
UP SJMP UP stay here
CMND MOV P1,A // CPPY 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
CLR P2.2 //E=0 for H to L pulse
RET
DATWRT MOV P1,A // CPPY 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
CLR P2.2 //E=0 for H to L pulse
RET
I NTERFACING OF SEVEN SEGMENT
DISPLAY
SEVEN SEGMENT DISPLAY
7-segment displays come in 2 configurations:
Common Anode
Common Cathode
A resistor will be needed to control the current
Case 2 would be more appropriate
Case 1 will produce different brightness depending on
the number of LEDs turned on.
SEVEN SEGMENT DISPLAY
SEVEN SEGMENT DISPLAY CODE FOR
COMMON CATHODE
SEVEN SEGMENT DISPLAY
SEVEN SEGMENT DISPLAY
DB: Assembler directive indicating 8 bit value
SEVEN SEGMENT DISPLAY
Port 1 is used to send data on seven segment display and
port 3 is used to control it (Switch ON & OFF display)
S EVEN SEGMENT DISPLAY
I NTERFACING WITH 8051
Two 7-segment displays connected to the same port on the
8051. Because the circuit is connected in this way we have to
multiplex the output.
switch on display 1 and switch off the other display
switch on display 2 and switch off the other display
If it is this fast enough, we will not be able to notice that one of
the 7-segment displays is on and other 7-segment display is off.
To turn the 7-segment displays off and on there are two pins on
each of the the 7-segment displays which correspond to
common cathode.
If these pins are set to +5V the 7-segment display is on. If these
pins are set to 0V the 7-segment display if off.
S EVEN SEGMENT DISPLAY
I NTERFACING WITH 8051
ORG 0000H
START: SETB P3.0
CLR P3.1
MOV P1, #3FH
SETB P3.1
CLR P3.0
MOV P1, #06H
SJMP START
S TEPPER MOTOR INTERFACING
S TEPPER M OTOR
Stepper Motor :- It is an electromagnetic device which
converts digital pulses into discrete mechanical rotational
movements. In rotary stepper motor the output shaft of
the motor rotates in equal increments in response to train
of input pulses.
Every stepper motor has a permanent magnet rotor,
surrounded by a stator. The most common stepper motor
has four stator windings that are paired with a center
tapped common as shown in the figure below. The rotor is
suspended in the stator by means of sealed ball bearings.
In our case motor is basically with 2 phases, eight salient
poles and toothed iron rotor. The step angel for given
stepper motor is 1.8. The total angel is 360.
No. of steps = 360/ 1.8 = 200 steps/revolution
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
S TEPPER M OTOR
ULN2003A
8051 doesn’t provide enough current to drive the
coils so we need to use a current driver IC that is
ULN2003A. ULN2003A is the array of seven NPN
Darlington transistor pairs. Darlington pair is
constructed by connecting two bipolar transistors
to achieve high current amplification.
In ULN2003A, 7 pins are input pins and 7 pins are
output pins, two pins are for Vcc (power supply)
and Ground. Here we are using four input and four
output pins. We can also use L293D IC in place of
ULN2003A for current amplification.
ADC & DAC 0808
ADC 0808/0809
I NTERFACING ADC 0808/0809
WITH 8051
P IN CONFIGURATION
ALE (Address Latch Enable) & Start
ALE is required to load the selected address lines into
the ADC. Once loaded the multiplexer sends the
appropriate channel to the converter on the chip. The
ALE should be pulsed for at least 100ns in order for
the addresses to get loaded properly.
START (SOC) The purpose of the start signal is two
fold. On the rising edge of the pulse the internal
registers are cleared and on the falling edge of the
pulse the conversion is initiated.
P IN C ONFIGURATION
EOC (End of Conversion signal)
The End of Conversion signal is sent to the FPGA
from the ADC. The signal goes low once a
conversion is initiated by the start signal and
remains low until a conversion is complete.
P IN CONFIGURATION
OE (Output Enable signal )
The Output Enable signal causes the ADC to
actually output the digital values on the output
lines.
In this implementation the OE signal is pulsed
high one clock cycle after the EOC signal goes
high and remains high until the data is safely
stored into the desired register
A LGORITHM
P ROBLEM STATEMENT
Design a microcontroller based system to
interface 8051 with ADC and receive the analog
input from channel 7 and convert it to digital
output and save it in memory location C050H
P ROBLEM STATEMENT
ORG 0000H
ADC0809 Channel Select (A, B, C)
CHANNEL_A0 EQU P2.0 ; A0 (Least Significant Address Bit)
CHANNEL_A1 EQU P2.1 ; A1
CHANNEL_A2 EQU P2.2 ; A2 (Most Significant Address Bit)
ALE_PIN EQU P2.3
ADC0809 Control Signals
OE_PIN EQU P2.4
START_PIN EQU P2.5 ; Signal to initiate conversion (Active High Pulse)
EOC_PIN EQU P2.6 ; End of Conversion (Output from ADC, Input to 8051.
HIGH when done)
P ROBLEM STATEMENT
JMP MAIN
DELAY_SHORT:
NOP ; One NOP is roughly 1 microsecond at 12MHz clock
NOP
RET
ORG 0030H
MAIN:
Initialization and Setup
Set P1 as input port for data from ADC
MOV P1, #0FFH ; P1 must be set high to act as an input port
Setup DPTR to point to the external RAM storage location
MOV DPTR, #0C050H
P ROBLEM STATEMENT
Select Channel 7 (Binary 1 1 1 on A2 A1 A0)
SETB CHANNEL_A0
SETB CHANNEL_A1
SETB CHANNEL_A2
SETB ALE
Generate START Pulse to initiate conversion
CLR START_PIN
ACALL DELAY_SHORT ; Delay
SETB START_PIN
ACALL DELAY_SHORT ; Pulse width
CLR START_PIN
P ROBLEM STATEMENT
Wait for Conversion to Complete (Poll EOC)
WAIT_EOC:
JNB EOC_PIN, WAIT_EOC ; Jump if EOC is Not High (i.e., EOC is still
low)
SETB OE_PIN
Read Data
MOV A, P1
Store Data in External RAM (XRAM)
MOVX @DPTR, A ; Store the digital result in XRAM address C050H
SJMP $
END
P ROBLEM STATEMENT
RS232 SERIAL
COMMUNICATION
8051 provides a transmit channel and a receive
channel of serial communication. The transmit
data pin (TXD) is specified at P3.1, and the
receive data pin (RXD) is at P3.0.
RS means Recommended Standards
It needs driver to use RS232 with 8051
The serial signals provided on these pins are TTL
signal levels and must be boosted and inverted
through a suitable converter(Max232) to comply
with RS232 standard.
D ETAILS OF RS-232
Components of standard:
Connection must be less than 50 feet
Data represented by voltages between +15v and -
15v
25-pin connector, with specific signals such as
data, ground and control assigned to designated
pins
Specifies transmission of characters between,
e.g., a terminal and a modem
RS-232
Transmission voltages are –15V and +15V.
Specifies transmission of characters between, e.g., a
terminal and a modem
It is designed around transmission of characters (of 7
bits of length). Connection must be less than 50 feet
RS-232 communication is dependent on a set timing
speed at which both pieces of hardware communicate.
In other words, the hardware knows how long a bit
should be high or low.
RS-232 also specifies the use of “start” and “stop” bits
RS 232
The RS-232 specification denotes usage of a 25
pin cable, where each pin has a specific usage.
25-pin connector, with specific signals such as data,
ground and control assigned to designated pins
However, most devices never need to use all of
the pins, so the cabling requirements for specific
devices may vary.
Many common serial devices (modems for
example), use a 9 pin serial connection.
RS-232 DB25 P IN O UT
DB-25M Function Abbreviation
Pin #1 Chassis/Frame Ground GND
Pin #2 Transmitted Data TD
Pin #3 Receive Data RD
Pin #4 Request To Send RTS
Pin #5 Clear To Send CTS
Pin #6 Data Set Ready DSR
Pin #7 Signal Ground GND
Pin #8 Data Carrier Detect DCD or CD
Pin #9 Transmit + (Current Loop) TD+
Pin #11 Transmit - (Current Loop) TD-
Pin #18 Receive + (Current Loop) RD+
Pin #20 Data Terminal Ready DTR
Pin #22 Ring Indicator RI
Pin #25 Receive - (Current Loop) RD-
CONNECTOR TYPE
The two different connectors are associated with two
major types of hardware
The Computer Terminal Equipment (CTE) and the
Data Terminal Equipment (DTE).
For ease-of-use, a computer will transmit on pin 2
and receive on pin 3 (the CTE, remember).
Vice versa: a modem will transmit on pin 3, and
receive on pin 2 (for the DTE).
P ROBABLE Q UESTIONS
Draw neat diagram of TCON register of 8051
Write the pin functions RS and Enable of LCD
Explain the pin functions of SOC and EOC pin of ADC 0808
Expalain the SFR registers used in timer operation?
If considered the common cathode configuration what is the
hex code for displaying number ‘1’ on Seven Segment
Display(SSD) ?
If considered the common cathode configuration what is the
hex code for displaying number ‘0’ on Seven Segment
Display(SSD) ?
State the pin functions EOC and ALE of ADC 0808
P ROBABLE Q UESTIONS
Draw pin configuration of ADC 0808 and explain function of all output
pins
Draw interfacing diagram of 8051 microcontroller & stepper motor and
write a program to rotate motor in anti-clockwise direction
Draw interfacing diagram of 8051 microcontroller & stepper motor and
write a program to rotate motor in clockwise direction
Write 8051 based assembly Program to generate to make LED ON and
OFF connected to P1.7 continuously ON time 30ms and off time 40ms
Design a 8051 microcontroller-based system to interface 4 seven
segment to display 1234
Interface 8 LED's with port 1.0 and P1.1 of 8051 and write an assembly
language program to flash alternate LED's after every 1 sec
Draw the pin configuration of LCD and explain the function of Data and
Command register
P ROBABLE Q UESTIONS
Design a 8051 microcontroller-based system to interface 4 seven segment display
and write an assembly language program display 1234 on it
Interface 16*2 LCD to 8051 through Port 2 and Port 3 and write an assembly
language programme to display YES message on the display
Write 8051 based assembly Program to generate a square wave on P 1.0 of 2Khz
frequency and 70% duty cycle. Assume crystal frequency 12MHZ
Interface 16*2 LCD to 8051 microcontroller through Port 1 and Port 3 and write an
assembly language program to display “NO” message on the display
Draw the interfacing diagram of ADC 0808 and 8051 microcontroller and write an
assembly language program to receive analog input from channel 5 and convert it
in digital form
Draw the interfacing diagram of ADC 0808 and 8051 microcontroller and write an
assembly language program to receive analog input from channel 3 and convert it
in digital form
Draw the interfacing diagaram of DAC 0808 and 8051 microcontroller and write an
assembly language program to generate square wave