8051 Interfacing
8051 Interfacing
External Devices
Contents
8255 - PPI
LED
7-segment display
LCD
Keyboard matrix
Stepper motor
DC motor
ADC
DAC
Programmable Peripheral
Interface(PPI)
Programmable Peripheral Interface
(PPI) devices are used for
extending the I/O capabilities of processors/controllers.
8255A is a popular PPI device for 8 bit processors/controllers.
8255A supports 24 I/O pins and these I/O pins can be grouped as either
three 8-bit parallel ports (Port A, Port B and Port C) or two 8 bit parallel
ports (Port A and Port B) with Port C in any one of the following
configuration.
As 8 individual I/O pins.
Two 4bit Ports namely Port CUPPER (CU) and Port CLOWER (CL).
The Configuration of ports is done through the Control Register of
8255A.
Programmable Peripheral
Interface(PPI)
Programmable Peripheral
Interface(PPI)
For example, write the CW to program port C PC.5 of 8255 as input pin.
LED
LED is a p-n junction diode and it contains a anode and a cathode. For
functioning of the LED, the anode of it should be connected to +ve
terminal of the supply voltage and cathode to the ve terminal of supply
voltage.
The current flowing through the LED must be limited to a value below
the maximum current that it can conduct. A resister is used in series
between the power supply and the resistor to limit the current through
the LED.
LED
In the second case cathode of LED is connected to port pin and anode to
power supply. Whenever port pin is in low state, LED glows.
In first case brightness will not be as per the requirement. But in second
case brightness can be obtained as per the requirement.
The LED segments are named A to G and the decimal point LED
segment is named as DP.
10
11
The current flow through each of the LED segments should be limited to
the maximum value supported by the LED display unit
12
ORG 8000H
MOV P1,#0FFH
LOOP: JNB P1.2, L1
MOV A,#06H
MOV P2,A
SJMP LOOP
L1: MOV A,#3FH
MOV P2,A
SJMP LOOP
13
LCD
14
LCD
Pin Description for LCD
15
LCD
Command Codes for LCD
LCD
16
Write a program to display MMC course on the LCD connected to 8051 MC. Note the following: P1.1 en pin,
P1.2
RS
pin,
P1.3
R/W
pin
and
port
2
data
pins
of
LCD.
17
ORG 8000H
RPT:MOV DPTR,#CMD
ACALL L1
MOV DPTR,#MSG
ACALL L2
SJMP RPT
L1: MOVC A,@A+DPTR
JZ EXIT
INC DPTR
MOV P1,#04H
MOV P2,A
MOV P1,#01H
ACALL DELAY
MOV P1,#00H
JZ EXIT
SJMP L2
INC DPTR
EXIT: RET
MOV P1,#00H
MOV P2,A
MOV P1,#01H
ACALL DELAY
DJNZ R0, GO
MOV P1,#00H
RET
SJMP L1
ORG 9800H
EXIT: RET
CMD: DB 01H,06H,02H,0EH,85H,0
MSG: DB MMC COURSE, 0
END
18
It differs from the normal dc motor in its operation. The dc motor produces continuous
rotation on applying dc voltage whereas a stepper motor produces discrete rotation in
response to the dc voltage applied to it.
The stepping of stepper motor can be implemented in different ways by changing the
sequence of activation of the stator windings.
o Full step
o Wave step
o Half step
Microcontroller lab, Dept. of E&C.
19
20
21
Store the hex equivalent codes for energizing the windings as a LUT.
Get every code from the table and give it to the motor through Port with
some delays to observe motor rotation.
ORG E000H
HERE: MOV DPTR, #TABLE
ACALL SEND
SJMP HERE
SEND: CLR A
MOVC A,@A+DPTR
JZ EXIT
INC DPTR
MOV P2,A
LCALL DELAY
SJMP SEND
EXIT: RET
DELAY: MOV R0, #F7H
REPEAT: MOV R1, #FFH
GO: DJNZ R1, GO
DJNZ R0, REPEAT
RET
ORG EE00H
TABLE: DB 0DH, 0EH, 07H, 0BH, 0
END
Microcontroller lab, Dept. of E&C.
23
Motors DC Motor
Reversing the polarity, the DC motor will move in the opposite direction.
24
Motors DC Motor
Although the voltage has a fixed amplitude, it has a variable duty cycle.
That means wider the pulse, higher is the speed.
25
CLR P1.2
ACALL DELAY
SJMP BACK
L1: SETB P1.2
ACALL DELAY
ACALL DELAY
CLR P1.2
ACALL DELAY
SJMP L1
Microcontroller lab, Dept. of E&C.
26
Keyboard
Keyboard
27
ADC
28
When sensors collect data, it will be in analog form and the MC cannot
process analog data. Hence an ADC is used to convert such data and
then given to the MC.
SOC
OE
EOC
Analog input
ADC
29
Write a program to interface an ADC with 8051 and read the digital data from ADC and store it in location
40h. Note that SOCP1.2 EOCP2.1 OEP1.4 digital data P3.
30
ORG 8000H
MOV R0,#40H
BACK: SETB P1.2
ACALL DELAY
CLR P1.2
L1:MOV A, P2
JNB ACC.1,L1
SETB P1.4
ACALL DELAY
MOV A,P3
MOV @R0,A
CLR P1.4
INC R0
SJMP BACK
END
Microcontroller lab, Dept. of E&C.
31
DAC