MPMC U 4
MPMC U 4
Microcontroller Microprocessor
Its designing and hardware cost is low. Its designing and hardware cost is high.
It is built with CMOS technology, which Its power consumption is high because it
requires less power to operate. has to control the entire system.
It consists of CPU, RAM, ROM, I/O ports. It doesn’t consist of RAM, ROM, I/O ports.
It uses its pins to interface to peripheral
devices.
Types of Microcontrollers
Applications of 8051:
Features of 8051:
8-bit ALU, Accumulator, 8-bit Registers and 8-bit data bus; hence it is an 8-
bit microcontroller
16-bit program counter (PC) and Data Pointer (DPTR)
8-bit Processor Status Word (PSW)
8-bit Stack Pointer
Internal RAM of 128bytes
Special Function Registers (SFRs) of 128 bytes
On chip ROM is 4KB
Special Function Registers (SFRs) of 128bytes
32 I/O pins arranged as four 8-bit ports (P0 -P3)
Two 16-bit timer/counters : T0 andT1
Two external and three internal vectored interrupts
Full duplex UART (serial port)
As we know that the CPU is the brain of any processing device of the
microcontroller. It monitors and controls all operations that are performed on the
Microcontroller units. The User has no control over the work of the CPU directly .
It reads program written in ROM memory and executes them and do the expected
task of that application.
Interrupts
Out of these, (INT0) ̅ and (INT1) ̅ are external interrupts that could be
negative edge triggered or low level triggered. When All these interrupts
are activated, set the corresponding flogs except for serial interrupt,. The
interrupt flags are cleared when the processor branches to the interrupt
service routine (ISR). The external interrupt flags are cleared when the
processor branches to the interrupt service routine, provides the interrupt
is a negative edge triggered whereas the timers and serial port interrupts
two of them are external interrupts, two of them are timer interrupts and
one serial port interrupt terminal in general.
Memory
BUS
Address Bus
Data Bus
Address Bus: Microcontroller 8051 has a 16 bit address bus for transferring the
data. It is used to address memory locations and to transfer the address from CPU
to Memory of the microcontroller. It has four addressing modes that are
Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry
data of particular applications.
Oscillator
Input/Output Port
Timers/Counters
8051 microcontroller has two 16-bit timers and counters. These counters are
again divided into a 8 bit register. The timers are used for measurement of
intervals to determine the pulse width of pulses.
Serial Port
TXD and RXD are utilized for serial port. Each pin has separate buffer registers
named as SBUF.
Out of these 128 Memory Locations (80H to FFH), there are only 21
locations that are actually assigned to SFRs. Each SFR has one Byte
Address and also a unique name which specifies its purpose.
Since the SFRs are a part of the Internal RAM Structure, you can access
SFRs as if you access the Internal RAM. The main difference is the
address space: first 128 Bytes (00H to 7FH) is for regular Internal RAM
and next 128 Bytes (80H to FFH) is for SFRs.
A or ACC
B
DPL
DPH
IE
IP
P0
P1
P2
P3
PCON
PSW
SCON
SBUF
SP
TMOD
TCON
TL0
TH0
TL1
TH1
I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
A or Accumulator (ACC)
B (Register B)
The B Register is used along with the ACC in Multiplication and Division
operations. These two operations are performed on data that are
stored only in Registers A and B. During Multiplication Operation, one
of the operand (multiplier or multiplicand) is stores in B Register and
also the higher byte of the result.
In case of Division Operation, the B Register holds the divisor and also
the remainder of the result. It can also be used as a General Purpose
Register for normal operations and is often used as an Auxiliary
Register by Programmers to store temporary results.
Flags are 1-bit storage elements that store and indicate the nature of
the result that is generated by execution of certain instructions. The
following image shows the contents of the PSW Register.
The following table describes the function of each flag.
Pointer Registers
DPTR doesn’t have a physical Memory Address but the DPL (Lower
Byte of DPTR) and DPH (Higher Byte of DPTR) have separate addresses
in the SFR Memory Space. DPL = 82H and DPH = 83H.
SP or Stack Pointer points out to the top of the Stack and it indicates
the next data to be accessed. Stack Pointer can be accesses using
PUSH, POP, CALL and RET Instructions. The Stack Pointer is an 8-bit
register and upon reset, the Stack Pointer is initialized with 07H.
When writing a new data byte into the stack, the SP (Stack Pointer) is
automatically incremented by 1 and the new data is written at an
address SP+1. When reading data from stack, the data is retrieved
from the Address in SP and after that the SP is decremented by 1 (SP-
1).
Each bit in these SFRs corresponds to one physical Pin in the 8051
Microcontroller. All these Port Registers are both Bit Addressable and
Byte Addressable. Writing 1 or 0 on a Port Register Bit will reflect as an
appropriate voltage (5V and 0V) on the corresponding Pin.
If a Port Bit is SET (declared as 1), the corresponding Port Pin will be
configured as Input and similarly if a Port Bit is CLEARED (declared as
0), the corresponding Port Pin is configured as Output. Upon reset, all
the Port Bits are SET (1) and hence, all the Port Pins are configured as
Inputs.
Peripheral Control Registers
During Idle Mode, the Microcontroller will stop the Clock Signal to the
ALU (CPU) but it is given to other peripherals like Timer, Serial,
Interrupts, etc. In order to terminate the Idle Mode, you have to use an
Interrupt or Hardware Reset.
In the Power Down Mode, the oscillator will be stopped and the power
will be reduced to 2V. To terminate the Power Down Mode, you have to
use the Hardware Reset.
Apart from these two, the PCON Register can also be used for few
additional purposes. The SMOD Bit in the PCON Register is used to
control the Baud Rate of the Serial Port.
There are two general purpose Flag Bits in the PCON Register, which
can be used by the programmer during execution.
The
7 SMOD Serial Comm. Baud Rate If 1, doubles the baud rate
Modify Bit using Timer 1. If 0, normal following
timer 1 baud rate. table
describes
6– —- — the
4
function
of each
3 GF1 General Purpose User Flag (Bit
1) bit in the
PCON
SCON Register also consists of bits that are automatically SET when a
byte of data is transmitted or received.
The following table describes the function of each bit in the SCON
Register.
The Serial Port Mode Selection Bits (SM0 and SM1) determine the mode
of UART and also the baud rate. The following table gives an overview
of how the Serial Port Mode Selection Bits can be used to configure
Serial Port (UART) of 8051.
(Frequency of oscillator
/ 12)
(Frequency of oscillator
/ 32 or Frequency of
oscillator / 64
The following table gives the description of each bit in the TCON SFR.
The TMOD or Timer Mode register or SFR is used to set the Operating
Modes of the Timers T0 and T1. The lower four bits are used to
configure Timer0 and the higher four bits are used to configure Timer1.
The following table gives a brief description of each bit in the TMOD
SFR.
IE (Interrupt Enable)
6 — —
5 ET2 Reserved
IP (Interrupt Priority)
6 — —
5 PT2 Reserved
The Serial Buffer or SBUF register is used to hold the serial data while
transmission or reception.
The TL1 and TH1 are the lower and higher bytes of the Timer 0.