Embedded Systems

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

e-PG Pathshala

Subject : Computer Science

Paper: Embedded System


Module: 8051 Architecture
Module No: CS/ES/5

Quadrant 1 – e-text

In this lecture the detailed architecture of 8051 controller, register bank, special purpose
registers, timers and memory elements of 8051 will be discussed.

1. 8051 Micro controller

The Microcontroller incorporates all the features that are found in microprocessor. It has built
in ROM, RAM, Input Output ports, Serial Port, timers, interrupts and clock circuit.
Microcontroller (MC) may be called computer on chip since it has basic features within single
chip. These are usually dedicated devices embedded within an application. For example,
microcontrollers are used as engine controllers in automobiles and as exposure and focus
controllers in cameras.

The I/O, memory, and on-chip peripherals of a microcontroller are selected depending on the
specifics of the target application. Since microcontrollers are powerful digital processors, the
degree of control and programmability they provide significantly enhances the effectiveness of
the application. The 8051 is the first microcontroller of the MCS-51 family introduced by Intel
Corporation at the end of the 1970s. The microcontroller has on chip peripheral devices. This
is widely used in washing machines, vcd player, microwave oven, robotics or in industries.
Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC. 8
bit microcontroller, means it can read, write and process 8 bit data. Ex. 8051 microcontroller.
Basically 8 bit specifies the size of data bus. 8 bit microcontroller means 8 bit data can travel
on the data bus or we can read, write process 8 bit data.

1.1 8051 Architecture

8051 micro controller is an 8 bit controller. Figure 1.1 shows the architecture diagram of
8051.

The 8051 microcontroller has the following features:

 4 Kb of ROM.
 128b of RAM (including SFRs) satisfies the user's basic needs.
 4 ports, each having 8 input/ouput lines, total of 32 input/output lines are present which
are sufficient to make all necessary connections to peripheral environment.
 It has Accumulator, general purpose registers and special purpose registers and
 It has ALU which does all kind of arithmetic and logical operations.
Figure 1.1 Architecture of 8051

The whole configuration is obviously thought of as to satisfy the needs of most programmers
working on development of automation devices. One of its advantages is that nothing is
missing and nothing is too much. In other words, it is created exactly in accordance to the
average user‘s taste and needs. Another advantages are RAM organization, the operation of
Central Processor Unit (CPU) and ports which completely use all recourses and enable further
upgrades.

Further it has eight general purpose registers namely R0, R1, R2, R3, R4, R5, R6, R7. All
are 8 bit wide and used as scratch pad. R0 and R1 are used as pointers in indirect addressing
mode. Accumulator is a very important register in 8051. In this figure ACC is the Accumulator
register. It is referred as A. It is holding one operand in arithmetic and logical instructions and
8 bit wide.

Next important register is B Register. The B register is used during multiply and divide
operations for other instructions it can be treated as another scratch pad register and 8 bit
length.

During program execution Program counter (PC) plays vital role. It is 16 bit length. Holds
address of the instruction to be execute next. It has many special purpose registers like PSW,
TMOD , SBUF etc.

1.2 Program Status Word (PSW)

(MSB) (LSB)
CY AC F0 RS1 RS0 OV - P
PSW (Fig 1.2) is a special purpose register. It is 8-bit wide. The PSW register contains
program status information execution. It shows the carry Flag and auxiliary carry flag and

Symbol Position Name and significance


CY PSW 7 Carry flag
AC PSW 6 Auxillary carry flag
( For BCD Operations)
F0 PSW 5 Flag 0
(Available to the user for general purposes)
RS1 PSW 4 Register bank select control bits 1 & 0. Set/Cleared by software
to determine working register bank(see Note).
RS0 PSW 3
ov PSW 2 Overflow flag
- PSW 1 (reserved)
P PSW 0 Parity flag
Set/cleared by hardware each instruction cycle to indicate and
odd/even number of "one" bits in the accumulator,i.e., even
parity
Note: The contents of (RS1,RS0) enable the working banks as follows
(0,0)- Bank 0(00H-07H)
(0,1)- Bank 1(08H-0FH)
(1,0)- Bank 2(10-17H)
(1,1)- Bank 3(18H-1FH)
F
Figure 1.2 PSW

overflow flag to indicate these information during program execution. If the MSB bit CY is 1,
then it indicates there is presence of carry that arrives during processing. While doing the
addition of two numbers and if there is overflow in the fourth bit, then the Auxillary carry
becomes 1. When a data is processed and the result obtained is zero, then Flag F0 is set as
1.Registers memory address also shown via RS0 and RS1 bits. OV is the Overflow flag. parity
flag indicated parity status, this bit is 1 based on odd and even parity.

1.3 Stack Pointer

The Stack Pointer register is 8 bits wide. It indicates the address of the stack. It is incremented
before data is stored during PUSH and CALL executions. It may reside anywhere in on-chip
RAM. The Stack Pointer is initialized to 07H after a reset. This causes the stack to begin at
location 08H.

1.4 Data Pointer

The Data Pointer (DPTR) consists of two registers namely high byte (DPH) and a low byte
(DPL). Its intended function is to hold a 16-bit address. It may be manipulated as a 16-bit
register or as two independent 8-bit registers. This register pair is used as a pointer for
addressing/accessing the external memory.
1.5 Ports 0 to 3

There are four parallel ports and two serial communication ports. Ports P0, P1, P2 and P3 are
the SFR latches of Ports 0, 1, 2 and 3, respectively. Port 1 is a simple I/O port. Port 0 and
Port 2 are simple I/O and address/data ports. These ports are used as multiplexed ports for
address and data communication for external memory access. Port 3 is a simple I/O port and
Multiple function assigned to each pins of this port.

All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as
inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to
be connected to peripheral devices are available for use.

Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends
on its logic state. In order to configure a microcontroller pin as an output, it is necessary to
apply a logic zero (0) to appropriate I/O port bit. In this case, voltage level on appropriate pin
will be 0.

Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic


one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the
case with any TTL input). This may seem confusing but don't loose your patience. It all
becomes clear after studying simple electronic circuits connected to an I/O pin.

1.5.1 Port 1

P1 is a true I/O port, because it doesn't have any alternative functions as is the case with P0,
but can be configured as general I/O only. It has a pull-up resistor built-in and is completely
compatible with TTL circuits.

1.5.2 Port 2
P2 acts similarly to P0 when external memory is used. Pins of this port occupy addresses
intended for external memory chip. This time it is about the higher address byte with
addresses A8-A15. When no memory is added, this port can be used as a general
input/output port showing features similar to P1.

1.5.3 Port 3
All port pins can be used as general I/O, but they also have an alternative function. In order to
use these alternative functions, a logic one (1) must be applied to appropriate bit of the P3
register. In terms of hardware, this port is similar to P0, with the difference that its pins have a
pull-up resistor built-in.

1.6 Serial Data Buffer (SBUF)

Serial data buffer supports serial communication. It is actually two separate registers, one
transmit buffer and one receive buffer register. When data is moved to SBUF, it goes to the
transmit buffer where it is held for serial transmission. When data is moved from SBUF, it
comes from the receive buffer. It acts as a interface between either transmitter or receiver to
the processor.
1.7 Timer Registers

Timer register pairs (TH0, TL0), (TH1,TL1), are the 16-bit counting registers for
Timer/Counters 0, 1 respectively. This can be operated as 8 bit /13bit/16 bit timers. It counts
the external negative transition also if it is configured as counter.

1.8 Control Registers

Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON contain control and
status bits for the interrupt system, the timer/counters, and the serial port. When the system
configured for interrupt based service then Interrupt Enable(IE) and TCON registers place
major role. IE is set to 1 for enabling the system to work on interrupt. SCON is used during
serial communication. TMOD is used during the timer/counter operation. These registers are
used to support, enable and to activate different processes which can be handled by 8051
microcontroller.

1.9 Memory

The 8051 has two types of memory and these are Program Memory and Data Memory.
Program Memory (ROM) is used to permanently save the program being executed, while Data
Memory (RAM) is used for temporarily storing data and intermediate results created and used
during the operation of the microcontroller. Depending on the model in use, at most a few Kb
of ROM and 128 or 256 bytes of RAM is used. However all 8051 microcontrollers have a 16-
bit addressing bus and are capable of addressing 64 kb memory. It is neither a mistake nor a
big ambition of engineers who were working on basic core development. It is a matter of smart
memory organization which makes these microcontrollers a real “programmers’ goody“.

1.9.1 Data Memory (128 bytes)

8051 has only 128 bytes. It has been used effectively and optimally as given below (Fig 1.3).

Figure 1.3 Data memory


Based on the bits (RS0, RS1) set at PSW register the register bank address is found from the
memory. The address of the memory ranges from 00-7F and data is stored on it. If (RS0,
RS1) is between 00-07,08-0F,10-17,18-1F (Fig 1.4) then the data is stored in register bank 0,
bank 1, bank2 and bank3 respectively. If (RS0,RS1) is between 20-2F, it is called as Bit-
addressable RAM. It is used to address data while doing processing. The major space from
30-7F is called as Scratch pad RAM in which all code can be moved here and the process can
be done. Program status word is used to refer the location of the registers.

Figure 1.4 Register bank and Address

Figure 1.5 PSW bank selection

If the program status word ( Fig 1.5) register (PSW.4, PSW.3) is (0,0) then the data is stored
in bank 0, if it is (0,1) , (1,0) and (1,1) then the data is stored in bank 1,bank 2 and bank3
respectively. External memory is interfaced through DPTR register. It has DPH and DPL
register pair combined to form 16 bit word.

1.10 Arithmetic and Logic unit ( ALU )

Arithmetic and logic unit is a 8 bit unit. It performs arithmetic and logical operations. For doing
addition operation minimum two operands are needed and one of the operand comes through
the accumulator and other one comes through the temporary register. After the addition
operation, data is send to another temporary register. For doing multiplication or division
operation the operands are put in Accumulator and B register. It also performs
Increment/decrement register contents. Sometimes the PC values can be incremented or the
data values can be decremented in the register.

1.11 Timers and counters

The microcontroller oscillator uses quartz crystal for its operation. As the frequency of this
oscillator is precisely defined and very stable, pulses are generated with same width, which
makes them ideal for time measurement. Such crystals are also used in quartz watches. In
order to measure time between two events it is sufficient to count up pulses coming from this
oscillator. That is exactly what the timer does. If the timer is properly programmed, the value
stored in its register will be incremented (or decremented) with each coming pulse, i.e. once
per each machine cycle. A single machine-cycle instruction lasts for 12 quartz oscillator
periods, which means that by embedding quartz with oscillator frequency of 12MHz, a number
stored in the timer register will be changed million times per second, i.e. each microsecond.

The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest,
their main purpose is to measure time and count external events. Besides, they can be used
for generating clock pulses to be used in serial communication, so called Baud Rate.

1.11.1 Clock circuit

Figure 1.6 Clock Circuit

8051b has crystal oscillators (Fig 1.6) which generates the clock pulses. The oscillator, in any
case, drives the internal clock generator, the clock generator provides the internal clocking
signals to the chip. The internal clocking signals are at half the oscillator frequency, and define
the internal phases, states, and machine cycles. External clocks can also be supported by the
controller. Machine cycle consists of 12 oscillator periods So each work done by the controller
in 1 machine cycle take 12 clock cycles.
2. Pinout Description

Figure 2.1 Pin configuration


Figure 2.1 shows the pin configuration of microcontroller 8051.

Pins 1-8: Port1 Each of these pins can be configured as an input or an output.
Pin 9: RS 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 Interrupt 0 input.
Pin 13: INT1 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: X2, X1 Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins. Instead of it, miniature ceramics
resonators can also be used for frequency stability. Later versions of microcontrollers operate
at a frequency of 0 Hz up to over 50 Hz.
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 register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state
of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its
previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is
performed by means of only one additional (and cheap) integrated circuit. In other words, this
port is used for both data and address transmission.
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.

3. Summary

In this lecture, the complete architecture of 8051 controller is discussed. Register bank and all
special purpose registers are briefly explained. Pin configuration of 8051, Program status
word, timer and its functions are also discussed.

4. References
1. The 8051 Microcontroller and Embedded Systems Using Assembly and C
Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D.McKinlay.

2. Intel 8051 Microcontroller manual

3. http://www.mikroe.com/

You might also like