UNIT - 5 MP&I
UNIT - 5 MP&I
MICROCONTROLLER
Introduction:
The 8051 microcontroller was invented in 1980's by Intel. Its foundation is based
on Harvard architecture and this microcontroller was developed principally for
bringing it to be used in Embedded Systems.
At first it was created by using NMOS technology but the use of NMOS
consumed more power to work therefore Intel re-launch the microcontroller 8051
using CMOS technology and new edition came up with edition of letter 'C' in the
title name, therefore the new modified version of microcontroller is called by
name 80C51.
The 8051 microcontroller programming is performed in embedded C
language using Keil software.
A microprocessor is a A microcontroller is a
processor where the memory controlling device wherein the
What is it?
and I/O component are memory and I/O output
connected externally. component are present internally.
Memory and The memory and I/O The memory and I/O
I/O components are to be components are available.
components connected externally.
Data Types: In 8051, there is only one data type of 8 bits, from the MSB (most
significant bit) D7 to the LSB (least significant bit) D0. With an 8-bit data type,
any data type larger than 8-bit must be broken into 8-bit chunks by the
programmer before it is processed.
Registers:
8051 microcontrollers mainly contain two types of registers:
1. General-purpose registers (Byte addressable registers)
2. Special function registers (Bit addressable registers)
8051 microcontrollers basically consist of 256 bytes of RAM (Random Access
Memory), which is divided into two parts, first part contain 128 bytes for general
purpose Register these are byte addressable registers and second part contain 128
bytes for special function registers (SFR) memory these are bit addressable
registers.
The part of memory which is used for general purpose is called as RAM, and the
memory used for Special Function Register (SFR) contains all the peripheral
related registers like Accumulator, ‘B’ register, Timers or Counters, and interrupt
related registers.
General Purpose Registers:
We know that a register is a storage element that can be store bits of information.
8051 microcontroller has 4 registers bank. These are B0, B1, B2, and B3 stand
for Bank0, Bank1, Bank2, Bank3 respectively and each bank contains eight
general purpose registers ranging from ‘R0’ to ‘R7’.
These are 32 general purpose registers address from 00h to 1Fh.
The address range of Register Bank 0 (00 h to 07 h)
The address range of Register Bank 1 (08 h to F h)
The address range of Register Bank 2 (10 h to 17 h)
The address range of Register Bank 3 (18 h to 1F h)
These Register Banks are selected with the help of PSW (Program Status Word)
Register bits i.e., RS0, RS1.
Accumulator (A register):
It is an 8-bit register.
It holds a data and receives the result of the arithmetic instructions.
ACC is usually accessed by direct addressing and its physical address
is E0H. Accumulator is both byte and bit addressable. if you want to
access the second bit (i.e bit 1), you may use E1H and for third bit E2H
and so on.
B Register:
It is 8-bit register.
It is bit and byte-addressable register.
You can access 1-bit or all 8-bits by a physical address F0h. Suppose to
access a bit 1, we have to use f1.
The B register is only used for multiplication and division arithmetic
operations.
PSW Register
PSW Register Bits
Timer/Counter Registers:
The 8051 has two 16-bit Programmable timers / counters (Timer 0 -Timer 1).
Which can be used either as timer to generate a time delay or as counter to
count events happening outside the microcontroller.
The Counters and Timers in 8051 microcontrollers contain two special
function registers: TMOD (Timer Mode Register) and TCON (Timer Control
Register).
TMODE Registers:
TMODE register is an 8-bit register.
Gate: when Gate control is set. Timer/counter is enable only while the
INTx pin is high and the TRx control pin is set. When it is cleared, the
timer is enabled whenever the TRx control bit is set.
C/T: The Timer or counter selection. When cleared for timer operation
(input from internal system clock). Set for counter operation (input from
Tx input pin).
Mode selects bits of TMODE register: The M1 and M0 are mode select
bits, which are used to select the timer operations. There are four modes to
operate the timers.
SP (Stack Pointer):
The stack is a portion of a RAM Used by the CPU to store data or memory
address on temporary basis.
The stack pointer register is used to access the stack is known as SP register.
The stack pointer register is 8-bits wide. It can take a value of 00 to FFH.
The RAM memory location 08H is the first location used for the stack. When
the 8051 microcontroller is initialized, the SP register contains the value
07H.
If we want to store CPU register data into the stack this is known as PUSH
operation and if we getting the data from stack back into a CPU register this
is known as a POP operation.
Pins 18 and 19 (XTAL 2 and XTAL 1): The pins connecting an external oscillator are
18 and 19, or XTAL 2 and XTAL 1, respectively. A Quartz Crystal Oscillator is often
attached here.
Pin 20 (GND): The ground pin on an 8051 microcontroller is pin 20, or GND. It
connects to the power supply's negative terminal (0V), representing 0V.
Pins- 21-28 (P2.0-P2.7) (A8-A15): The PORT 2 Pins on the 8051 Microcontroller are
Pins 21 through 28. The PORT 2 pins function as either inputs or outputs because it is
a bidirectional port. Additionally, PORT 2 pins work as the higher-order address byte
when external memory is interfaced.
Pin 29 (PSEN): Program Store Enable, often known as PSEN, is used to interpret
signals from external program memory.
Pin 30 (ALE): It is also known as Address Latch Enable or ALE and is used to
demultiplex the port 0 address data indication (for external memory interfacing).
Pin 31 (EA): This is EA pin which stands for External Access input. It is used to
enable/disable the external memory interfacing.
Pins 32 to 39 (P0.7 - P0.0): Pins 32 to 39 are known as Port 0 (P0.7 - P0.0), and they
are multiplexed with low-order data/address bus signals (AD7-AD0) to act as
input/output ports (to provide the use of outer memory interfacing).
Pin 40 (VCC): The circuit receives power supply voltage, or +5 Volts, from this pin, V CC
(Voltage Common Collector).
After a reset, the program counter is loaded with 0000H but the content of on-chip
RAM is not affected.
Clock Circuit of 8051:
An 8051 clock circuit is shown above. In general cases, a quartz crystal is used
to make the clock circuit. The connection is shown in figure (a) and note the
connections to XTAL 1 and XTAL 2. In some cases, external clock sources are
used and you can see the various connections above. Clock frequency limits
(maximum and minimum) may change from device to device. Standard practice
is to use 12MHz frequency. If serial communications are involved then its best to
use 11.0592 MHz frequency.
Okay, take a look at the above machine cycle waveform. One complete oscillation
of the clock source is called a pulse. Two pulses forms a state and six states forms
one machine cycle. Also note that, two pulses of ALE are available for 1 machine
cycle.
8051 Memory Organization:
The 8051 microcontroller's memory is divided into Program Memory and Data
Memory. Program Memory (ROM) is used for permanent saving program being
executed, while Data Memory (RAM) is used for temporarily storing and keeping
intermediate results and variables.
Program Memory (ROM):
Program Memory (ROM) is used for permanent saving program (CODE) being
executed. The memory is read only. Depending on the settings made in compiler,
program memory may also use to store a constant variable. The 8051 executes
programs stored in program memory only. code memory type specifier is used to
refer to program memory.
8051 memory organization allows external program memory to be added.
How does the microcontroller handle external memory depends on the pin EA
logical state.
The entire timing of a machine cycle of 8031/8051 is divided into 6 states and
they are denoted as S1, S2, S3, S4, S5 and S6. The timing of each state is two
clock periods and they are denoted as P1 and P2.A state in a machine cycle is a
basic time interval for discrete operation of the microcontroller such as fetching
an opcode byte, decoding an opcode, executing an opcode, writing a data, etc.
The time taken to execute a machine cycle is 12 clock periods and so the time
taken to execute an instruction is obtained by multiplying the number of machine
cycles of that instruction by 12 clock periods.
Instruction execution time = C × 12 × T
= C × 12 × 1/f
where, C = Number of machine cycles of an instruction.
T = Time period of crystal frequency in seconds.
f = Crystal frequency in Hz
The 8051 microcontroller has four machine cycles. These are:
1. External program memory fetch cycle
2. External data memory read cycle
3. External data memory write cycle
4. Port operation cycle
The timing diagram provides information about the various conditions of the
signal while a machine cycle is executed. The following section describes the
timing diagram of the various machine cycles.
THE END