Module 1
Module 1
SEMESTER- IV
Module-1
8051MICROCONTROLLER
Prepared by
Dr. KAVITHA N
Assistant Professor, Dept.of E&CEngg, RVITM,
Bengaluru
Module – 1
8051 Microcontroller
Microprocessor vs Microcontroller
• General-purpose microprocessors
• Must add RAM, ROM, I/O ports, and timers externally to make them functional as
shown in Fig 1.1.
• Have the advantage of versatility on the amount of RAM, ROM, and I/O ports
• Microcontroller
• The fixed amount of on-chip ROM, RAM, and number of I/O ports makes them ideal
for many applications in which cost and space are critical as shown in Fig 1.2.
• In many applications, the space it takes, the power it consumes, and the price per unit
are much more critical considerations than the computing power
Microprocessor Microcontroller
Microprocessor contains ALU, General Microcontroller contains the circuitry of
purpose registers, stack pointer, program microprocessor, and in addition it has built in
counter, clock timing circuit, interrupt circuit ROM, RAM, I/O Devices, Timers/Counters
etc.
It has many instructions to move data between It has few instructions to move data between
memory and CPU memory and CPU
Few bit handling instruction It has many bit handling instructions
Less number of pins are multifunctional More number of pins are multifunctional
Single memory map for data and code Separate memory map for data and code
(program) (program)
Access time for memory and IO are more Less access time for built in memory and IO.
Microprocessor based system requires It requires less additional hardware
additional hardware
More flexible in the design point of view Less flexible since the additional circuits which
is residing inside the microcontroller is fixed for
a particular microcontroller
Large number of instructions with flexible Limited number of instructions with few
addressing modes addressing modes
ECE, RVITM | Prepared By Dr.Kavitha N 1
BEC405A MICROCONTROLLER | MO DULE1:8051MICROCONTROLLER
8051 Architecture
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.
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.
PSW (Program Status Word). This is an 8 bit register which contains the arithmetic status of ALU
and the bank select bits of register banks.
The heart of the 8051 is the circuitry that generates the clock pulses by which all internal
operations are synchronized.
Pins XTALI and XTAL2 are provided for connecting a resonant network to form an
oscillator.
The 8051 requires an external oscillator circuit. The oscillator circuit usually runs
around 12MHz. the crystal generates 12M pulses in one second. The pulse is used to
synchronize the system operation in a controlled pace.
A machine cycle is minimum amount time a simplest machine instruction must take.
An 8051 machine cycle consists of 12 crystal pulses (ticks).
Instruction with a memory operand needs multiple memory accesses (machine cycles).
4 Prepared By Dr. Kavitha N | ECE, RVITM
MICROCONTROLLER | MODULE1:8051MICROCONTROLLER BEC405A
Typically, a quartz crystal and capacitors are employed, as shown in Fig 1.5.
• The A (accumulator) register is used for many operations, including addition, subtraction,
integer multiplication and division, and Boolean bit manipulations.
• The A register is also used for all data transfers between the 8051 and any external
memory.
• The B register is used with the A register for multiplication and division operations.
7 6 5 4 3 2 1 0
CY AC F0 RS1 RS0 OV - P
• Not all of the addresses from 80h to FFh are used for SFRs, and attempting to use an
address that is not defined, or "empty" results in unpredictable results.
• SFRs are named in certain opcodes by their functional names, such as A or TH0, and are
referenced by other opcodes by their addresses, such as 0E0h or 8Ch.
• Note that any address used in the program must start with a number; thus address E0h for the
A SFR begins with 0.
• Failure to use this number convention will result in an assembler error when the program is
assembled.
Pin Diagram
Pinout Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and clears the contents
of most registers. In other words, the positive voltage on this pin resets the
microcontroller. By applying logic zero to this pin, the program starts execution from
the beginning.
Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions
Pin 10 RXD. Serial asynchronous communication input or Serial synchronous
communication output.
Pin 11 TXD. Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12 INT0.External Interrupt 0 input
Pin 13 INT1. External Interrupt 1 input
Pin 14 T0. Counter 0 clock input
Pin 15 T1. Counter 1 clock input
Pin 16 WR. Write to external (additional) RAM
Pin 17 RD. Read from external RAM
Pin 18, 19 XTAL2, XTAL1. Internal oscillator input and output. A quartz crystal which
specifies operating frequency is usually connected to these pins.
Pin 20 GND. Ground.
Pin 21-28 Port 2. If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the
higher address byte, i.e. addresses A8-A15 will appear on this port. Even
though memory with capacity of 64Kb is not used, which means that not all
eight port bits are used for its addressing, the rest of them are not available as
inputs/outputs.
Pin 29 PSEN. If external ROM is used for storing program then a logic zero (0)
appears on it every time the microcontroller reads a byte from memory.
Pin 30 ALE. Prior to reading from external memory, the microcontroller puts the
lower address byte (A0-A7) on P0 and activates the ALE output. After
receiving signal from the ALE pin, the external latch latches the state of P0
and uses it as a memory chip address. Immediately after that, the ALE pin is
returned its previous logic state and P0 is now used as a Data Bus.
Pin 31 EA. By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It
means that even there is a program written to the microcontroller, it will not
be executed. Instead, the program written to external ROM will be executed.
By applying logic one to the EA pin, the microcontroller will use both
memories, first internal then external (if exists).
Pin 32-39 PORT 0. Similar to P2, if external memory is not used, these pins can be used
as general inputs/outputs. Otherwise, P0 is configured as address output (A0-
A7) when the ALE pin is driven high (1) or as data output (Data Bus) when
the ALE pin is driven low (0).
Pin 40 VCC. +5V power supply.
The lower order address and data bus are multiplexed. De-multiplexing is done by the latch. Initially
the address will appear in the bus and this latched at the output of latch using ALE signal. The output
of the latch is directly connected to the lower byte address lines of the memory. Later data will be
available in this bus. Still the latch output is address itself. The higher byte of address bus is directly
connected to the memory. The number of lines connected depends on the memory size.
The RD and WR (both active low) signals are connected to RAM for reading and writing the data.
PSEN of microcontroller is connected to the output enable of the ROM to read the data from the
memory as shown in fig 1.10.
EA (active low) pin is always grounded if we use only external memory. Otherwise, once the program
size exceeds internal memory the microcontroller will automatically switch to external memory.
The number of bits that a semiconductor memory chip can store is called chip capacity
o It can be in units of Kbits (kilobits), Mbits (megabits), and so on.
Memory chips are organized into a number of locations within the IC.
o Each location can hold 1 bit, 4 bits, 8 bits, or even 16 bits, depending on how it is
designed internally
The number of locations within a memory IC depends on the address pins
The number of bits that each location can hold is always equal to the number
of data pins
A memory chip contain 2x location, where x is the number of address pins.
Each location contains y bits, where y is the number of data pins on the chip.
The entire chip will contain 2x X y bits
Example 1.1
A given memory chip has 12 address pins and 4 data pins. Find:
(a) The organization, and (b) the capacity.
Solution:
a) This memory chip has 4096 locations (212 = 4096), and each location can hold 4
bits of data. This gives an organization of 4096 × 4, often represented as 4K × 4.
b) The capacity is equal to 16K bits since there is a total of 4K locations and each
location can hold 4 bits of data.
Example 1.2
A 512K memory chip has 8 pins for data. Find:
(a) The organization, and (b) the number of address pins for this memory chip.
Solution:
a) A memory chip with 8 data pins means that each location within the chip can hold
8 bits of data. To find the number of locations within this memory chip, divide the
capacity by the number of data pins. 512K/8 = 64K; therefore, the organization for
this memory chip is 64K × 8
b) The chip has 16 address lines since 216 = 64K
o In the case of the address buses, while the lower bits of the address from the CPU go
directly to the memory chip address pins, the upper ones are used to activate the CS pin
of the memory chip.
Normally memories are divided into blocks and the output of the decoder selects a given memory
block
o Using simple logic gates
o Using the 74LS138
o Using programmable logics
Following.
Solution :
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
The above shows that the range for Y4 is 4000H to 4FFFH. In the above figure, notice
that A15 must be 0 for the decoder to be activated. Y4 will be selected when
and 1
for the highest address.
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Above fig 1.15 shows how to connect or interface external RAM (data memory) to 8051.
Port 0 is used as multiplexed data & address lines. Address lines are decoded using external latch &
ALE signal from 8051 to provide lower order (A7-A0) address lines. Port 2 gives higher order address
lines. RD' & WR' signals from 8051 selects the memory read & memory write operations respectively.
Example 1.4: Design a controller system using 8051.Interface the external RAM of size 16k x 8.
Solution: Given, Memory size: 16k
That means we require 2n=16k :: n address lines
Here n=14 :: A0 to A13 address lines are required.
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.
Example 1.5: Design a controller system using 8051.Interface the external ROM of size 4k x 8.
Solution: Given, Memory size: 4k
That means we require 2n=4k :: n address lines
Here n=12 :: A0 to A11 address lines are required.
Remaining lines A12, A13, A14, A15 & 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.
****************************************************************************************