Vous êtes sur la page 1sur 6

91

Chapter12
Interfaceexamples
Solutions to THINK AND ANSWER Exercises
1. Explain the interfacing of four seven-segment LED displays with the 8051, using the
multiplexed display concept.


IC 8279 is a programmable keyboard and display interface controller, that can be used for
interfacing multiplexed display with the 8051 microcontroller. Figure shows the interfacing of
sevensegment LEDs with the 8051 using the 8279. The lines A0 A3 and B0 B3 of 8279 are
used to give the display data to the devices. The scan lines, SL0 and SL1 are used to select a
display device among the four. The sevensegment displays are all common anode type and a
transistordriverisusedwitheachdisplaydevice.Alogiclowisrequiredtoturnonthetransistor
driver;itisgeneratedusingthedecoderIC.CommondecoderICssuchasIC74138canbeused
as these ICs can give an active low signal on any of their outputs. The segments of the display
devicesareallconnectedtogetheronacommonbusandconnectedtotheA0A3andB0B3
outputs of the 8279. As the displays are all of common anode type, the data output for
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
92
illuminatingtheLEDsmustbelogiclow.Thismeansthatalogic1inthedatalinesA0A3and
B0 B3 blanks the display and a logic 0 displays all the segments. 8279 uses two addresses
selectedbyA0addressinputto8279.
Theprogramfordisplayingthedatatothesevensegmentdisplaythrough8279isgivenbelow.
Label Mnemonics Comments
MOVDPTR,
#COMMAND_PORT
;Loadthecommandportaddressof8279todata
pointer
START: MOVA,#00H ;Loadthemodesetcommandwordinthe
accumulator.
MOVX@DPTR,A ;Outputittothecommandport.
MOVA,#0C0H ;Loadthecleardisplaycommandwordinthe
accumulator.
MOVX@DPTR,A ;Outputittothecommandport.
MOVA,#90H ;LoadthewritedisplayRAMcommandwordinthe
accumulator.
MOVX@DPTR,A ;Outputittothecommandport.
MOVDPTR,#DATA_PORT ;Loadthedataportaddressof8279todatapointer
MOVA,#DATA1 ;Loadthefirstdataintheaccumulator.
MOVX@DPTR,A ;Outputittothesevensegmentdisplay.
MOVA,#DATA2 ;Loadtheseconddataintheaccumulator.
MOVX@DPTR,A ;Outputittothesevensegmentdisplay.
MOVA,#DATA3 ;Loadthethirddataintheaccumulator.
MOVX@DPTR,A ;Outputittothesevensegmentdisplay.
MOVA,#DATA4 ;Loadthefourthdataintheaccumulator.
MOVX@DPTR,A ;Outputittothesevensegmentdisplay.
;endofdisplayinterfaceprogram.


Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
93
2. Interface an ADC chip and an intelligent LCD with the 8051. Explain the algorithm
needed to read data from the ADC and display it in the LCD.



START: MOV A,#01H
; Load the control word to clear the display in the LCD.
CALL COMMAND
; Call the subroutine to issue this command to the LCD.
MOV A, #0EH
; Load the control word to initialize the cursor to
home position, and switch on the display and the
cursor.
CALL COMMAND
; Call the subroutine to issue this command to the LCD.
MOV DPTR, #9000H
; Initialize the memory pointer.
MOV R0, #0FH
; Initialize the counter for the number of characters to
display.
NEXT: MOVX A, @DPTR
; Load the display data in the accumulator.
CALL DISP
; Call the subroutine to issue this data to the LCD.
INC DPTR
; Point to the next data for display.
DJNZ R0, NEXT
; Decrement the count for the number of data to be
displayed. If it is not zero, loop again.




COMMAND: MOV P1,A
; Give the control word to the data lines of the LCD
CLR P2.2
; RS =0 (command)
CLR P2.1
; R/W =0 (write)
SETB P2.0
; E =1 (apply a high pulse)
CLR P2.0
; E =0 (apply a low to E, so that there will be a H-to-L
pulse)
CALL DELAY
; Wait for a predefined time delay
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
94
RET
; Return from subroutine




DISP: MOV P1,A
; Give the data to the data lines of the LCD.
SETB P2.2
; RS =1 (data)
CLR P2.1
; R/W =0 (write)
SETB P2.0
; E =1 (apply a high pulse)
CLR P2.0
; E =0 (apply a low to E, so that there will be a H-to-L
pulse)
CALL DELAY
; Wait for predefined time delay
RET
; Return from subroutine.




DELAY: MOV R1, #COUNT1
; Load a register with a count value, COUNT1.
LOOP1: MOV R2, #COUNT2
; Load another register with a count value, COUNT2,
for more delay.
LOOP2: DJNZ R2, LOOP2
; Decrement it.
DJNZ R3, LOOP1
; Decrement until the required time delay is obtained.
RET
; When the required time delay has been produced,
return from subroutine.

3. Interface a DC motor and two switches with the 8051 and explain the software needed for
controlling the direction of the DC motor using the switches.


Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
95
Mode Pin A/ P1.1 /P2.0 Pin B/ P1.0 / P2.1 Motor
0 0 0 Off
1 0 1 (5 V) Reverse
2 1 (5 V) 0 Forward
3 1 (5 V) 1 (5 V) Off

START: MOV C,P2.0
;Load the P2.0 contents to carry flag
MOV P1.0,C
;Give the data in carry flag to P1.0 for motor
MOV C, P2.1
;Load the P2.1 contents to carry flag
MOV P1.1,C
;Give the data in carry flag to P1.1 for motor

The interfacing of the DC motor that can be driven bidirectional is given above. The port pins
P1.0 and P1.1 will control the direction of the motor as given in the table. The switches are
interfaced in the port pins P2.0 and P2.1. The program for driving the motor is given which
just reads the data on the Port 2 pins and outputs it on port 1 pins. Remember that if both the
input pins are at logic 0, the motor will not rotate. Similarly, if both the input pins are at logic
1, then also the motor will not rotate. If P2.0 is 1 and P2.1 is 0, then the motor will rotate in a
particular direction. The motor direction is reversed if P2.0 is 0 and P2.1 is 1.

Solutions to NUMERICAL/DESIGN-BASED EXERCISES
1. Design a microcontroller-based system for a weighing machine.
[Hint: Use a load cell or any other suitable transducer, instead of a thermistor, in the
example discussed in section 12.12.]
2. Design a microcontroller-based controller for turning on and off the lights in a building,
based on the movement of people in the building.
[Hint: Use an IR sensor to detect persons in the building and accordingly either turn on or
turn off the light, as done in the traffic light control example.]

Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan


Oxford University Press 2011
96

Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan


Oxford University Press 2011