You are on page 1of 46

Microcontroller

8051

By
Siddhasen R Patil
Microcontroller 8051
Agenda
1. Features
2. Architecture
3. On chip Memory
4. Special Function Register
5. I/O Ports
6. Timer
7. Serial Interface
8. Interrupt
9. Power On Reset
10. Power Saving Modes
Features of 8051
Microcontroller 8051

Features:
1) 8-bit microcontroller
2) Operating speed 12MHz
3) Four 8-bit I/O Ports
4) Two 16-bit Timers
5) UART with variable baud rate
6) 128 Bytes RAM
7) 4K Bytes EPROM
8) 5 Interrupt Sources
9) Two Power Control Modes
10) Ideal Mode
11) Power down Mode
Features:
1) 8 bit Microcontroller
-ALU performs 8 bit operation on either Arithmetic
or Logical operation
- Internal Data bus is of 8-bit

8-bit 8-bit

ALU Accumulator B-Register

8-bit
Features:
8051

2) Operating speed
- 8051 operates on 12MHz
- On chip Oscillator XTAL2

XTAL2
Features:
8051

2) Operating speed
- 8051 operates on 12MHz
- On chip Oscillator Xtal2

Xtal2
Features:
3) Four 8-bit I/O Ports
- All ports Bidirectional
- Each bit consist latch, input buffer and output driver

Port2 Port0

` Port3 Port1
Features:
4) Two 16-bit Timers
- Two 16-bit Timer/Counter Registers
- Both Timers Operates Separately any one mode
out of 4 Modes
- Both Timers/Counter Interrupts µC on Terminal Count

Clk Timer/Counter 0 Interrupt

Clk Timer/Counter 1 Interrupt


Features:
5) UART with variable baud rate
- Serial Port Full Duplex
- Serial Port can Operate in 4 Modes

TxD

RxD
Features:
6) 128 Bytes of internal On Chip RAM
- 4 Register Bank (Each bank is of 8 Register)
- Bit addressable locations 20h to 27H
- Remaining part of Memory can use as scratch pad memory

7F

Scratch Pad
Memory
28

Bit Addressable 20 to 27

Register Bank0 1F
to Bank3

00
Features:
7) 4K Bytes EPROM
- User can use either 4KB Internal Memory
with 60KB External or 64KB External Memory
- To distinguish either Internal or External Memory
EA pin is used

8051
EA Address
64KB
EPROM
4KB Data
ROM
Features:
8) 5 Interrupt Sources
- Two External Interrupts i.e. INT0 and INT1
- Two Interrupts from Timer 0 and Timer 1
- One Interrupt by UART

8051
INT 0
TF0
INT 1 TF1

RI or TI
Features:
9) Two Power Control Modes
- Ideal Mode (oscillator runs UART, Interrupt, and Timer blocks),
but clock signal gated off to the CPU
- Power Down Mode (Oscillator frozen)
Features:
9) Two Power Control Modes
- Ideal Mode (oscillator runs UART, Interrupt, and Timer blocks),
but clock signal gated off to the CPU
- Power Down Mode (Oscillator frozen)
Architecture of 8051
Microcontroller 8051
Architecture:
1) 128 Byte on chip data memory
2) Special function register
3) Four 8-bit I/O Port
4) Timers and counters
5) Serial Interface
6) Interrupts
7) Reset
8) Power Saving Modes
Architecture
Onchip Memory of 8051
On chip Memory
1) 128 Byte on chip data memory
On chip Memory
2) Special function register
- The register in between memory location 80H to FFH are use as a SFR
- The unused locations are shown by blank and must not be used by 8051 programmer.
Special Function Register
Accumulator: 8 bit Register
B Register: Use during Multiply and Divide operation
Programmable Status Word: Contains Program Status Information
Special Function Register
Stack Pointer:
- Points Stack Memory.
- Increment during PUSH operation and decrement during
POP operation.
- Initialized 07H after reset so Stack memory starts from 08H.
Data Pointer (DPTR):
- Consist of High (DPH) and Low (DPL) Byte.
- Holds 16 bit address of external memory.
Port Registers (P0 , P1 , P2 , P3):
- P0 to P3 are SFR latches of ports P0 to P3 respectively.
Serial Data Buffer:
- These are two separate register i.e. Transmit Buffer and Receive Buffer.
- When data moved to SBUF it goes to Transmit Buffer.
- When data moved from SBUF it comes from Receive Buffer.
Timer Register:
- These are 16-bit counter register.
Control Registers:
- IP, IE, TMOD, TCON, SCON, PCON contains control and status bits.
I/O Port
Four 8-bit I/O Port
Port0 and Port2 are also used to access external memory
Port3 pins are multifunction that are listed below

Timer/Counter0 External
P3.0 RxD Serial input Pin P3.4
Input
Timer/Counter1 External
P3.1 TxD Serial output Pin P3.5
Input
Wr External Memory Write
P3.2 Int0 External Interrupt0 P3.6
Strobe
Rd External Memory Read
P3.3 Int1 External Interrupt1 P3.7
Strobe
I/O Port
Port 0
All 8 pins can be used either Input or Output
Need to connect external Pull-up resistor since P0 is an Open drain port

Vcc

10K

8051

Port 0
I/O Port
Port 0
- To make Port0 as a input port, port must be programmed by writing ‘1’
to all bits.
I/O Port
Port 0
- To make Port0 as a input port, port must be programmed by writing ‘1’
to all bits.
- What happened if we write ‘0’ before reading ?
- Port0 is also used to access external memory
I/O Port
Port 1
- All 8 pins can be used either Input or Output.
- Need not to connect external Pull-up resistor since P1 has internal
pull up resistor.
- To make Port1 as a input port, port must be programmed by writing ‘1’ to all bits.
I/O Port
Port 2
- All 8 pins can be used either Input or Output.
- Need not to connect external Pull-up resistor since P1 has internal
pull up resistor.
- Port 2 is also used to access external memory
I/O Port
Port 3
- All 8 pins can be used either Input or Output.
- Need not to connect external Pull-up resistor since P1 has internal
pull up resistor.
- Port 3 has some additional functions like RxD, TxD, Int0, Int1, T0, T1,
Wr, and Rd.
Timer/Counter
- 8051 has two 16 bit Timers (Timer0 and Timer1)
- Both can be operated either as Timer or event Counter
- In Timer function Timer counts machine cycle
- So Timer increments by1 after every 12 oscillator cycle (1/12)
- In Counter function Counter increments by 1 in the response
to 1-to-0 transition at external input pin i.e. T0 or T1.
- Timer/Counter operates in 4 different modes
1) Mode0 – 13 bit Timer Mode
2) Mode1 – 16 bit Timer Mode
3) Mode2 – 8 bit Auto-Reload Mode
4) Mode3 – Split Timer Mode
Timer/Counter
Timer Mode Control Register
MSB LSB
Gate1 C/T1 M1 M0 Gate0 C/T0 M1 M0
Timer 1 Timer 0
Gatex: Allows the Timer to control by external input Intx.
C/Tx: To Select Timer or Counter Operation.
M1 & M0: To select mode out of 3 Modes.

Timer Control Register


MSB LSB
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
TF: Overflow flag, Set by hardware on overflow and cleared by hardware when processor
vectors to interrupt.
TR: Timer run control bit, Set or Reset by software to turn Timer On or Off.
IE: Interrupt edge flag, Set by hardware when external interrupt edge detected
and cleared when interrupt proceed.
IT: Interrupt type control bit set or cleared by software to specify falling edge or
level trigger external interrupt.
Timer/Counter
Mode 0
- Timer operates as Divide by 13-bit Timer (8-bit with 5-bit Prescaler)
- Timer register are configured by 13-bit number, as count rolls over from all 1s to
all 0s it sets the Timer interrupt flag
Timer/Counter
Mode 1
- Timer operates as Divide by 16-bit Timer
- Timer register configured by 16-bit number, as count rolls over from all 1s to
all 0s it sets the Timer interrupt flag
Timer/Counter
Mode 2
- Mode 2 configures Timer (TL1) with automatic reload.
- Overflow TL1 sets TF1 and reloads TL1 from TH1.
Timer/Counter
Mode 3
- Timer 0 in Mode3 establishes TL0 and TH0 as two separate counters.
- TL0 uses Timer0 control bits and TH0 uses Timer1 control bits.
- Timer 1 in Mode3 holds its count. The effect is the same as TR1=0.
Serial Interface
- Serial Port is a Full Duplex Port
- Supports UART function
- Serial port operates in 4 different modes
1) Mode0 – 8-bit shift register with fixed baud rate
2) Mode1 – 8-bit UART with variable baud rate
3) Mode2 – 9-bit UART with fixed baud rate
4) Mode3 – 9-bit UART with variable baud rate
- Framing Error Detection
Serial Interface
Serial Port is a Full Duplex Port

8051 8051

TxD RxD

RxD TxD

Supports UART function


Serial Interface
Serial Port Control Register

MSB LSB
SM0 SM1 SM2 REN TB8 RB8 TI RI

SM0, SM1: Serial Port Mode selector bits


SM2: Enables the Multiprocessor communication.
REN: Receiver enable bit.
TB8: Used in Mode2 and Mode3 as a 9th bit.
RB8: Used in Mode2 and Mode3, the received 9th bit stored in RB8.
TI: Transmit Interrupt flag.
RI: Receive Interrupt flag.
Serial Interface
Operating Modes:
Mode 0:
- Serial data enters and exit through RxD and TxD respectively.
- 8 Data bits transmitted or received LSB first.
- Baud rate is fixed i.e. 1/12 of (Osc. frequency), so no need to
set any Timer.
- SM2 of Serial control register should be 0.

Osc. Frequency
Baud Rate =
12
Serial Interface
Operating Modes:
Mode 1:
- 10 bits are transmitted or received
- a start bit (0), 8 data bit (LSB first), and one stop bit (1).
- Variable Baud rate using Timer 1(Mode 2 i.e. Auto reload mode).

2SMOD x Osc. Frequency


Baud Rate =
12 x 32 x [256-TH1]

- SMOD is the MSB bit of Power Control Register.


- 8051 divide Oscillator frequency by 12 to get machine cycle frequency.
- UART circuitry divide machine cycle frequency by 32 to set baud rate.
- For variable baud rate TH1 can set by programming so that Oscillator frequency
divide by 256 - TH1.
Serial Interface
Operating Modes:
Mode 2:
- 11 bits are transmitted or received
- a start bit (0), 8 data bit (LSB first), a programmable 9th data bit (TB8 in
SCON) and one stop bit (1).
- On receive 9th bit goes into RB8 of Serial port control register and stop bit
ignored.
- Fixed Baud rate i.e. 1/32 or 1/64 Oscillator frequency.

2SMOD x Osc. Frequency


Baud Rate =
64

-SMOD is the MSB bit of Power Control Register.


Serial Interface
Operating Modes:
Mode 3:
- 11 bits are transmitted or received.
- A start bit (0), 8 data bit (LSB first), a programmable 9th data bit (TB8 in
SCON) and one stop bit (1).
- Variable Baud rate using Timer 1(Mode 2 i.e. Auto reload mode).

2SMOD x Osc. Frequency


Baud Rate =
12 x 32 x [256-TH1]

- SMOD is the MSB bit of Power Control Register.

- 8051 divide Oscillator frequency by 12 to get machine cycle frequency.


- UART circuitry divide machine cycle frequency by 32 to set baud rate.
- For variable baud rate TH1 can set by programming so that
Oscillator frequency divide by 256 - TH1.
Interrupts

- 8051 provides 5 interrupt sources.


- Two External Interrupt Int0 & Int1 can level activated or edge activated
depending on bits IT0 and IT1 in TCON register.
- External Interrupts sets the flags IE0 and IE1 in TCON register. These
flags resets by Hardware when Interrupt service is vector.

INT0 IT0 IE0

Interrupt Sources

INT1 IT1 IE1


Architecture
6) Interrupts
- Timer0 and Timer1 interrupts are generated by flags TF0 and TF1
of Timer Control register.
- When Timer rollover then TF0 and TF1 are set.
- These flags are cleared when interrupts service are vector.

TF0

Interrupt Sources

TF1
Architecture
6) Interrupts
- Serial Interrupt generated by logical OR TI and RI of Serial Port
Control register.

- Both TI and RI flags are set by serial control hardware on valid data bits
transmitted or received in SBUF register.

- Neither TI or RI are cleared by hardware on interrupt service vector.

- TI and RI are cleared by software.

TI
Interrupt Source
RI

You might also like