0% found this document useful (0 votes)
54 views12 pages

DEE S5 MPMC Unit4

The document provides an overview of microcontrollers, specifically focusing on the 8051 microcontroller, including its architecture, features, and applications. It compares microcontrollers with microprocessors, detailing the evolution of microcontrollers and their components such as CPU, RAM, ROM, and various registers. Additionally, it discusses the memory organization and special function registers that control the microcontroller's operations.

Uploaded by

sumitradas.abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views12 pages

DEE S5 MPMC Unit4

The document provides an overview of microcontrollers, specifically focusing on the 8051 microcontroller, including its architecture, features, and applications. It compares microcontrollers with microprocessors, detailing the evolution of microcontrollers and their components such as CPU, RAM, ROM, and various registers. Additionally, it discusses the memory organization and special function registers that control the microcontroller's operations.

Uploaded by

sumitradas.abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

DEPARTMENT OF ELECTRICAL ENGINEERING

SEMESTER: 5

SUBJECT: MICROPROCESSOR AND MICROCONTROLLER

CODE: EE/S5/MPMC

UNIT 4: MICROCONTROLLER BASICS

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.

Comparison between microprocessor and microcontroller:

Sl. No. Microprocessor Microcontroller


Microprocessor is a general purpose Microcontroller is a dedicated chip
1
device which is called a CPU. which is called single chip computer.
Microcontroller includes RAM, ROM,
Microprocessor does not contain on chip
2 I/O ports, timers, serial communication
memory, I/O ports, timers etc.
interface etc. on a single chip.
Microcontrollers are commonly used in
Microprocessors are most commonly small, medium component designs
3
used as CPU in microcomputer system. performing control-oriented
applications.
Microprocessor based system design is Microcontroller based system design is
4
complex and expensive. simple and cost-effective.
5 Few instructions handle individual bit. Extensive bit handling capabilities.
Large number of memory related Small number of memory (external)
6
instructions and hence relatively slower. related instructions and hence faster.
Evolution of microcontrollers:

Year Microcontroller Comments


1974 TMS 1000 8-bit microcontroller
1976 MCS-48 8-bit microcontroller
1980 8051 8-bit microcontroller
1982 8096 (MCS-96) 16-bit microcontroller
PIC Microcontrollers by
1985 8-bit microcontroller
Microchip
8-bit RISC
1997 Atmel 8 bit AVR family
microcontrollers

Features of 8051 microcontroller:

• 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.

CPU (Central Processing Unit):


• It is the brain of the microcontroller.
• It executes information stored in memory and manages all processes that are carried out in the
microcontroller.

RAM (Random Access Memory):


• It is a volatile memory.
• It stores data and information temporarily while the computer is running. The data is lost when the
power is off.
• In 8051 microcontroller 128 byte internal RAM is available.

ROM (Read Only Memory):


• It stores data permanently.
• The 8051 microcontroller has 4K byte of code memory or program memory.

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.

Input / Output Port:


• The 8051 microcontroller has 4 ports for input and output operation.

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.

Oscillator and clock generator:


• All operations in a microcontroller are synchronized by the help of an oscillator clock. The oscillator
clock generates the clock pulses by which all internal operations are synchronized.
• A resonant network connected through pins XTAL1 and XTAL2 forms up an oscillator. For this
purpose a quartz crystal and capacitors are employed.

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.

Special function Registers (SFR):

• 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.

PSW (Program Status Word):


o Bit-addressable
o It is 8 bit register.
o It has 4 conditional flags (CY, AC, OV & P) and 3 control flags.

▪ 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:

I/O Port Registers:


o 8051 Microcontroller has four ports (P0, P1, P2 and P3) which can be used as input and/or
output.
o Each port has a corresponding register with same names (the Port Registers are also P0, P1, P2
and P3).
o All these port registers are both bit-addressable and byte-addressable.
o 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.
o Upon reset, all the port bits are SET (1) and hence, all the port pins are configured as inputs.
SBUF (Serial Data Buffer):
o Byte-addressable
o The Serial Data Buffer is actually two separate registers - a transmit buffer and a receive buffer
register.
o When data is moved to SBUF, it goes to the transmit buffer where it is held for serial
transmission.
o When data is moved from SBUF, it comes from the receive buffer.

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).

DPTR (Data Pointer):


o The Data Pointer is a 16-bit register and is physically the combination of DPL (Data Pointer
Low) and DPH (Data Pointer High) SFRs.
o The Data Pointer can be used as a single 16-bit register (as DPTR) or two 8-bit registers (as
DPL and DPH).
o 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.
o The DPTR register is used by the programmer addressing external memory.

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.

▪ EA: Disables all interrupts. If EA = 0, no interrupt will be acknowledged. If EA = 1, each


interrupt source is individually enabled or disabled by setting or clearing its enable bit.
▪ —: Not implemented, reserved for future use
▪ ET2: Enable or disable the Timer 2 overflow or capture interrupt (8052 only)
▪ ES: Enable or disable the serial port interrupt
▪ ET1: Enable or disable the Timer 1 overflow interrupt
▪ EX1: Enable or disable External Interrupt 1
▪ ET0: Enable or disable the Timer 0 overflow interrupt
▪ EX0: Enable or disable External Interrupt 0

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.

▪ PT2: Defines the Timer 2 interrupt priority level (8052only)


▪ PS: Defines the Serial Port interrupt priority level
▪ PT1: Defines the Timer 1 interrupt priority level
▪ PX1: Defines External Interrupt 1 priority level
▪ PT0: Defines the Timer 0 interrupt priority level
▪ PX0: Defines the External Interrupt 0 priority level

TMOD (Timer / Counter Mode Control Register): Not bit-addressable

▪ 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

TCON (Timer / Counter Control Register): Bit-addressable

▪ 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

▪ SM0: Serial port mode specifier


▪ SM1: Serial port mode specifier
▪ SM2: Enables the multiprocessor communication feature in modes 2 and 3
▪ REN: Set/Cleared by software to enable/disable reception
▪ TB8: Transfer bit 8
▪ RB8: Receive bit 8
▪ TI: Transmit interrupt flag. Set by hardware at the beginning of the stop bit in mode 1. Must be
cleared by software.
▪ RI: Receive interrupt flag. Set by hardware halfway through the stop bit time in mode 1. Must
be cleared by software.

PCON (Power Control Register): Not 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.

Pin diagram of 8051:

• 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.

You might also like