MAA UNIT 4
MAA UNIT 4
4 8051 Interfacing
Syllabus:
LED, LCD, SevenSegment display.
4.1 /OInterfacing: Keyboard, Relays.
80O51 Simple programs for ADCintertacing.
2ntertacing ADC 0808/09 with
programs for DAC intertacing.
Intertacing DAC 0808/09 with 8051, Simple
.3
4.4 Memory Interfacing: Program and Data Memory.
rows.
While designing the 8051 microcontroller based the keyboard
system, we have to expand the I/0 ports as Port 0 The nibble driven onto the columns always contains
and Port 2 are used to interface external memory. only a single 0.
any row pin is
The I/0 devices such as LED, relays, keyboard, LCD, The microcontroller can find a 0 on
Seven Segment Display, stepper motor can be for the keyboard keys to be pressed that connects
a row.
interfaced using port pins of 8051 Microcontroller. the column set to 0 to
The controller knows which column is ata 0 level and
4.1.1 4 x 4 Matrix Keyboard which row reads 0, which determine which kev
is
R2
7 8 9
R3
E D
R4
Fig. 4.1.1: 4 x 4
Matrix Keyboard RÀ
Pa
The keyboard consists of a number of keys i.e.
Switches, connected in a matrix form i.e. row and
column arrangement as shown in Fig. 4.1.1.
a
In order to scan the keyboard, microcontroller makes
one of the columns low and then reads the rows to see
if any keys in that column have been pressed.
The rows are pulled up by resistance in the 8051ports.
Fig.4.1.2: Interfacing of 4 x 4 matrix
keyboard with 8051 microcontroller
<br>
If it is,then the key at the junction between the current No All keyS
row and column being scanned is the pressed key. open?
Yes
Start.
Make All Pins High
Read all columns
Clear row 1, set other 3
Scan column 1, if column 1 is low then 0' key is No All
keys
pressed. open?
Scan column 2, if column 2 is low then (1' key is Yes
pressed. Wait for debounoe
Scan column 3, if column 3 is low then 2' key is
Bead all columns
pressed.
Scan column 4, if column 4 is low then '3' key is NC
Any keys
pressed. down?
Yes
Clear row 2, set other 3
Scan column 1, if column 1
is low then '4' key is
pressed. Ground next row
Scan column 2, if column 2 is low then '5 key is
Read all colunns
pressed.
Scan column 3, if column 3 is low then '6 key is No Key press
pressed. in this row?
Scan column 4, if column 4 is low then '7' key is Yes
pressed. Find which key is pressed
8051 Interfacing
Microcontroller and Applications 4-3
4.1.1 (D) Program CLR PRESSED ;reset the flag
JB COL1, NEXTCOL
check if first key is pressed
KEYPORT EQU P3
4x4 keyboard port
JNB COL1,$ ;if yes then wait for
connected to port 3
;key release
LEDPORT EQU P2
; LED connected to PORT 2
COL1 EQU P3.0 SETB PRESSED
; set the flag
1
column
COL2 EQU P3.1
column 2
;
RET
COL3 EQU P3.2 read col2
column 3 NEXTCOL:
COL4 EQU P3.3
column 4 JB COL2, NEXTCOL1
;
checkifsecond key is
KEYVALEQU 30H
to store key number ;pressed
PRESSED BIT OH
flag
JNB COL2,$ ;if yesthen wait for key
KEY_INIT:
MOV KEYPORT,#0FH ;release
make rows as
;
0/P and
; column as I/P INC KEYVAL ;its key number 2
RET ;
SETBPRESSED set the flag
GET KEY:
RET
MOV KEYVAL,#0
;reset the number
MOV KEYPORT,#7FH NEXTCOL1: ; read col3
;make row1 low
ACALL READ_COL read columns JB COL3, NEXTCOL2 ;check if third key is pressed
JB PRESSED, DONE ;check if flag is set
JNBCOL3,$ ;if yes then wait for key release
MOV KEYVAL,#4 ;if not then read next row INC KEYVAL ;its key3
MOV KEYPORT,#OBFH ;make row2 low
INC KEYVAL
ACALL READ_COL ;read columns
JB PRESSED,DONE ;check if flag is set
SETB PRESSED :set the flag
MOV KEYVAL,#8 RET
if not then read nextrow
MOV KEYPORT,#ODFH NEXTCOL2: ;read column 4
;make row3 low
ACALL READ_COL JB COL4, EXIT ;check if fourth key
;read columns pressed
JB PRESSED,DONE check if flag is set JNB COL4,S ;ifyes then wait for key release
MOV KEYVAL,#12 ;ifnot read row4 INC KEYVAL its key 4
MOV KEYPORT,#OEFH ;make row4 low INC KEYVAL
ACALL READ_COL ;
read columns
INC KEYVAL
JB PRESSED, DONE ;check if flag is set
SETB PRESSED ; set the flag
DONE:
RET
MOV A, KEYVAL ;display keys pressed
EXIT:
if nokey is pressed
on LED CLR PRESSED
;clrthe flag
MOV LEDPORT, A
CLR KEYVAL
reset the number
RET
RET
READ_COL: read columns routine
END
Tech Knowledge
Pubiications
<br>
interfacing diagram showing 4 x 4 matrix that connects the column set to 0 to a row.
. Draw
vovboard connections to Port 2 and Port 1 of 8051 The controller knows which column is at a 0-level
mícrocontroller. Draw fiowchart to detect
a
pressed and which row reads 0, allowing it to determine
key. W-15, 6 Marks
which key is pressed.
Kevpads are often used as a primary input device For the keypad, the pins from left to right are: R1,
for embedded microcontrollers. R2, R3, R4, C1,C2, C3, C4.
45V
Vee
P1.3
P1.2
P11
P1.0
C3
R'
8051 P2.3
R
R2
92.2
R2
R3
TAL: P2.1
R2
R4
HO
P2.0
C2 R4
TAL2
Teck Knouledge
Publications
<br>
8051 Interfacing
Microcontroller and Applications 4-5
open?
Yes or some relays may operates with 50mA current to
Wait for debounce excite the inductor coil.
But the current sinking capability of each port pin of
Read all columns
8051 is 20mA.
No
Any keys So whenever 70mA current flow through the nort
down?
Yes pin may harm that particular port pin.
So, large current sinker is required to avoid this
problem.
Ground next row
Hence, to drive the relay with 8051 microcontroller.
Read all columns ULN2003/ULN2803 driver can be used.
No
A
driver has 500mA current sinking capacity
ULN
Key pre ss
in this row? for each output pin, hence 8051 microcontroller is
Yes interfaced with relay via ULN driver which will not
Find which key is pressed damage the microcontroller port pin.
Fig. 4.1.5 shows the interfacing relay with 8051
Get code from lookup tabie
microcontroller to make bulb ON or OFF.
End IN1 pin of ULN2803 is connected to Port 2 pin i.e.
Flowchart 2 P2.0of 8051 microcontroller.
+5V +5V
(Bub
C1
XTAL1 1
| in Out 1
P20
Cystal XTAL2 in 2 out 2
+12 V
33p in 3 out 3
R1 in 4
RST 8051 out 4
8k2 C3 in 5 |out 5
ULN2803
T10u EA in 6
out 6
in 7 Out 7
in 8
Out 8
GND
COM
+5V
Fig. 4.1.5: Interfacing of Relay with 8051
Tech Knowledge
Pubiicatiens
<br>
Microcontroller.and Applications
4-6 8051 Interfacing
Program
4.1.3 Interfacing of LED (Light Emitting
NEXT:
Diode) with 8051
SETB P2.0 ;Make Relay ON
SETB PI.0 Mostly used LEDs have voltage drop of 1.7v and
MOVR5 #55 current of 10mA to glow at full intensity.
ACALL DELAY
LED can be connected to any port pin of 8051.
CLRP1.0 LED is
A
connected to P1.0 of 8051, as shown in
MOV R5, #55
Fig. 4.1.8.
ACALL DELAY
SIMP MAIN
XTAL1
DELAY:
Cystal XTAL2
MOV R4, #100
H2
MOV R3, #253
RST
DJNZ R3, H3 8051
EA
DJNZ R4, H2
DINZ R5, H1
P10
RET
END
Fig. 4.1.8 : LED Connected to 8051
TechKnouledge
Publicatiens
<br>
AL $2
Crystal XTALE
P20 XTALI
8051 P21
RÍ P22
RST 13.0882
P2
P2.
MaTL3
E P2
R2.6 LEDS
LEDZ
:
Fig. 4.1.9 Interfacing of Eight LEDs with Port 2 of 8051
Progranm
UP: MOV A, #00H Load A with 00 to make LED OFF
MOV A, #10H
ACALL Delay ;Wait for some time
MOV P2,A
;Make LEDO ON
SJMP UP
ACALL Delay
:Wait for 20 ms
Tech Knowledge
Pubiications
<br>
MOVP2, A
Make LED1 ON
MOV A, #40H
MOV P2,A Make LED2 ON"
d
comC dot
ACALL Delay Wait for 20 ms
Fig. 4.1.11 : Seven Segment LED
SJMP NEXT
The common digit patterns of a seven segment
CJNE A, #OF7H, DN4
DN3
display are shown in the Table 4.1.3.
MOV A, #80H Table 4.1.3: Code for Digit
MOV P2, A Make LED3 ON
Pins of Seven Segment Display Hex
ACALL Delay Wait for 20 ms |Digit
dp e C b Code
DN4: SJMP NEXT
0 1 1
CO
4.1.5 Seven Segment Display 1 1 1 1 1 1 1 P9
Now we will see how to interface a seven segment 2 1 1 1
0 A4
LED display to an 8051 microcontroller using 8255.
3 1 1 1
BO
Seven segment LED display mostly used in many
industrial applications and can display digits from 0 4 1 1 1 0 1 99
to 9 and few characters like A, B, C, D etc. 5 1
1 1
92
A seven segment display consists of seven LEDs
6 1 1
0 82
organized in the form of a squarish '8 inclined to
the right and a single LED as the dot character. 7 1 1 1 1 1
0 F8
Different characters can be displayed by making ON 8 1
80
the required LED segments.
9 1
0 1
0 0 90
Seven segment displays are of twO types, common
cathode and common anode. 4.1.5(A) Interfacing Seven Segment Display
In common cathode type, the cathode of all LEDs to 8051
are connected together to a single terminal which is
Draw the interfacing diagram of seven segment display
usually labeled as 'COM and the anode of all LEDS
are left open as individual pins labeled as a, b, c, d, e, to8051 microcontroller. W-14, W-15,6 Marks
Tech Knouledge
PubiiCatipns
<br>
33p XTAL1
P212w segment LED display
Status of Pins of Seven Segment Display Hex
R5
ystal C2
H XTAL2
P22W R6
Digit
for 'g
Code
8051 P234
R1
dp e C b
RST
Bk2 RT
P2.4Pw
10ur EA
R8 1 0 1
90
P2.5Dww h
Com
R9 Assume the Digit code for 'g is stored in internal
P26w
R10 RAM location 40H.
P27ww
MOV R2, #40HMemory pointer to point
Fig. 4.1.12 : Interfacing
of Seven g
code
Segment LED to Port 2 of 8051
The common cathode seven segment NEXT: MOV A, @R2 ; Load A reg. with digit
display is
connected to the Port 2 of the microcontroller 8051 code of 'g
and R3 to R10are current limiting resistors.
Assume the Digit code are stored in internal Ram
MOV P2, A Send to Port 2 of 8051
from 40H onward, So we will initialize memory ACALL Delay Wait for 1
Sec
pointer using R2 register to read digit code.
SJMP NEXT Send continuously
Program 1:
NEXT: MOV R1, #0AH; Counter to display digit 4.1.5(B) Interfacing Multiplexed 7 Segment
MOV R2, Display with 8051 (4 Digit)
#40H: Memory pointer
Tech Knowiedge
Puniicatiens
<br>
of time.
Thus this cycle must be repeated to achieve a
fast
rate and due to the persistence of vision of human
eye, all digits seems to glow. DISP4
Transistor Q1 drives the first display (DISP1), 4.1.6 LCD (Liquid Crystal Display)
transistor Q2 drives the second display (DISP2),
Transistor Q3 drives the third display (DISP3) and 4.1.6(A) Basics of LCD
transistor Q4 drives the fourth display (DISP4). x 2
Draw interfacing of
16 LCD with 8051 and state
R9 to R12 are the base current limiting resistors of the function of EN and RS pin of
LCD. W-19, 4 Marks
Q1 to Q4.
The LCD Display can be simply connected with an
Suppose we want to display 1 on DISP1, '2' on 8051 microcontroller and can be used in digital
DISP2,'3' on DISP3 and '4' on DISP4. device like digital voltmeter / ammeter, digital
So according to concept of multiplexing we must put clock, home automation displays, status indicator
data corresponding to digit 1, when only DISP1 is display, digital code locks, digital speedometer/
enable. odometer, display for music players etc.
Enable DISP1 by applying a high pulse on base of Q1 2 x 16 LCD is a very common type of LCD display
at DISP1, now put the hex data corresponding to that is used in 8051 based embedded systems and is
Digit 1 on the data lines that is Port0. shown in Fig. 4.1.14.
Tech Knowledge
Puhiications
<br>
8051 Interfacing Mi
Microcontroller and Applications 4-11
4
abcdeshiiklmnor Note
X = Don't care
Fig. 4.1.14 : LCD Character 2 x 16 Module DL : Sets interface data length.
DL = 1, Data is sent or received in 8
bit 5.
2 x 16 LCD display consists of 16 rows and -
length (DB7 DBO)
2
columns of 5 x 7 or 5 x 8 LCD dot matrices. DL = 0, Data is sent or received in 4 bit
It is available in a 16-pin package with back light, (DB7 - DB4)
length
contrast adjustment function and each dot matrix coe
When the 4 bit length is selected, data must be
has 5 x 8 dot resolution.
or received twice.
The pins on the 16-pin connector of the LCD Module
are given below 2
Entry Mode Set
No
PIN Sets the increment/ Decrement and Shift modes
Name Function
the desired settings
1 VSS Ground voltage RS
R/W DB7 DB6| DB5 DB4| DB3 DB2DB1 DR0
2 VCC +5V
0 0 0 0 0 1 I/D
3 VEE Contrast voltage
I/D: Increment/ Decrement the DDRAM address by
4 RS Register Select 0 = Instruction 1 whena character code is written into or read from the
Register,
DDRAM.
1= Data Register
I/D ="0", Decrement
L
5 R/W Read/ Write, to choose write or read
= "1",
mode 0 write mode 1 = read mode
=
I/D Increment
6 EN Enable: 0 = start to latch data to LCD
S :
Shift the entire display either to the right or to left.
1 = =
character, disable S 1, shift toright or left depend on I/D
7 DBO LSB of Data S = 0, display does not shift
DB1 3. Display On/ Off Cursor
9 DB2 Controls the display ON/OFF status, cursor ON/0FF
and Cursor Blink function
10 DB3
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Se
11 DB4
0 0 0 0 1 D C B
12 DB5
13 DB6
D: Controlling display
D = 1, Display is ON
14 DB7 MSB of Data D
=0, Display is 0FF
15 BPL Back Plane Light In this case display data remains in the DDRAM. It
can be displayed
16 GND Ground voltage immediately by setting D=1.
C: Display cursor
4.1.6(B) LCD Initialization
C= 1, Cursor is Displayed
1. Function Set C = 0, Cursor does not display
Sets the interface data length, the number of lines,
and character font
B: The character indicated by the
cursor blinks when B = 1
Tech Knowledge
P9llcation5
<br>
Display
Clear Command Function
execution of clear display instruction sets entry
The OF For switching on LCD, blinking the
mode
mode to increment cursor.
DB7 DB6 DB5 DB4 DB3 DB2 DB1 DBO
RSRW 1
Clearing the screen
0 0 0 1
0
0 2 Return home.
Shift Decrement cursor
t Cursor of Display 4
1 1 Shift the entire display to the right 0C1 Jump to second line position1
8051 Interfacing
Microcontroller and Applications 4-13
;Enable H>L
4.1.6(D) Initializing and sending Data to the CHECK: SETBP3.3
LCD_DATA
BACK:
SETB P3.4 ;Set RS bít to 1 i.e. select MOV R6,#FFH
data register
CLR P3,2 Write Data to LCD DJNZ R6,S
Tech Knowledge
PubiIcatiens
<br>
8051 Interfacing
Microcontroller and Applications 4-14
#OFH
AMOVA, ACALL LCD_BUSY
LCD_COMMAND
ACALL RET
BUSY LCD COMMAND:
CALL LCD
;
Entry mode, set increment ;Clear RS bit i.e. Select command
MOVA, #06H CLR P3.4
LCD_COMMAND 3 register
ACALL
ACALL
LCD_BUSY CLR P3.2 ;Write command to LCD
MOV P1, A ;Command code is in Accumulator
RET
SETB P3.3
41.6(E) Program to display "WELCOME" to CLR P3.3 High to Low pulse on EN to latch
LCD the data
"WELCOME" are LCD finishes its ínternal
Assume the eight characters the CALL LCD BUSY
to 37H.
stored in memory locationstarts from 30H
operations
memory
So, in this program we read character from RET
and send it to LCD. LCD BUSY:
MOV R1, #30H Initialize memory pointer CLR P3,4 Select command register
ACALL INIT LCD ; Initialize LCD i.e, 8-bit,2 Line, Reading Enable
SETB P3.2
Dots Cursor blinking, P3.3 Enable H->L
5x7 CHECK: SETB
NEXT: MOVA, @R1 Read Character from memory JB P1.7, CHECK Read busy flag again and again
if0 then go to NEXT SETB P3.4 Set RSbit to 1 ie. select data
8051
Interfacing
Microcontroller and Applications 4-15
x;
4.1.6(F) Interfacing 20 x 4 LCD with 8051 Although the program written for the 16 2 display
x 4 LCD display
can be used with the 16 beside we
The 20 x 4 LCD displays 4 lines of 20 characters can only display on the first two lines only.
each as shown in Fig. 4.1.16. There are separate commands
for setting
the cursor
to the required line in these displays and used to set
cursor at
the line address and place the
appropriate line.
Now commands are given below, the line addrecear:
for the 16 x 4/20x 4 LCD display,
1. display the characters on the 15t line send
To
the command 0 x 80
Fig. 4.1.16 : 20 x 4 LCD Display
2. To display the characters on the 2nd line send
There is no any difference in interfacing the the command 0 CO
>x
The Fig. 4.1.17 shows the interfacing of a 20 x 4 LCD module with 8051 microcontroller.
20 x 4 LCD Display
EA
P3.5
P3,4 +5V
RST
P3.3
8051
Microontroller
P10
P1.]
P12
Pi.3
XTAL1
P1.4
P1.5
P1.6
MHz
L211.0592 XTAL2GND
P17
Tech Knowledge
Publcatibns
<br>
1
instead of polling for EOC just put some delay, so
IN1
instead of 15 lines we will require 13 lines.
IN2 0 1
We can also provide the clock through the controller
IN3 0 1 1 thus eliminating the need of external circuit for
clock.
IN4 1 0
But using all signals, the interfacing of ADC 0808
IN5 1 0 1
with 8051 microcontroller is shown in Fig. 4.2.2
IN6 1 1 where Port P2 is used read data by connecting it to
ADC0808 data bus.
IN7 1 1 1
Tech Knowledge
Publications
<br>
8051 Interfacing
Microcontroller and Applications 4-17
5V supply Ground
Vcc GND
P2.5 DB5
+5V NcG ADC
P2.4 DB4 0809
P2.3 DB3 10808
EA
P2.2 DB2
P2.1 DB1
st P2.0 DBO LSB
RST A
ADO
P12
P13 BAD1
Rg AD
8.2K
P14
Low-High transition
ADC_ DATA
SAR. BIT P2
ADD_ A
BIT
5. A High Low transition on ALE, P1,2
Tech Knowledge
Publlcalions
<br>
REPT: 7 A3 A6 10
JNB ADC EOC, REPT 8A4 A59
SETB ADc OE ; Make available converted
Fig. 4.3.1: Pinout of DAC0808
data on D0-D7
ACALL DELAY, Wait for some time
The output of DAC is in the form of current, but we
need voltage as a output, so, current to voltage
MOV A, ADC DATA; Read binary data from DO-D7 converted is used.
of ADC 0808
Calculation of Io i.e. Lour and Vo i.e. Vour
on LCD
ACALL DISPLAYDisplay data lo= K
128 256
SJMP NEXT
VREE
Where, K= Ra
4.3 Interfacing of DAC 0808 with 8051
Vo = Re x I,
DAC to 8051.
Draw and explain the interfacing
of
- A3 Ag As A6 A7 As
S-19, W-19, 4 Marks Rk16*32 64128* 256
Q Draw the interfacing diagram of DAC with 8051
microcontroller. Write an ALP to generate a square
waveform. S-22, 4 Marks
Tech Knouwledge
Puhlltations
<br>
8051 Interfacing
Microcontroller and Applications 4-19
+5V
EA VoG
+5V
8051
Microcontroller Voc R14
PO.4 A5
Iout
PO.5 A6
PO.6 A7 Vout
PO.7 A8 Comp
XTAL 1
15pF
+12V
i1.0592MHiz
XTAL2
GND
Simple Programming in Assembly Language Program 2: Write a program to generate a Stair Step
Voltage from DAC 0808 with stair step voltage from 0 volt
Program 1: Write a program to generate a voltage 2
volt from DAC0808. Assume Vref =5 volt, R,, =5 k. and trough 5 volt, with resolution 0.5 volt each step using LOOK
UP R = 5k.
Table. Assume Vef=5volt, Ry4=5 k, and
R,= 5k.
Soln.: Soln.:
With reference to figure shown in Fig.4.3.2, first we With reference to figure shown in Fig. 4.3.2, first we
have to find out the binary value to generate voltage of have to find out the binary value to generate steps of
2 volt from DAC 0808 as shown. voltage of 1 volt from 0 volt to 5 volt as shown below.
K = Vret/ Ri4 =
5/5k =1 mA K = Vef/ Rq4 = 5/5k = 1 mA
If, we put logic high into A1 through A8 then we
If, we put logic high into A1 through A8 then we have:
have:
I, = 1mA x 0.99 =1 mA I, = 1mA x 0.99 =1 mA
So, So,
Vo = L, x
R=1 mA 5k= 5 voltx
Vo = , x R,= 1 mA x 5k= 5 volt
= =
Voltage Resolution 5/255 0.02 volt =
Voltage Resolution 5/255 = 0.02 volt
If you like to send 2 volt out from your
a DAC, than
you must the value in binary or decimal So, the steps voltages are calculated below.
1. =
Value = 2/0.02 = 100 decimal (64H) Voltage 0 volt 0/0.02 =0 decimal or HEX
Program 2. Voltage 0.5 volt = 0.5/0.02 =
25 decimal or 19H
3 Voltage 1 volt = =
START: MOV A,#100Load value in A
register 1/0.02 50 decimal or 32H
4. Voltage 1.5 volt =
1.5/0.02 =75 decimal or 4BH
MOV PO,A Send it to DAC 0808 to generate
5 =
Voltage 2 volt 2/0.02 = 100 decimal or 64H
voltage of2 volt
6. Voltage 2.5 volt = =
2.5/0.02 125 decimal or 7DH
SJMP START Continuously
Tech Knowledge
Publications
<br>
Microcontrollerrand Applications
4-20 8051 Interfacing
=
Voltage 3 volt 3 /0.02 150 decimal or 96H DELI: MOV R2,#255
=
Voltage 3.5i volt 3.5/0.02 175 decimal or AFH
DEL2: DJNZ R2, DEL2
=
Vooltage 4 volt 4/0.02 200 decimal or C8H
=
; case wave
ELAY: UP1: MOV PO, R1 ;Start falling edge of triangular
MV RO, #0
ELAY1: MOV R2, #0FH wave
ACALL DELAY Add appropriate delay
DJNZ R2, $
DJNZ RO, DELAY1 DEC R1
ACALL DELAY
and used to accept different kinds of signals.
Add appropriate delay
2. Basically each and every memory device has pins
INC R1 Set next value for rising edge
for address, data, control signals and chip select
CJNE R1, #FFH, UP If not max peak of Saw Tooth signals.
;wave then UP
Address pins
UP1: SJMP START ;
Start falling edge of Saw Address pins are used to read address of the
;Tooth wave memory location from the system address bus
;Continuous Saw Tooth wave transmitted by the microcontroller.
DELAY: MOV R1, #255;subroutine to add delay The numbers of address pins on the memory device
DEL1: MOV R2, #255 is depending on the size of the memory as shown in
2 4
4.4.1 Introduction 3 8
Memory is the storage device which is used to store 4 16
monitor program, userS program or users data. 5 32
So memory is the important element of the
6 64
microcontroller based system, which will allow to
7
store program and data. 128
8 256
The memory consists of the numbers of memory
cells arranged to store data. 512
Each memory cell is used to store1 bit of
the data. 10 1024 1k
Hence, memory must be interfaced with 11 2048 2k
microcontroller to store programs or data of user or 12 4096 ~ 4k
system, so that it can be accessed while reading or
13 8192 8k
writing data or program from/to it.
14 16384 16k
Access time of the memory chip is commonly
15 32768
referred to speed of the memory. 32k
16 65536 64k
4.4.2 Semiconductor Memory 17 131072 128k
Tech Knouwledge
Publlcatio ns
<br>
Tech Knowledge
Pubilcations
<br>
8051 Interfacing
Microcontroller and Applications 4-23
G2A G2B G1 YO
Yi b -A11A0 -A11
A0
Y2
A12 A 74LS138
A13 3:8 CS
A14 decoder AD WA
Y5
Y6P AD
WR
Fig. 4.4.2 : Using 74LS138 Decoder
The address map of the both i.e. NAND as decoder and 74LS138 Decoder are given in Table 4.4.2(a) and (b).
Table 4.4.2(a) Address map NAND as decoder
:
|A1s| A14 A13|A12| A11|A10 Ag| AgA A6As|A4| A3| A2| A1|Ao|Address
1 0 0 0 0 4000H
0 0 0 0 0 0 0
1 0 1 1 1 1 1 1 1 1 11 1 1 4FFFH
This addressing technique is normally used in large It reduces the cost of the decoding circuit but has
it
a drawback of multiple address ie. shadow
memory systems.
addresses for the same memory location.
Using a simple logic gate like AND or NAND gate
Using a simple logic gate like AND or NAND gate
address decoder, we can generate chip select (CS)
signals from the address bus as shown in Fig. 4.1.3. address decoder, we can generate chip select (CS)
signals from the address bus as shown in Fig. 4.4.4.
Tech Kaowledge
Pubilcations
<br>
A.5(C) Difference between Absolute and 4 Increases the cost Reduces the cost of
of
EA(RD) P3.7 RD
Control
{WR) P3.6 WR bus
PSEN PSEN
PO.7
A0 - A7
AD0 - AD7 74LS373 8 bit Lower order
PO.0 address bus
D0 - D7
Data bus
Tech Knowledge
PubliCations
<br>
The first one is activated byte from external The 8051 microcontroller has writing signals WR
data
memory (RAM) should be read, while one (P3.6) and this signal is active low.
another is
activated to read byte from external program
memory (ROM).
4.4.7 Interfacing of 8K x 8
Program ROM
x
To interface 8K 8
Program ROM,13 address lines and8 data lines are required.
EA (RD) P3.7
(WA) P3.6 WR
PSEN OE
P2.0- P2.4
8 bit A8- A15 A8- A12
8051
ALE
Program
ROM
-
P0.0- P0.7 ADO AD7 74LS373 B
bt A0 A7
8K x8
(2764)
Voo
DO D7
G2A G2B G1 Yoþ
Y1
Y2
(P2.5) A13 74LS138
(P2.6) A14 3:8
(P2.7) A15 decoder
Y5
Tech Knowledge
PuDications
<br>
Interfacing of 8K x 8
Data ROM
4.8
x 8 data
To interface
8K ROM, 13 address lines and 8
data lines are required.
e can use A0-A12 address lines and DO-D7 data lines to interface data ROM with 8051.
nhe Latch 74LS373 is used to de-multiplexed
AD0-AD7 bus and decoder 74LS138 is
used to generate chip select
CS signal.
The complete interfacing of 8Kx 8 data ROM with 8051 is shown in Fig. 4.4.7.
EA (AD) P37
(WA) P3.6 W
PSEN
P2.0 - P2
8 bit
A8- A15 A8 A12
8051
ALE
Data
ROM
8K
x8
DO D7
To interface 8K x 8 data ROM and 8Kx 8program ROM, 13 address lines and 8 data lines are required.
So, we can use A0-A12 address lines and D0-D7 data lines to interface Data ROM and Program ROM with 8051.
The Latch 74LS3 73 is used to de-multiplexed ADO-AD7 bus and decoder 74LS138 is used to generate chip select
CS signals.
The complete interfacing of 8K x 8 data ROM and 8K x 8 program ROM with 8051 is shown in Fig. 4.4.8.
Tech Knowedge
Publicatipns
<br>
8051
ALE
Data Data
ROM ROM
PO.0-PO: ADO- AD7 74LS373 8 bit A0 - A7 A0- A7
8K x 8 eK x8
8bi! DO D7 DO- 07
G2A G2B G1 YO
(P2,5) A13 Y2
74L8138 Y3
(P2.6) A14 3:8
(P2.7) A15 decoder Y5
Y6
Tech Knouledge
Puo}icaticns
<br>
EA (RU) P3.7
WA) P36 WR
PSEN
WR
P2.0- P2.4
8 bit A8- A15 A8- A12
8051
ALE
Data
RAM
- AD7 A0- A7
PO.0PO7ADO 74LS373 8 bit
8K x8
Voc
8 bit DOD7
G2A G28 G1 YOF
CS
74LS138 Y2þ
(P2.5) A13A
P2.6) A14B 3:8
(P2.7) A15C decoder
PSEN
A9 A13
A12
WA WR
A10
A9
AA
AB
RAM(S4K) ROM(64K)
a8538868 A7
A6 D6
A3
8051
s88389a8
ALE
8051 Interfacing
Microcontroller and Applications 4-29
memory (ROM), the microcontroller.
when the 8051 microcontroller starts execution from external
generates ALE signal and transmit lower 8 bits of address i.e. A0:A7 on PU.
Now ALE pin is connected to 74HCT573 octal latch.
A SIgnal on the pin ALE, the 74HCT573 octal latch latches higher bits
8 of address A0-A7 on the output pins
of latch which are available on the port.
The higher address byte i.e. A8-A15 is transmitted on Port 2 at the same time.
In this way 16 bit memory address is transmitted to memory device.
as an input, then PSEN signal is generated by the
Now ALE i.e. removed by the 8051, and PO is configured
microcontroller to reads content from memory location whose address is already transmitted.
The Port 0is
used both for data and lower address byte.
is
Same thing is happened when 8051 reads some data from external Data Memory where, addressing
performed in the same way, while reading or writing of data is performed using signals RD or WR.
Draw interfacing diagram of 4K byte EPROM and 4K byte RAM to 8051 microcontroler. Daw memory map
W-16, S-17, W-18, 4 Marks
Draw the interfacing diagram of 8 K byte of EPROM and 8 K byte of RAM to 8051 microcontroler. Draw the address
To interface 4K × 8 RAM and 4K x 8 EPROM,12 address lines and 8 data lines are required.
So, we can use A0-A11 address lines and DO-D7 data lines to interface RAM and EPROM with 8051.
The Latch 74LS373 is used to de-multiplexed ADO-AD7 bus and decoder 74LS138 is used to generate chip select
CS signals.
The complete interfacing of 4K x 8 EPROM and 4Kx 8 RAM with 8051 is shown in Fig. 4.4.11.
1 0 0 0 0 0 0 0 0 8000H
1 1 1 11 1 1 111 1 1 8FFFH
1 0 1 0 00 00 0 0 0 A000H
1 1 0 1 1
1|1 11 1 1 1 11 1 AFFFH
Tech Knouledge
PupiiCations
<br>
P2.0-P2
8 bit AB-A15 A8-A11 A8-A11
8051
ALE
EPROM RAM
PO.0- PO,7 ADO AD7
74LS373 8bit A0 - A7 A0- Á7
4K x 8 AKx8
Voc
DO- D7 DO D7
To interface 4K x 8 RAM and 4Kx 8RAM, 12 address lines and 8 data lines are required.
So, we can use A0-A11 address lines and D0-D7 data lines to interface RAM with 8051.
The Latch 74LS373 is used to de-multiplex ADO-AD7 bus and decoder 74LS138 is used to generate chip select
CS signals.
The complete interfacing of 4K>x8 RAM 1 and 4K x 8 RAM 2 with 8051 is shown in Fig. 4.4.12.
A
As AE A
A1 Ao Address
A1s A14 A13 A12 A11
A10 Ag AB A4 A3
0 0 0 0000H
0 1 1 1 1 1 1 1 1 1 1 1 1 OFFFH
A1s A14
A13 A12 A11 A10 Ag Ag
A
A6 As A A
A2
A
Ao Address
1 0 0 0 0 0 0 0 0 0 2000H
0
1 0 1 1 1 1 1 1 1 1 1 1 1 1 2FFFH
0 0
TechKaowledge
Publications
<br>
RD RD
E WR WA
PSEN OE
P2,-P2, AgAgt AgAt
ALE
5 4kx 8 4kx8
RAM RAM
AD-AD, G
D-D D,D,
8 Bit
CS CS
Aq5
A14
A13 A
A2 74LS138
G
A11
PSEN
A15A8-A12A8A12
8051
ALE
EPROM FARM
8K8 8KXS
1 0 0 0 0 0 0 0 0 0 0 0 0 0 800OH
1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 9FFFH
Tech Knowledge
Publications
<br>
The Latch 74LS373 is used to de-multiplexed AD0-AD7 bus and decoder 74LS138 is used to generate chip select
(CS) signal.
8051
ALE
2KB
DATA RAM
ADO - AD7
PO
0PO.7 74LS373 3 bit A0- A7
A11 A12
DO D7
8 bit
G2A G2B G1 Yob CS
Y2
(P2.5) A13 74LS138 Y3
(P2.6) A14 3:8
(P2.7) A15 - Y4b
decoder Y5
Tech Knowladge
Publications
<br>
8051 Interfacing
Microcontroller and Applications 4-33
4.4.14 Interfacing of 2K x 8 RAM and 2K x 8 EPROM
Draw the memory map.
Draw Interfacing of 2 Kbyte EPROM and 2 Kbvte RAM to 8051 microcontroller.
S-15, W-15, S-18, 6 Marks
to memory map. S-19, 4 Marks
Sketch interfacing diagram of 2 Kbyte RAM and 2 Kbvte EPROM 8051. Draw the
To interface 2K x 8 RAM and 2Kx 8 EPROM, 11 address lines and 8 data lines are required.
So, we can use A0-A10 address lines and D0-D7 dat lines to interface RAM and EPROM with 8051.
The Latch 74LS373 is used to de-multiplexed ADO-AD7 bus and decoder 74LS138 is used to generate chip select
CS signals.
The complete interfacing of 2K x 8 ROM and 2Kx8 ROM with 8051 is shown in Fig. 4.4.15.
805t
ALE
2KB 2KE
RAM
EPROM
A13
P25) 741.3138
P2.6) A1i
A15
(P27)
1 0 1 1
00 000 00000 DO00H
1 0 1 1 1 1 111|1 1 1
11 D7FFH
Review Questions
Q. Draw interfacing diagram of relay with 8051 microcontroler. Write an ALP to turn ON and OFF relay.
Draw the diagram to interface external RAM and ROM with 8051. Mention the pins during interfacing and describe in brief.
Tech Knouwledge
Publications
<br>
lateh interfacing diagram of 2 Kbyte RAM and 2 Kbyte EPROM to 8051. Draw
the memory map.
Aveteh 8051 interfacing diagram to interface 4 LED's and 4 switches. Inteface switches to port
0 and LED to port 1
.onner nibble.
Develop an ALP to read status of switches and operate LED's as per switch status.
0. Interface ADC 0809 with 8051 and write a program to read data from the device and convert to digital.