Module 1 Notes_2024-2025
Module 1 Notes_2024-2025
1.10 Memory Address Decoding, 8031/51 Interfacing With External ROM and RAM
Objectives
1. A set of instructions written in a specific sequence for the computer to solve a specific
task is called a program and software is a collection of such programs.
2. The program stored in the computer memory in the form of binary numbers is called
machine instructions. The machine language program is called object code.
3. An assembly language is a mnemonic representation of machine language. Machine
language and assembly language are low level languages and are processor specific.
4. The assembly language program the programmer enters is called source code. The
source code (assembly language) is translated to object code (machine language)
using assembler.
5. Programs can be written in high level languages such as C, C++ etc. High level
language will be converted to machine language using compiler or interpreter.
6. Compiler reads the entire program and translate into the object code and then it is
executed by the processor.
7. Interpreter takes one statement of the high level language as input and translate it into
object code and then executes.
Microprocessors
3. To make a computer microcomputer one must add memory usually RAM and ROM,
memory decoders, an oscillator and a number of Input, Output devices such as serial
and parallel ports.
4. In addition special purpose devices such as interrupt handler and counters may be
added to relieve the CPU from time consuming counting or timing cores. When the
Microcomputer is equipped with mass storage devices, I/O peripherals such as a key
board and a display CRT it yields a small computer that can be applied to a range of
general purpose applications.
5. The hardware design of a microprocessor is arranged such that a very small or very
large system can be configured around the CPU as the application demands as shown in
Fig1.
6. The prime use of the Microprocessor is to read data , perform extensive calculations on
that data, and store those calculations in a mass storage device or display the results
for human use. The programs used by microprocessor are stored in the mass
storage device and loaded into RAM as user directs. A few microprocessor program are
stored in ROM. The ROM based programs are primarily small fixed programs that
operate peripherals and other fixed devices that are connected to the system.
Microcontroller:
Microcontrollers with small instruction set are called reduced instruction set computer (RISC)
machines and those with complex instruction set are called complex instruction set computer
(CISC). Intel 8051 is an example of CISC machine whereas microchip PIC 18F87X is an
example of RISC machine.
It uses single memory space for both It has separate program memory
2
instructions and data. and data memory
It is not possible to fetch instruction code and Instruction code and data can be
3
data fetched simultaneously
Execution of instruction takes more machine Execution of instruction takes less
4
cycle machine cycle
5 Uses CISC architecture Uses RISC architecture
Instruction parallelism is a main
6 Instruction pre-fetching is a main feature
feature
Also known as control flow or control driven Also known as data flow or data
7
computers driven computers
Simplifies the chip design because of single Chip design is complex due to
8
memory space separate memory space
Eg.General purpose
9 Eg. 8085, 8086, MC6800 microcontrollers, special DSP chips
etc.
1. Microcontrollers have gone through a silent evolution (invisible). The evolution can
be rightly termed as silent as the impact or application of a microcontroller is not well
known to a common user, although microcontroller technology has undergone
significant change since early 1970's.
2. Development of some popular microcontrollers is given in Table 4
The programming model of 8051 shows the 8051 as the collection of 8 and 16 bit registers and
8 bit memory locations. These registers and memory locations can be made to operate
using software instructions that are incorporated as part of the program instructions.
Salient Features
Microcontroller Chips:
This is an 8 bit register which contains the arithmetic status of ALU and the bank
select bits of register banks.
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
CY AC F0 RS1 RS0 OV - P
Note: CY- carry flag AC - auxiliary carry flag
1.5.1 Stack
6. As the data is retrieved from the stack the byte is read from the stack, and then SP
decrements to point the next available byte of stored data (post decrement). The
stack pointer is set to 07 when the 8051 resets.
7. So that default stack memory starts from address location 08 onwards (to avoid
overwriting the default register bank i.e., bank 0).
15. PSW, SP, 16 bit program counter, stack pointer. ALU can perform arithmetic and
logic functions on 8 bit variables.
16. 8051 has 128 bytes of internal RAM which is divided into
17. Working registers [00 – 1F] o Bit addressable memory area [20 – 2F] o General
purpose memory area (Scratch pad memory) [30-7F]
18. 8051 has 4 K Bytes of internal ROM. The address space is from 0000 to 0FFFh. If the
program size is more than 4 K Bytes 8051 will fetch the code automatically from
external memory.
19. Accumulator is an 8 bit register widely used for all arithmetic and logical operations.
Accumulator is also used to transfer data between external memory. B register is used
along with Accumulator for multiplication and division. A and B registers together is
also called MATH registers.
1. I/O Port pins, Ports and Circuits: One major feature of a microcontroller is versatility
built into the I/O circuits that connect the 8051 to the outside world.
2. Out of 40 pins 24 pins may each be used for one of two entirely different functions
yielding a total pin configuration of 64.
3. But the port pins have been multiplexed to perform different functions to make 8051
as 40 Pin IC
The port pin circuitry is as shown below
Port-0
3. When the port is used as an input port, '1' is written to the latch. In this situation both the
output MOSFETs are 'off'. Hence the output pin floats. This high impedance pin can be
pulled up or low by an external source.
4. When the port is used as an output port, a '1' written to the latch again turns 'off' both the
output MOSFETs and causes the output pin to float. An external pull-up is
required to output a '1'.
5. But when '0' is written to the latch, the pin is pulled down by the lower MOSFET.
Hence the output becomes zero. When the control is '1', address/data bus controls the
output driver MOSFETs. If the address/data bus (internal) is '0', the upper MOSFET is
'off' and the lower MOSFET is 'on'.
6. The output becomes '0'. If the address/data bus is '1', the upper transistor is 'on' and
the lower transistor is 'off'.
7. Hence the output is '1'. Hence for normal address/data interfacing (for external
memory access) no pull-up resistors are required. Port-0 latch is written to with 1's
when used for external memory access
Port-1
Port-2
1. Port-2 has 8-pins (P2.0-P2.7) . The structure of a port-2 pin is shown in Fig 1.7
2. Port-2 is used for higher external address byte or a normal input/output port. The I/O
operation is similar to Port-1.
3. Port-2 latch remains stable when Port-2 pin are used for external memory access.
Here again due to internal pull-up there is limited current driving capability.
Port-3
1. Each pin of Port-3 can be individually programmed for I/O operation or for alternate
function. The alternate function can be activated only if the corresponding latch has
been written to '1'.
2. To use the port as input port, '1' should be written to the latch. This port also has
internal pull-up and limited current driving capability.
3. Alternate functions of Port-3 pins –
Note:
1. Port 1, 2, 3 each can drive 4 LS TTL inputs.
2. Port-0 can drive 8 LS TTL inputs in address /data mode. For digital output port, it needs
external pull-up resistors.
3. Ports-1,2and 3 pins can also be driven by open-collector or open-drain outputs.
• Each Port 3 bit can be configured either as a normal I/O or as a special function bit.
Reading a port (port-pins) versus reading a latch.
• There is a subtle difference between reading a latch and reading the output port pin.
The status of the output port pin is sometimes dependant on the connected load.
• For instance if a port is configured as an output port and a '1' is written to the latch,
the output pin should also show '1'.
• If the output is used to drive the base of a transistor, the transistor turns 'on'. If the
port pin is read, the value will be '0' which is corresponding to the base-emitter
voltage of the transistor.
• Reading a latch: Usually the instructions that read the latch, read a value, possibly
change it, and then rewrite it to the latch. These are called "read-modify-write"
instructions.
1. The 8051 operations that do not use the internal RAM addresses from 00h to 7fh
are done by a group of specific internal registers each called a specific function
register (SFR) which may be addressed much like internal RAM using addresses
from 80h to FFh.
2. Some SFRs are also bit addressable as is the case for the bit area of RAM. This
feature allows the programmer the programmer to change only what needs to be
altered leaving the remaining bits in that SFR unchanged. Not all of the addresses
from 80h to FFh are used for SFRs .
3. Only the addressed ones can be used in programming SFRs and equivalent internal
RAM addresses are shown in Fig.1.8.
4. SFR Map: The set of Special Function Registers (SFRs) contain important registers
such as Accumulator, Register B, I/O Port latch registers, Stack pointer, Data Pointer,
Processor Status Word (PSW) and various control registers.
5. The detailed map of various registers is shown in the following Fig.1.8. The PC is not
part of the SFR 0e0h or 8ch. and has no internal RAM address.
1.10 Memory Address Decoding, 8031/51 Interfacing With External ROM and RAM
Connecting External Memory: The following figure shows the connection between an
8051 and external memory
Interfacing External Memory:
1. The system designer is not limited by the amount of internal ROM and RAM
available on chip.
2. Two separate external memory spaces are made available by the 16 bit Program
Counter PC and DPTR and by different control pins for enabling the external ROM
and RAM chips.
3. Internal control entry accesses the correct physical memory , depending on the
machine cycle state and opcode being executed .
4. There are several reasons for adding external memory, particularly Program Memory,
when applying the 8051 in a system. When project is in the prototype stage, having a
masked internal ROM for each program “try” is prohibitive.
5. To help the programmer the manufacturers make available an EPROM version, the
8751, which has 4K of on-chip EPROM that may be programmed and erased as
needed as the program is developed If external program/data memory are to be
interfaced, they are interfaced in the following way
Microcontroller Notes:BEE403
The external memory access in 8051 can be shown by a schematic diagram as given in Fig
1.12
1. Immediate addressing.
In this addressing mode the data is provided as a part of instruction itself. In other
words data immediately follows the instruction.
Eg. MOV A,#30H
ADD A, #83H ; Symbol indicates the data is immediate
2. Register addressing.
In this addressing mode the register will hold the data. One of the eight general
registers (R0 to R7) can be used and specified as the operand.
Eg. MOV A,R0 ADD A,R6 R0 – R7 will be selected from the current selection of
register bank. The default register bank will be bank 0
3. Direct addressing
1. There are two ways to access the internal memory. Using direct address and indirect
address. Using direct addressing mode we can not only address the internal memory
but SFRs also.
2. In direct addressing, an 8 bit internal data memory address is specified as part of the
instruction and hence, it can specify the address only in the range of 00H to FFH. In this
addressing mode, data is obtained directly from the memory.
Eg. MOV A,60h ADD A,30h
4. Indirect addressing
1. The indirect addressing mode uses a register to hold the actual address that will be
used in data movement.
2. Registers R0 and R1 and DPTR are the only registers that can be used as data pointers.
Indirect addressing cannot be used to refer to SFR registers.
3. Both R0 and R1 can hold 8 bit address and DPTR can hold 16 bit address.
Eg. MOV A,@R0 ADD A,@R1 MOVX A,@DPTR
5. Indexed addressing.
1. In indexed addressing, either the program counter (PC), or the data pointer (DTPR)—
is used to hold the base address, and the A is used to hold the offset address.
2. Adding the value of the base address to the value of the offset address forms the
effective address. Indexed addressing is used with JMP or MOVC instructions.
3. Look up tables are easily implemented with the help of index addressing.
4. Eg. MOVC A, @A+DPTR // copies the contents of memory location pointed by the
sum of the accumulator A and the DPTR into accumulator A.
MOVC A, @A+PC // copies the contents of memory location pointed by the sum of
the accumulator A and the program counter into accumulator A
6. Relative Addressing.
1. Relative addressing is used only with conditional jump instructions. The relative
address, (offset), is an 8 bit signed number, which is automatically added to the PC to
make the address of the next instruction.
2. The 8 bit signed offset value gives an address range of +127 to —128 locations. The
jump destination is usually specified using a label and the assembler calculates the
jump offset accordingly.
3. The advantage of relative addressing is that the program code is easy to relocate and
the address is relative to position in the memory.
Eg. SJMP LOOP1 JC BACK
7. Absolute addressing
1. Absolute addressing is used only by the AJMP (Absolute Jump) and ACALL
(Absolute Call) instructions.
2. These are 2 bytes instructions. The absolute addressing mode specifies the lowest 11
bit of the memory address as part of the instruction.
3. The upper 5 bit of the destination address are the upper 5 bit of the current program
counter.
4. Hence, absolute addressing allows branching only within the current 2 Kbyte page of
the program memory.
Eg. AJMP LOOP1 ACALL LOOP2
8. Long Addressing
1. The long addressing mode is used with the instructions LJMP and LCALL. These are
3 byte instructions.
2. The address specifies a full 16 bit destination address so that a jump or a call can be
made to a location within a 64 Kbyte code memory space.
Eg. LJMP FINISH LCALL DELAY
1.11.1 PROGRAMS
1. Write a program to store data FFH into RAM memory locations 50H to 58H using
direct addressing mode
2. Write a program to store data FFH into RAM memory locations 50H to 58H using
indirect addressing mode.
Outcomes
CO1: Interpret the architectural features of 8051 microcontroller and its peripherals, Memory organization,
Memory interfacing and looping instructions. [L4, MODULE 1, 2]
CO2: Develop 8051 programs in assembly language to solve arithmetic and logical programs. [L3
MODULE 1, 2]
TEXT BOOKS:
1. The 8051 Microcontroller and Embedded Systems Using Assembly and C , Muhammad Ali Mazadi ,
Pearson 2nd Edition, 2008.
Reference Books
1. The 8051 Microcontroller, Kenneth Ayala, Cengage Learning , 3rd Edition, 2005
2. The 8051 Microcontroller and Embedded Systems ,Manish K Patel, McGraw Hill, 2014
Microcontrollers: Architecture, Programming, Interfacing and System Design, Raj Kamal , Pearson ,1st
Edition, 2012