DEE S5 MPMC Unit4
DEE S5 MPMC Unit4
SEMESTER: 5
CODE: EE/S5/MPMC
Sarmistha Sengupta
Lecturer in Electrical Engineering
The Calcutta Technical School
Introduction:
A Microcontroller is a device which contains all the devices necessary to form a working system in a
single chip. Therefore, inside the microcontrollers, we find a central processing unit (CPU), memory
(program memory and data memory), I/O ports (input / output ports), timers, serial communication
interface etc.
Applications:
• Consumer electronics products: Toys, Cameras, Robots, Washing Machine, Microwave Ovens etc.
• Medical instruments: ECG Machine etc.
• Communication: Cell Phones, Telephone Sets, Answering Machines etc.
• Office equipment: Fax, Printers etc.
• Multimedia application: MP3 Player etc.
• Automobile: Speedometer, Auto-breaking system etc.
• Instrumentation and process control: Oscilloscopes, Multi-meter, Leakage Current Tester, Data
Acquisition and Control etc.
• 8-bit CPU
• Extensive Boolean processing capabilities
• 64K Program Memory address space
• 64K Data Memory address space
• 4K bytes of on-chip Program Memory
• 128 bytes of on-chip Data RAM
• 32 bidirectional and individually addressable I/O lines
• Two 16-bit timer/counters
• Full duplex UART
• 6-source/5-vector interrupt structure with two priority levels
• On-chip clock oscillator (Maximum internal clock frequency is 12MHz)
Architecture of 8051:
8051 microcontroller is an 8-bit microcontroller. It is built with 40 pins DIP (dual inline package), 4KB
of ROM storage and 128 bytes of RAM storage, two 16-bit timers. It consists of four parallel 8-bit ports,
which are programmable as well as addressable as per the requirement. An on-chip crystal oscillator is
integrated in the microcontroller having crystal frequency of 12MHz.
In the above diagram, the CPU connects with all on-chip peripheral using the system bus.
System Bus:
• The bus is a collection of wires which work as a communication channel or medium for transferring
the data.
• In 8051, the system bus consists of an 8-bit data bus, a 16-bit address bus and bus control signals.
Timers/Counters:
• A timer is used to generate the delay and counter is used to count the events happening outside of
the microcontroller.
• 8051 microcontroller has two 16 bit timers/counters.
Interrupts:
• An interrupt is an external or internal event that interrupts the microcontroller to inform it that a
device needs its service.
• The 8051 microcontroller has 6-source/5-vector location based interrupt structure with two priority
levels.
Program Counter:
• Program counter points to the address of the next instruction to be executed. After execution of one
instruction, the program counter is incremented to point to the address of the next instruction to be
executed.
• 8051 has 16-bit program counter so it can address from 0000H to FFFFH, a total of 64K bytes of
code.
Registers:
• 8051 microcontroller contains 34 general purpose registers or working registers. Two of them are
called math registers A & B and 32 are bank of registers.
Memory Organisation:
• In 8051, the memory is organised logically into program memory and data memory separately.
• The program memory is read only type.
• The data memory is organised as read-write memory.
• Both program and data memories can be within or outside the chip.
Program Memory:
o The program memory can be up to 64K bytes long.
o The lower 4K may reside on-chip.
o The user can configure the entire program memory outside the chip or use 4KB inside and
60KB outside the chip.
Data Memory:
o The 8051 has 128 bytes of on-chip RAM plus a number of Special Function Registers (SFRS).
o The lower 128 bytes of RAM can be accessed either by direct addressing or by indirect
addressing.
o The 8051 can address up to 64K bytes of data memory external to the chip. The “MOVX”
instruction is used to access the external data memory.
o The 128 bytes of RAM which can be accessed by both direct and indirect addressing can be
divided into 3 segments:
▪ Register Banks 0-3: The lowest 32 bytes are grouped into 4 banks of 8 registers. Program
instructions call out these registers as R0 through R7. Two bits in the Program Status Word
(PSW) select which register bank is in use.
▪ Bit Addressable Area: The next 16 bytes above the register banks form a block of bit-
addressable memory space. This bit-addressable memory is both bit-addressable (from 00H
to 7FH) and byte-addressable (from 20H to 2FH).
▪ Scratch Pad Area: Bytes 30H through 7FH are available to the user as data RAM.
• SFRs, which occupy the upper 128 bytes of the internal memory, are the registers that control the
entire processor.
• They can be accessed only by direct addressing.
Accumulator (A-register):
o It is 8 bit register.
o Result of arithmetic and logic operations performed by ALU is accumulated by this register.
B-register:
o It is special 8 bit math register.
o It is used during multiplication and division operations.
o For other instructions it can be treated as another scratch pad register.
▪ Carry flag (CY): During addition and subtraction if any carry or borrow is generated then
carry flag is set otherwise carry flag resets.
▪ Auxiliary carry flag (AC): If during addition and subtraction any carry or borrow is
generated from lower 4 bit to higher 4 bit then AC sets else it resets. It is used in BCD
arithmetic operations.
▪ Overflow flag (OV): This flag is set whenever the result of a signed number operation is
too large, causing the high order bit to overflow into the sign bit. In other words, this flag
is set in 8-bit signed number operation if there is a carry from D6 to D7 or from D7 out, but
not both.
▪ Parity flag (P): If the A register contains odd number of ones ("1"), then parity flag sets. If
A has even number of ones ("1"), then parity flag resets.
▪ FO: It is user defined flag. The user defines the function of this flag.
▪ RS1 and RS0: These flags are used to select register bank by resetting those flags which
are as shown in table:
Timer/Counter register:
o Byte-addressable
o 8051 has two 16-bit timer/counter registers T0 and T1. Each register is divided into lower (TL0,
TL1) and higher byte registers (TH0, TH1).
o These registers are used to hold initial number of count.
SP (Stack Pointer):
o Stack Pointer points out to the top of the Stack and it indicates the next data to be accessed.
o SP can be accessed using PUSH, POP instructions.
o It is an 8-bit register and upon reset, the Stack Pointer is initialized with 07H.
o 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.
o 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).
Control Registers:
o Special Function Registers IE, IP, TMOD, TCON, SCON and PCON contain control and status
bits for the interrupt system, the timer/counters and the serial port.
IE (Interrupt Enable):
o Bit –addressable
o If the bit is 0, the corresponding interrupt is disabled. If the bit is 1, the corresponding interrupt
is enabled.
IP (Interrupt Priority):
o Bit –addressable
o If the bit is 0, the corresponding interrupt has a lower priority. If the bit is 1, the corresponding
interrupt has a higher priority.
▪ GATE: When TRx (in TCON) is set and GATE = 1, TIMER/COUNTERx will run only while
INTx pin is high (hardware control). When GATE = 0, TIMER./C0UNTERx will run only
while TRx = 1 (software control).
▪ ̅: Timer or Counter selector. Cleared for Timer operation. Set for Counter operation.
C/T
▪ M1: Mode selector bit
▪ M0: Mode selector bit
▪ TFl: Timer 1 overflow flag. Set by hardware when the Timer/Counter 1 overflows. Cleared by
hardware as processor vectors to the interrupt service routine.
▪ TR1: Timer 1 run control bit. Set/cleared by software to turn Timer/Counter 1 ON/OFF.
▪ TF0: Timer 0 overflow flag. Set by hardware when the Timer/Counter 0 overflows. Cleared by
hardware as processor vectors to the service routine.
▪ TR0: Timer0 run control bit. Set/cleared by software to turn Timer/Counter 0 ON/OFF.
▪ IE1: External Interrupt 1 edge flag. Set by hardware when External Interrupt edge is detected.
Cleared by hardware when interrupt is processed.
▪ ITI: Interrupt 1 type control bit. Set/cleared by software to specify falling edge/low level
triggered External Interrupt.
▪ IE0: External Interrupt 0 edge flag. Set by hardware when External Interrupt edge detected.
Cleared by hardware when interrupt is processed.
▪ IT0: Interrupt 0 type control bit. Set/cleared by software to specify falling edge/low level
triggered External Interrupt.
SCON (Serial Port Control): Bit –addressable
▪ SMOD: Double baud rate bit. If Timer 1 is used to generate baud rate and SMOD = 1, the baud
rate is doubled when the serial port is used in modes 1, 2, or 3.
▪ —: Not implemented, reserved for future use
▪ GF1: General purpose flag bit
▪ GF0: General purpose flag bit
▪ PD: Power Down bit. Setting this bit activates Power Down operation in the 80C51BH.
▪ IDL: Idle Mode bit. Setting this bit activates Idle Mode operation in the 80C51BH.
• VCC (Pin number 40): 8051 operates on +5V of the supply voltage. Thus this pin is solely assigned
to VCC at which the supply voltage is provided.
• GND (Pin number 20): This pin is allotted to ground, that passes the excess current of the
microcontroller to the ground.
• Port 0 (Pin number 32 to 39): These eight pins acts as bidirectional I/O ports as well as multiplexed
data and address bus. Here lower order address and data bus (i.e., AD0 to AD7) are multiplexed
together with the I/O ports.
• Port 1 (Pin number 1 to 8): These pins are assigned specifically to bidirectional I/O ports.
• Port 2 (Pin number 21 to 28): These pins are assigned to bidirectional I/O port 2. Also when external
memory is needed to be accessed then these pins act as higher order address bus (i.e., A8 to A15).
• Port 3 (Pin number 10 to 17): These pins are bidirectional I/O ports. Along with this, all the pins in
port 3 act as multipurpose pins. This means despite serving as I/O port, these pins also hold some
special function, which is stated below:
o P3.0 (RXD): This pin is used for serial port to receive the data in UART mode. While in shift
register mode, it acts as data I/O pin.
o P3.1 (TXD): This is another pin for serial port that is used to transmit data in UART mode.
However, in shift register mode, it acts as clock output.
o ̅̅̅̅̅̅̅): It is the interrupt 0 input pin which shows the presence of an interrupt when an
P3.2 (INT0
active low signal is generated at this pin.
o ̅̅̅̅̅̅̅): It is the interrupt 1 input pin, which when goes active low shows the existence of
P3.3 (INT1
interrupt in the system.
o P3.4 (T0): This pin is assigned to timer 0 of the microcontroller. An active high signal at this
pin indicates that the system is producing a time delay.
o P3.5 (T1): This pin is allotted to timer 1.
o ̅̅̅̅̅): This pin gets active whenever a write operation is performed. This means an active
P3.6 (WR
low signal at this pin indicates that write operation is being executed at the external memory.
o ̅̅̅̅): This pin is used to show the read operation. Basically, the hardware generates an
P3.7 (RD
active low signal at the pin for the case of read operation from the external memory.
• XTAL 2 and XTAL 1 (Pin number 18 and 19 respectively): These two pins are allotted for internal
clock signalling. The external oscillator forms a connection to these two pins so as to have an
internal clock signal to the system.
• RST (Pin number 9): This pin gets active high whenever the microcontroller is required to be set to
its initial state. Basically, in order to have proper reset operation of the microcontroller, at the time
of running oscillator, this pin signal must be kept high for two consecutive machine cycle.
• ̅̅̅̅̅̅̅
PSEN (Pin number 29): PSEN is an abbreviation for program store enable. An active low signal at
this pin shows that read operation is being executed from external program memory i.e.,
ROM/EPROM.
• ALE (Pin number 30): It is an address latch enable pin. An active high signal at this pin represents
the presence of address in the multiplexed address and data bus.
• ̅̅̅̅
EA/VPP (Pin number 31): EA is used for External Access. Whenever there is a need to access the
program from external memory, then signal at this pin must be active low. While in case the code
is not accessed by the external memory then it has an active high signal. Sometimes when flash
programming is executed in the microcontroller, then programming enable voltage of 12V is
applied at this pin.