MPMC - Unit-3 Part 1
MPMC - Unit-3 Part 1
Interfacing of 8051with: Analog Sensors, Keypad & LCD display, ADC, DAC,
LCD INTERFACING:
1
VEE pin is meant for adjusting the contrast of the LCD display and the contrast can be
adjusted by varying the voltage at this pin.
This is done by connecting one end of a POT to the Vcc (5V), other end to the Ground
and connecting the center terminal (wiper) of of the POT to the VEE pin. (Refer Figure
5.2)
RS:
LCD has two built in registers namely data register and command register.
Data register is for placing the data to be displayed, and the command register is to
place the commands.
High logic at the RS pin will select the data register and Low logic at the RS pin will
select the command register.
If we make the RS pin high and the put a data in the 8 bit data line (DB0 to DB7), the
LCD module will recognize it as a data to be displayed.
If we make RS pin low and put a data on the data line, the module will recognize it as a
command.
R/W:
R/W pin is meant for selecting between read and write modes.
High level at this pin enables read mode and low level at this pin enables write mode.
Enable (E):
E pin is for enabling the module.
The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high to low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins.
This pulse must be a minimum of 450ns wide.
Data Pin:
The 8-bit data pins, DB0 to DB7 are used to send information to the LCD or read the
contents of the LCD’s internal register.
To display letters and numbers, send ASCII codes for the letters A-Z; a-z and numbers
0-9 to these pins while making RS=1.
There are also instruction command codes that can be sent to the LCD to clear the
display or force the cursor to the home position or blink the cursor.
Table 5.2 Lists the instructions command codes.
2
0C Display on, cursor off
0E Display on, cursor blinking
0F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to the beginning of 1st line
C0 Force cursor to the beginning of 2nd line
38 2 lines and 5 x 7 matrix
We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive
information’s.
The busy flag id D7 and can be read when R/W=1 and RS=0, as follows: if R/W=1,
RS=0.
When D7=1 (busy flag =1), the LCD is busy taking care of internal operations and will
not accept any new information.
LED+ & LED-:
LED+ is the anode of the back light LED and this pin must be connected to Vcc through
a suitable series current limiting resistor.
LED- is the cathode of the back light LED and this pin must be connected to ground.
LCD initialization
The steps that has to be done for initializing the LCD display is given below and these
steps are common for almost all applications.
o Send 38H to the 8 bit data line for initialization
o Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
3
o Send 06H for incrementing cursor position.
o Send 80H for displaying the character from 1 st row and 1st column in LCD
o Send 01H for clearing the display and return the cursor.
4
MOV P1,A ;copy reg 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
ACALL DELAY
CLR P2.2 ;E=0 for H-to-L pulse
RET
ORG 0
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
MOV A,#’N’ ;display letter N
ACALL DATAWRT ;call display subroutine
5
MOV A,#’O’ ;display letter O
ACALL DATAWRT ;call display subroutine
AGAIN: SJMP AGAIN ;stay here
READY:
SETB P1.7 ;make P1.7 input port
CLR P2.0 ;RS=0 access command reg
SETB P2.1 ;R/W=1 read command reg
;read command reg and check busy flag
BACK: SETB P2.2 ;E=1 for H-to-L pulse
CLR P2.2 ;E=0 H-to-L pulse
JB P1.7,BACK ;stay until busy flag=0
RET
END
LCD Interfacing Using MOVC Instruction:
ORG 0
MOV DPTR,#MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ SEND_DAT
SJMP C1
SEND_DAT:
6
MOV DPTR,#MYDATA
D1: CLR A
MOVC A,@A+DPTR
ACALL DATAWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ AGAIN
SJMP D1
AGAIN: SJMP AGAIN
ORG 300H
MYCOM: DB 38H,0EH,01,06,84H,0 ; commands and null
MYDATA: DB “HELLO”,0
END
KEYBOARD INTERFACING:
At the lowest level, keyboards are organized in a matrix of rows and columns.
The CPU accesses both rows and columns through ports; therefore, with two 8-bit ports,
an 8 x 8 matrix of keys can be connected to a microprocessor.
When a key is pressed, a row and a column make a contact; otherwise, there is no
connection between rows and columns
Scanning and identifying the key
7
Figure 5.3 Matrix Keyboard Connection to Ports
To detect a pressed key, the microcontroller grounds all rows by providing 0 to the
output latch, then it reads the columns.
If the data read from the columns is D3 - D0 =1111, no key has been pressed and the
process continues until a key press is detected.
However, if one of the column bits has a zero, this means that a key press has occurred.
For example, if D3 - D0 = 1101, this means that a key in the D1 column has been
pressed.
After a key press is detected, the microcontroller will go through the process of
identifying the key.
Starting with the top row, the microcontroller grounds it by providing a low to row D0
only; then it reads the columns.
If the data read is all 1s, no key in that row is activated and the process is moved to the
next row.
It grounds the next row, reads the columns, and checks for any zero.
This process continues until the row is identified.
After identification of the row in which the key has been pressed, the next task is to find
out which column the pressed key belongs to.
This should be easy since the microcontroller knows at any time which row and column
are being accessed.
Given keyboard program is the 8051 Assembly language program for detection and
identification of key activation.
In this program, it is assumed that P1 and P2 are initialized as output and input,
respectively.
8
o Program goes through the following four major stages:
o
o To make sure that the preceding key has been released, 0s are output to all rows
at once, and the columns are read and checked repeatedly until all the columns
are high. When all columns are found to be high, the program waits for a short
amount of time before it goes to the next stage of waiting for a key to be pressed.
o To see if any key is pressed, the columns are scanned over and over in an
infinite loop until one of them has a 0 on it. Remember that the output latches
connected to rows still have their initial zeros (provided in stage 1), making them
grounded. After the key press detection, the microcontroller waits 20 ms for the
bounce and then scans the columns again. This serves two functions: (a) it
ensures that the first key press detection was not an erroneous one due to a
spike noise, and (b) the 20-ms delay prevents the same key press from being
interpreted as a multiple key press. If after the 20-ms delay the key is still
pressed, it goes to the next stage to detect which row it belongs to; otherwise, it
goes back into the loop to detect a real key press.
o To detect which row the key press belongs to, the microcontroller grounds one
row at a time, reading the columns each time. If it finds that all columns are high,
this means that the key press cannot belong to that row; therefore, it grounds the
next row and continues until it finds the row the key press belongs to. Upon
finding the row that the key press belongs to, it sets up the starting address for
the look-up table holding the scan codes (or the ASCII value) for that row and
goes to the next stage to identify the key.
o To identify the key press, the microcontroller rotates the column bits, one bit at a
time, into the carry flag and checks to see if it is low. Upon finding the zero, it
pulls out the ASCII code for that key from the look-up table; otherwise, it
increments the pointer to point to the next element of the look-up table. Figure
5.4 flowcharts this process.
While the key press detection is standard for all keyboards, the process for determining
which key is pressed varies.
The look-up table method shown in keyboard Program can be modified to work with any
matrix up t0 8 x 8.
Figure 5.4 provides the flowchart for keyboard interfacing Program for scanning and
identifying the pressed key.
9
Figure 5.4 Flowchart for Programming Keyboard Interfacing
10
Program:
;keyboard subroutine. This program sends the ASCII
;code for pressed key to P0.1
;P1.0-P1.3 connected to rows, P2.0-P2.3 to column
MOV P2,#0FFH ;make P2 an input port
K1: MOV P1,#0 ;ground all rows at once
MOV A,P2 ;read all col
;(ensure keys open)
ANL A,00001111B ;masked unused bits
CJNE A,#00001111B,K1 ;till all keys release
K2: ACALL DELAY ;call 20 msec delay
MOV A,P2 ;see if any key is pressed
ANL A,00001111B ;mask unused bits
CJNE A,#00001111B,OVER ;key pressed, find row
SJMP K2 ;check till key pressed
OVER: ACALL DELAY ;wait 20 msec debounce time
MOV A,P2 ;check key closure
ANL A,00001111B ;mask unused bits
CJNE A,#00001111B,OVER1;key pressed, find row
SJMP K2 ;if none, keep polling
OVER1: MOV P1, #11111110B ;ground row 0
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_0 ;key row 0, find col.
MOV P1,#11111101B ;ground row 1
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_1 ;key row 1, find col.
MOV P1,#11111011B ;ground row 2
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_2 ;key row 2, find col.
MOV P1,#11110111B ;ground row 3
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_3 ;key row 3, find col.
LJMP K2 ;if none, false input,
;repeat
ROW_0: MOV DPTR,#KCODE0 ;set DPTR=start of row 0
SJMP FIND ;find col. Key belongs to
ROW_1: MOV DPTR,#KCODE1 ;set DPTR=start of row
SJMP FIND ;find col. Key belongs to
ROW_2: MOV DPTR,#KCODE2 ;set DPTR=start of row 2
SJMP FIND ;find col. Key belongs to
11
ROW_3: MOV DPTR,#KCODE3 ;set DPTR=start of row 3
FIND: RRC A ;see if any CY bit low
JNC MATCH ;if zero, get ASCII code
INC DPTR ;point to next col. addr
SJMP FIND ;keep searching
MATCH: CLR A ;set A=0 (match is found)
MOVC A,@A+DPTR ;get ASCII from table
MOV P0,A ;display pressed key
LJMP K1
;ASCII LOOK-UP TABLE FOR EACH ROW
ORG 300H
KCODE0: DB ‘0’,’1’,’2’,’3’ ;ROW 0
KCODE1: DB ‘4’,’5’,’6’,’7’ ;ROW 1
KCODE2: DB ‘8’,’9’,’A’,’B’ ;ROW 2
KCODE3: DB ‘C’,’D’,’E’,’F’ ;ROW 3
END
ADCs (analog-to-digital converters)are among the most widely used devices for data
acquisition.
A physical quantity, like temperature, pressure, humidity, and velocity, etc., is converted
to electrical (voltage, current)signals using a device called a transducer or sensor
We need an analog-to-digital converter to translate the analog signals to digital numbers,
so microcontroller can read and process them.
An ADC has n-bit resolution where n can be 8, 10, 12, 16 or even 24 bits.
The higher-resolution ADC provides a smaller step size, where step size is the smallest
change that can be discerned by an ADC. This is shown in table 5.3
Table 5.3 Resolution Vs Step Size for ADC
12
ADC804 chip:
ADC804 IC is an 8-bit parallel analog-to-digital converter.
It works with +5 volts and has a resolution of 8bits.
In ADC804 conversion time varies depending on the clocking signals applied to the CLK
R and CLK IN pins, but it cannot be faster than 110μs.
Figure 5.5 Pin out of ADC0804 in free running mode.
The following is the ADC0804 pin description.
D0-D7:
D0-D7 are the digital data output pins.
These are tri-state buffered and the converted data is accessed only when CS =0
and RD is forced low.
To calculate the output voltage, use the following formula
15
Figure 5.7 8051 Connection to ADC0804 with Self-Clocking
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.
16
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
ADC0808:
While the ADC0804 has only one analog input, this chip has 8 of them.
The ADC0808/0809 chip allows us to monitor up to 8 different analog inputs using only a
single chip.
Notice that the ADC0808/0809 has an 8-bit data output just like the ADC804.
The 8 analog input channels are multiplexed and selected according to Table 5.5 using
three address pins, A, B, and C.
Table 5.5 Channel Selection in ADC0808
In the ADC0808/0809, Vref (+) and Vref.(-) set the reference voltage.
If Vref(-) = Gnd and Vref (+) = 5 V, the step size is 5 V/256 = 19.53 mV.
Therefore, to get a l0 mV step size we need to set Vref (+) = 2.56 V and Vref.(-) = Gnd.
From Figure 5.9, notice the ALE pin.
We use A, B, and C addresses to select.IN0 - IN7, and activate ALE to latch in the
address.
SC is for start conversion.
SC is the same as the WR pin in other ADC chips.
EOC is for end-of-conversion, and OE is for output enable (READ).
The EOC and OE are the same as the INTR and RD pins respectively.
Table 5.6 shows the step size relation to the Vref voltage.
Notice that there is no Vref/2 in the ADC0808/0809 chip.
17
Figure 5.9 ADC0808/0809
18
SENSOR INTERFACING:
LM35 Temperature sensors:
The LM35 series sensors are precision integrated-circuit temperature sensors whose
output voltage is linearly proportional to the celsius (centigrade) temperature.
The LM35 requires no external calibration since it is internally calibrated.
It outputs 10mV for each degree of centigrade temperature.
Table 5.7 is the selection guide for the LM35
The above figure 5.10 shows the steps involved in acquiring data from analog world.
Signal conditioning is widely used in the world of data acquisition.
The most common transducers produce an output in the form of voltage, current,
charge, capacitance, and resistance.
19
However, we need to convert these signals to voltage in order to send input to an A-to-D
converter.
This conversion (modification) is commonly called signal conditioning.
Signal conditioning can be a current-to-voltage conversion or a signal amplification.
For example, the thermistor changes resistance with temperature.
The change of resistance must be translated into voltages in order to be of any use to an
ADC.
Look at the case of connecting an LM35 to an ADC0848.
Since the ADC0848 has 8-bit resolution with a maximum of 256 (2 8) steps and the LM35
(or LM34) produces l0 mV for every degree of temperature change, we can condition V in
of the ADC0848 to produce a V out, of 2560 mV (2.56 V) for full-scale output.
Therefore, in order to produce the full-scale Vout of 2.56 V for the ADC0848, we need to
set Vref = 2.56.
This makes Vout, of the ADC0848 correspond directly to the temperature as monitored by
the LM35. Refer the table 5.8
Table 5.8 Temperature vs. Vout for ADC0848
CONVERSION:
MOV B,#10
DIV AB
MOV R7,B
MOV B,#10
DIV AB
MOV R6,B
MOV R5,A
RET
DATA_DISPLAY:
MOV P0,R7
ACALL DELAY
MOV P0,R6
ACALL DELAY
MOV P0,R5
ACALL DELAY
RET
The DAC is a device widely used to convert digital pulses to analog signals.
In this section we will discuss the basics of interfacing a DAC to 8051.
The two method of creating a DAC is binary weighted and R/2R ladder.
The Binary Weighted DAC, which contains one resistor or current source for each bit of
the DAC connected to a summing point.
These precise voltages or currents sum to the correct output value.
21
This is one of the fastest conversion methods but suffers from poor accuracy because of
the high precision required for each individual voltage or current.
Such high-precision resistors and current-sources are expensive, so this type of
converter is usually limited to 8-bit resolution or less.
The R-2R ladder DAC, which is a binary weighted DAC that uses a repeating cascaded
structure of resistor values R and 2R.
This improves the precision due to the relative ease of producing equal valued matched
resistors (or current sources).
However, wide converters perform slowly due to increasingly large RC-constants for
each added R-2R link.
The first criterion for judging a DAC is its resolution, which is a function of the number of
binary inputs.
The common ones are 8, 10, and 12 bits.
The number of data bit inputs decides the resolution of the DAC since the number of
analog output levels is equal to 2 n, where n is the number of data bit inputs.
Therefore, an 8-input DAC such as the DAC0808 provides 256 discrete voltage (or
current) levels of output.
Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
There also 16-bit DACs, but they are more expensive.
DAC0808:
The digital inputs are converter to current (Iout), and by connecting a resistor to the Iout
pin, we can convert the result to voltage.
The total current provided by the Iout pin is a function of the binary numbers at the D0-D7
inputs of the DAC0808 and the reference current (Iref), and is as follows
22
Figure 5.12 8051 Connection to DAC808
Example 1:
Assuming that R=5K and Iref=2mA, calculate Vout for the following binary inputs:
(a) 10011001B
(b) 11001000B
Solution:
(a) Iout = 2mA(153/256) = 1.195mA and Vout = 1.195mA * 5K =5.975V
(b) Iout = 2mA(200/256) = 1.562mA and Vout = 1.562mA * 5K =7.8125V
23
Generating a sine wave
To generate a sine wave, we first need a table whose values represent the magnitude of the sine of
angles between 0 and 360 degrees.
The values for the sine function vary from -1.0 to +1.0 for 0- to 360-degree angles.
Therefore, the table values are integer numbers representing the voltage magnitude for the sine of theta.
This method ensures that only integer numbers are output to the DAC by the 805l microcontroller.
Table 5.9 shows the angles, the sine values, the voltage magnitudes, and the integer values representing
the voltage magnitude for each angle (with 30-degree increments).
To generate Table 5.9,we assumed the full-scale voltage of 10 V for DAC output (as designed in
Example 4 Figure).
Full-scale output of the DAC is achieved when all the data inputs of the DAc are high.
Therefore, to achieve the full-scale 10 V output, we use the following equation
Vout= 5V(1+sinθ)
Vout of DAC for various angles is calculated and shown in Table 5.9. See Example 3 for verification of
the calculations
Example 4:
Write an ALP to generate a sine waveform.
Vout= 5V(1+sinθ)
2
4
Solution:
Calculate the decimal values for every 10 degree of the sine wave. These values can be maintained in a
table and simply the values can be sent to port P1. The sine wave can be observed on the CRO.
Example 5:
2
5
2
6
Memory Interfacing with 8051
External ROM (program memory) Interfacing
P1 P0 D0-D7
EA A0
| ROM/
8051 LATC A7 EPROM
ALE H
clock
A8 Address
P3 | lines
A15
PSEN OE
above figure shows how to access or interface ROM to 8051. port 0 is used as
multiplexed data & address lines.
it gives lower order (A7-A0) 8 bit address in initial T cycle & higher order (A8-A15)
used as data bus.
8 bit address is latched using external latch & ALE signal from 8051. port 2 provides higher
order (A15-A8) 8 bit address.
PSEN is used to activate the output enable signal of external ROM/EPROM.
External RAM (data memory) Interfacing
P1 D0 data
P0 | lines D7
clock RAM
A0
|
8051 ALE A7 address
LATCH
lines
P2
RD P3
WR W O
R E
RD & WR signals from 8051 selects the memory read & memory write operations
respectively.
RD & WR signals: generally P3.6 & P3.7 pins of port 3 are used to generate
meamory read and memory write signals. 2
remaining pins of port 3 i.e. P3.0-P3.5 can be used for other functions. 7
LINEAR AND ABSOLUTE DECODING
i. Absolute Decoding
all higher address lines : decoded to select memory chip for
specific logic levels.
for other logic levels memory chip is disabled. generally
used in large memory systems.
figure below shows memory interfacing using absolute decoding.
Vss
P0.7 D7-D0
EA |
P0.0
74LS373 A7-A0
ALE G OC 16k x 8
8051 RAM
P2.0
A8-A13
| P2.5
P2.6
P2.7
CS
PSEN WR
P3.6
RD
P3.7
FIGURE 3 MEMORY (RAM) INTERFACING USING ABSOLUTE DECODING.
reducing the cost of decoding, drawback is- multiple addresses. as shown in figure
below, A14 line is directly connected to chip select line, A15 line not connected
anywhere, kept open.
so, status of A15- not considered for generation of chip select signal.
Vss D7-D0
P0.7
EA | 74LS
P0.0 373
A7-A0
ALE G O 16 x 8
8051 P2.0 C RAM
|
P2.5 A8-A13 CS
P2.6
P2.7 (A14)
A15
PSEN
P3.6
W
P3.7 R
R
D
2
8
G
U
R
E
M
E
M
O
R
Y
(
R
A
M
)
I
N
T
E
R
F
A
C
I
N
G
U
S
I
N
G
L
I
N
E
A
R
D
E
C
O
D
I
N
G
.
2
9
Address Mapping(Memory Map)
i. Absolute Decoding
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A A1 A HEX
2 0 adrs.
starting 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0000H
end 0 0 1 1 1 1 11 1 1 1 1 1 1 1 1 3FFFH
ii. Linear Decoding
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A A1 A HEX
2 0
adrs.
starting 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0000H
end x 0 1 1 1 1 11 1 1 1 1 1 1 1 1 3FFFH
Comparison between Full address(Absolute) & Partial address (Linear) Decoding.
i. all higher address lines are |i. few or individual address lines decoded to select memory
or | are decoded to select memory or I/O device. | I/O device.
ii. more hardware : decoding |ii. less hardware : decoding logic. logic. | (sometimes
none.)
iii. decoding circuit : higher |iii. decoding circuit : less cost.
cost. |
iv. No multiple addresses. |iv. multiple addresses possible.
v. used in large systems. |v. used in small systems.
Solved Examples:
Example 1: Design a µController system using 8051.Interface the external RAM of size 16k x 8.
Solution: Given, Memory size: 16k
that means we require 2 n=16k :: n address lines here n=14 :: A0 to
A13 address lines arerequired.
A14 and A15 are connected through OR gate to CS pin of external RAM. when A14 and A15
both are low (logic ‘0’), external data memory(RAM) is selected.
Address Decoding(Memory Map)for 16k x 8 RAM.
ALE G OC 16k x 8
8051 RAM
A8-A13
P2.0
| P2.5
P2.6
P2.7 CS
PSEN
P3.6 WR
P3.7 RD
3
Example 2: Design a µController system using 8051.Interface the external ROM of size 4k x 8.
Solution: Given, Memory size: 4k
that means we require 2 n=4k :: n address lines here n=12 :: A0 to
A11 address lines arerequired.
remaining lines A0, A0, A0, A0 & PSEN are connected though OR gate to CS & RD of external
ROM.
when A0 to A0 are low (logic ‘0’), only then external ROM is selected. Address
Decoding(Memory Map)for 4k x 8 RAM.
Address A15A14A13A12 A11A10A9A8 A7A6 A5A4 A3 A2A1A0 HEX
adrs.
starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
end 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0FFFH
Vss
P0.7 D7-D0
E |
A P0.0
7 A7-A0
4
ALE G O
L 4k x 8
8051 C
S ROM
P2.0 3
| 7 A8-A11
P2.5 3
P2.6
P2.7 W
PSE R
N
P3.6 C
P3.7 S
FIGURE 6 4K X 8 MEMORY (ROM) INTERFACING TO µC 8051.
RD
Example 3: Design a µController system using 8051, 16k bytes of ROM & 32k bytes of RAM. Interface
the memory such that starting address for ROM is 0000H & RAM is 8000H.
Solution: Given, Memory size- ROM : 16k
that means we require 2 n=16k :: n address lines here n=14 :: A0 to
A13 address lines arerequired.
A14,A15,PSEN OR CS
for RAM
PSEN is used as chip select pin ROM. RD is used as read control signal pin. selection.
WR is used as write control signal pin.
4
Address Decoding(Memory Map)for 16k x 8 ROM.
Address A15A14A13A12 A11A10A9A8 A7A6 A5 A4 A3 A2 A1 A0 HEX
adrs.
starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
end 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FFFH
Address Decoding(Memory Map)for 32k x 8 RAM.
Address A15A1 A13A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 HEX
adrs.
starting 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8000H
Vss end 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 FFFFH
Vcc
Vcc
P0.7 D7-D0 D7-D0
EA |
P0.0
7 A7-A0 A7-A0
4 32k x 8
ALE G O 16k x 8
L RAM
8051 C
S ROM
P2.0 3
| A8-A13 A8-A13
7
P2.5
3
P2.6 To
P2.7 CS CS(A15)
P2.7
To
PSE P2.6 A14
N RD
P3.6 RD WR
P3.7
5
FIGURE 7 16K X 8 ROM AND 32K X 8 RAM INTERFACING TO µC 8051.
Example 4:Design a µController system using 8051, 8k bytes of program ROM & 8k bytes of data
RAM. Interface the memory such that starting address for ROM is 0000H & RAM is E000H.
A13,A14,A15,PSEN ORed CS
A13,A14,A15 NANDe C
d S
when high- data RAM is selected.
ALE G OC 8k x 8 8k x 8
8051 ROM RAM
P2.0
| P2.4 A8-A12 A8-A12
P2.5 To
P2.7
P2.6 To
P2.7 CS P2.6 CS
PSEN To
P2.5
P3.6
RD
P3.7 WR RD
FIGURE 8 8K X 8 ROM AND 8K X 8 RAM INTERFACING TO µC 8051.
6
Reference:
Muhammed Ali Mazidi, Janice Gillispie Mazidi and Rolin D.McKinlay, “The 8051
Microcontroller and Embedded Systems: Using Assembly and C”