8051,chapter1,architecture and peripherals

72
8051 Microcontroller Chapter 1 BY Amruta Chintawar (Asst.Prof at RAIT, Navi Mumbai) Thursday, September 03, 2015 1 By AMRUTA CHINTAWAR

Upload: amrutachintawar239

Post on 20-Mar-2017

913 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: 8051,chapter1,architecture and peripherals

8051 Microcontroller

Chapter 1

BY

Amruta Chintawar

(Asst.Prof at RAIT, Navi Mumbai)

Thursday, September 03, 2015 1 By AMRUTA CHINTAWAR

Page 2: 8051,chapter1,architecture and peripherals

Topics Covered • Comparison Between Microprocessors and

Microcontroller

• Features, Architecture & Pin configuration

• CPU Timing and Machine cycle

• I/P and O/P Ports

• Memory Organization

• Counters and Timers

• Interrupts

• Serial data I/P &O/P

Thursday, September 03, 2015 2 By AMRUTA CHINTAWAR

Page 3: 8051,chapter1,architecture and peripherals

Comparison Between P & C

P C

CPU is stand-alone, RAM, ROM, I/O,

timer are separate

CPU, RAM, ROM, I/O and timer are all

on a single chip

Designer can decide on the amount of

ROM, RAM and I/O ports

fix amount of on-chip ROM, RAM, I/P

O/P ports (internal h/w is fixed)

general-purpose single-purpose

Instructions are mainly to move large

volume of data

Many bit handling instructions along

with byte processing

More access time for peripherals-system

slower

Less access time on On-chip devices-

system faster

In contrast, similar system that builds

from uP would require a lot of

additional units

Only single chip can be a complete

system

Thursday, September 03, 2015 3 By AMRUTA CHINTAWAR

Page 4: 8051,chapter1,architecture and peripherals

Comparison Between P & C

P C

Implementation is complicated Implementation is easy

Bulkier, costly, less reliable and consume

more power

Compact, Cheaper, more reliable and

consume less power

S/W protection not possible - external

code memory

Possible –On chip memory

uPs are suitable to processing

information in computer systems.

uCs are suitable to control of I/O devices

in designs requiring a minimum

component

Thursday, September 03, 2015 4 By AMRUTA CHINTAWAR

Page 5: 8051,chapter1,architecture and peripherals

Features of 8051

• 12Mhz/ (11.0592Mhz to support standard baud rate for serial

port)

• 4K bytes ROM

• 128 bytes RAM

• Four 8-bit I/O ports (32 I/O pins)

• Two 8/16 bit timers

• Serial port-Asynchronous

• 64K external code memory space

• 64K data memory space

• Multiple internal and external interrupt sources (5 srcs)

Thursday, September 03, 2015 5 By AMRUTA CHINTAWAR

Page 6: 8051,chapter1,architecture and peripherals

Features of 8051

Thursday, September 03, 2015 6 By AMRUTA CHINTAWAR

Page 7: 8051,chapter1,architecture and peripherals

Blocks of Architecture

• ALU

• Memory

• Peripherals

• Timing and Control Unit

• Oscillator

Thursday, September 03, 2015 7 By AMRUTA CHINTAWAR

Page 8: 8051,chapter1,architecture and peripherals

ALU

• 8-bit

• Performs all arithmetic and

logical operations

• Updates status flags(PSW)

Thursday, September 03, 2015 8 By AMRUTA CHINTAWAR

Page 9: 8051,chapter1,architecture and peripherals

Memory

• Separate On-chip Data and Code memor

• Code Memory-Programs instructions (ROM-4KB)

• Data memory-various Data (RAM-128B)

• Few RAM locations used to program control

various on-chip peripherals and features-SFRs

Thursday, September 03, 2015 9 By AMRUTA CHINTAWAR

Page 10: 8051,chapter1,architecture and peripherals

Peripherals

• 2, 16 bit Timers T0,T1

SFRs- TCON,TMOD,T0,T1

PINs-T0, T1

• 4,I/O ports P0,P1,P2,P3

SFRs-P0,P1,P2,P3

PINs-P0.0-P0.7 ,P1.0-P1.7

• Serial Port

SFRs-SCON,SBUF,PCON (1-bit)

PINs-Rxd,Txd

• Interrupts

SFRs-IP,IE,TCON

PINs-INT0,INT1 (H/W)

Thursday, September 03, 2015 10 By AMRUTA CHINTAWAR

Page 11: 8051,chapter1,architecture and peripherals

Timing and Control • Generate time and Control signal

• Necessary for Execution

• Synchronizes all activities with clock

Thursday, September 03, 2015 11 By AMRUTA CHINTAWAR

Page 12: 8051,chapter1,architecture and peripherals

Oscillator • Onchip oscillator circuit – generates clock

pulses.

• External resonant ckt connected (complete

oscillator)

• 12Mhz

Thursday, September 03, 2015 12 By AMRUTA CHINTAWAR

Page 13: 8051,chapter1,architecture and peripherals

Pin Configuration

Thursday, September 03, 2015 13 By AMRUTA CHINTAWAR

Page 14: 8051,chapter1,architecture and peripherals

Pin Configuration

• 40 pins DIP package

• Four 8-bit I/O port pins-has two functions

1. Vcc (pin 40): Power supply ,+5v

2. GND(pin 20) : supply is connected wrp to

ground

Thursday, September 03, 2015 14 By AMRUTA CHINTAWAR

Page 15: 8051,chapter1,architecture and peripherals

Pin Configuration

3. XTAL1 &XTAL2: The external resonant circuit is

connected to on-chip oscillator circuit .

• NORMALLY Quartz crystal and capacitor are

connected with XTAL1(pin 19) & XTAL2 (pin

18)

• Works at a frequency of crystal oscillator

• If clock signal external oscillator is used,its

onne ted to XTAL …XTAL is left unconnected.

Thursday, September 03, 2015 15

By AMRUTA CHINTAWAR

Page 16: 8051,chapter1,architecture and peripherals

Pin Configuration

3. XTAL1 &XTAL2: The external resonant circuit

is connected to on-chip oscillator circuit .

• NORMALLY Quartz crystal and capacitor are

connected with XTAL1(pin 19) & XTAL2 (pin

18)

• Works at a frequency of crystal oscillator

• If clock signal external oscillator is used,its

onne ted to XTAL …XTAL is left unconnected.

Thursday, September 03, 2015 16 By AMRUTA CHINTAWAR

Page 17: 8051,chapter1,architecture and peripherals

Pin Configuration

Crystal connections:

Thursday, September 03, 2015 17 By AMRUTA CHINTAWAR

Page 18: 8051,chapter1,architecture and peripherals

Pin Configuration

Machine Cycle:

Thursday, September 03, 2015 18 By AMRUTA CHINTAWAR

Page 19: 8051,chapter1,architecture and peripherals

Pin Configuration

4.ALE/PROG#: Address latch Enable

• Used to Demultiplex address and data

• ALE=1,indicates presence of lower address bits on P0,thus enable latch to store address.

• ALE=0, contents are latched, it retains till next ALE.

• ALE=0, P0 act as data bus

PROG#

• for on-chip flash memory programming

• After reset if this pin is low ,uC enters into programming mode

Thursday, September 03, 2015 19

By AMRUTA CHINTAWAR

Page 20: 8051,chapter1,architecture and peripherals

Pin Configuration, ALE

Thursday, September 03, 2015 20 By AMRUTA CHINTAWAR

Page 21: 8051,chapter1,architecture and peripherals

Pin Configuration

5.RST: Reset

• Active high I/P

• Terminates all the activities

• Clears the contents of all the registers

• Default values will be loaded in SFRs

• Reset signal must be held high for at least 2

m/c cycles

Thursday, September 03, 2015 21 By AMRUTA CHINTAWAR

Page 22: 8051,chapter1,architecture and peripherals

Pin Configuration

RESET:

Thursday, September 03, 2015 22 By AMRUTA CHINTAWAR

Page 23: 8051,chapter1,architecture and peripherals

Pin Configuration

6.PSEN#: Program store Enable

• Active low

• Activate external ROM/EPROM/EEPROM

• Connected to OE# of ROM chip

• not activated when On-chip ROM is accessed

Thursday, September 03, 2015 23 By AMRUTA CHINTAWAR

Page 24: 8051,chapter1,architecture and peripherals

Pin Configuration

7.EA#/VPP: External Access

• Active low, External Access, complete code on external ROM

• If high fetch code from on-chip ROM

• Connected to OE# of ROM chip

• not activated when On-chip ROM is accessed

• However any reference to program address outside the address range of on-chip memory will automatically access External memory

Thursday, September 03, 2015 24 By AMRUTA CHINTAWAR

Page 25: 8051,chapter1,architecture and peripherals

Pin Configuration

8.PORT 0:

• 8-bit open drain bidirectional I/O port

• Occupies 8-pins

• Open drain external pull-up resistor of 10Kohm must be connected to each pin

• To program P0 as I/P, write 1 to lacth register

• It also has alternate function of ADD/DATA

• However any reference to program address outside the address range of on-chip memory will automatically access External memory

Thursday, September 03, 2015 25 By AMRUTA CHINTAWAR

Page 26: 8051,chapter1,architecture and peripherals

Pin Configuration

9.PORT 1:

• 8-bit bidirectional I/O port

• Occupies 8-pins

• Has Internal pull-up resistor

• To program P1 as I/P, write 1 to latch register

Thursday, September 03, 2015 26 By AMRUTA CHINTAWAR

Page 27: 8051,chapter1,architecture and peripherals

Pin Configuration

9.PORT 2:

• 8-bit bidirectional I/O port

• Occupies 8-pins

• Has Internal pull-up resistor

• Act as Higher order address bus A8-A15 while accessing external memory

• To program P1 as I/P, write 1 to latch register

Thursday, September 03, 2015 27 By AMRUTA CHINTAWAR

Page 28: 8051,chapter1,architecture and peripherals

Pin Configuration

9.PORT 3:

• 8-bit bidirectional I/O port

• Occupies 8-pins

• Has Internal pull-up resistor

• Has alternate functions

• To program P1 as I/P, write 1 to latch register

• TXD & RXD , INT0# & INT1# , T0 & T1 ,WR# and Rd#

Thursday, September 03, 2015 28 By AMRUTA CHINTAWAR

Page 29: 8051,chapter1,architecture and peripherals

Programming Model

• H/W which is available for Programmer to

directly use it through S/W

• It is a collection of 8 and 16 bit register and 8

bit memory locations.

• Can be operated using software instructions

• Each register with exception of PC, has an

internal one byte address assigned to it.

Thursday, September 03, 2015 By AMRUTA CHINTAWAR 29

Page 30: 8051,chapter1,architecture and peripherals

Programming Model

• Some registers such as TCON, SCON, IP, IE, A,

B, PSW and ports are all bit addressable and

are marked with * mark.

• These types have provision for reading or

writing the entire byte of data and also each

individual bits may be read or altered

• operations can be done by software

instructions that are generally able to specify a

register by its address or its symbolic name or

both Thursday, September 03, 2015 By AMRUTA CHINTAWAR 30

Page 31: 8051,chapter1,architecture and peripherals

Programming Model

Thursday, September 03, 2015 31 By AMRUTA CHINTAWAR

Page 32: 8051,chapter1,architecture and peripherals

SFRs Memory Mapping

Thursday, September 03, 2015 32 By AMRUTA CHINTAWAR

Page 33: 8051,chapter1,architecture and peripherals

PSW Structure

Thursday, September 03, 2015 33 By AMRUTA CHINTAWAR

Page 34: 8051,chapter1,architecture and peripherals

I/P and O/P Port

• Ports can be accessed directly by instructions

during program execution

• I/O ports are memory mapped, they are

treated as memory locations

• All ports are bit addressable

• Each PIN consists of a D latch, I/P buffer and

O/P driver

• SFRs for each port is made of 8-latches

• Accessed by SFRs address or name of that port

Thursday, September 03, 2015 34 By AMRUTA CHINTAWAR

Page 35: 8051,chapter1,architecture and peripherals

Port 0

Thursday, September 03, 2015 35 By AMRUTA CHINTAWAR

Page 36: 8051,chapter1,architecture and peripherals

Port 1

Thursday, September 03, 2015 36 By AMRUTA CHINTAWAR

Page 37: 8051,chapter1,architecture and peripherals

Port 2

Thursday, September 03, 2015 37 By AMRUTA CHINTAWAR

Page 38: 8051,chapter1,architecture and peripherals

Port 3

Thursday, September 03, 2015 38 By AMRUTA CHINTAWAR

Page 39: 8051,chapter1,architecture and peripherals

Timer Structure

Thursday, September 03, 2015 39 By AMRUTA CHINTAWAR

Page 40: 8051,chapter1,architecture and peripherals

TMOD Register

Thursday, September 03, 2015 40 By AMRUTA CHINTAWAR

Page 41: 8051,chapter1,architecture and peripherals

TCON Register

Thursday, September 03, 2015 41 By AMRUTA CHINTAWAR

Page 42: 8051,chapter1,architecture and peripherals

Timer Modes

• It operates in 4 different modes

1. Mode0: 13-bit Timer /Counter

2. Mode1: 16-bit Timer/Counter

3.Mode2: 8-bit Auto-reload

4.Mode3: 8-bit split timer(TL0,TH0)

Thursday, September 03, 2015 42 By AMRUTA CHINTAWAR

Page 43: 8051,chapter1,architecture and peripherals

Timer Modes

Thursday, September 03, 2015 43 By AMRUTA CHINTAWAR

Page 44: 8051,chapter1,architecture and peripherals

Timer Modes

Thursday, September 03, 2015 44 By AMRUTA CHINTAWAR

Page 45: 8051,chapter1,architecture and peripherals

Timer Modes

Thursday, September 03, 2015 45 By AMRUTA CHINTAWAR

Page 46: 8051,chapter1,architecture and peripherals

Timer Modes

Thursday, September 03, 2015 46 By AMRUTA CHINTAWAR

Page 47: 8051,chapter1,architecture and peripherals

Timer Modes

Thursday, September 03, 2015 47 By AMRUTA CHINTAWAR

Page 48: 8051,chapter1,architecture and peripherals

Serial Port

• Slow Process

• To tie-up with valuable processor time serial

data flags are included

• Transmission is under control of program

• Reception unpredictable

• Many a times beyond control of program

• Programmers must write routine to clear flags

Thursday, September 03, 2015 48 By AMRUTA CHINTAWAR

Page 49: 8051,chapter1,architecture and peripherals

Serial Port

• Support full-duplex serial communication

• Transmit and receive buffer register with shift

register

• Logic for generating timing signal

• Status bit showing that data byte has been

sent

• Status bit to indicate data bytes has been

received

• Controlled by SBUF & SCON

Thursday, September 03, 2015 49 By AMRUTA CHINTAWAR

Page 50: 8051,chapter1,architecture and peripherals

Serial Port

Thursday, September 03, 2015 50 By AMRUTA CHINTAWAR

Page 51: 8051,chapter1,architecture and peripherals

Serial Data Transmission

Thursday, September 03, 2015 51 By AMRUTA CHINTAWAR

Page 52: 8051,chapter1,architecture and peripherals

Serial Data Transmission

Thursday, September 03, 2015 52 By AMRUTA CHINTAWAR

Page 53: 8051,chapter1,architecture and peripherals

SCON

Thursday, September 03, 2015 53 By AMRUTA CHINTAWAR

Page 54: 8051,chapter1,architecture and peripherals

Serial Modes

MODE 0 MODE 1,2,3

Fixed baud rate Variable by T1 and SMOD bit of

PCON

Thursday, September 03, 2015 54 By AMRUTA CHINTAWAR

Page 55: 8051,chapter1,architecture and peripherals

Serial Mode 0 • 8-bit half Duplex

• START/STOP Bit not required

• TRN and REN is on RxD

• TxD-provides shift clock for data transfer

-data shifted out at S6P2

-data shifted in after Rxd is sampled S5P2

-signal is square wave

-high for S6,S1,S2

-low for S3,S4,S5

• Timer1 baud rate f/12

• For high speed data collection

Thursday, September 03, 2015 55 By AMRUTA CHINTAWAR

Page 56: 8051,chapter1,architecture and peripherals

Serial Mode 0

Thursday, September 03, 2015 56 By AMRUTA CHINTAWAR

Page 57: 8051,chapter1,architecture and peripherals

Serial Mode 1 • 10-bits per character, full duplex

• 1-start(0),8-data,1-stop bit(1)

• Start and stop bit -----discard

• RxD-receives

• TxD-Transmit

• TI=1-after all 10-bits transmitted

• RI=1-if SM2=0 unconditional

RB8=1 condition satisfies

Thursday, September 03, 2015 57

By AMRUTA CHINTAWAR

Page 58: 8051,chapter1,architecture and peripherals

Serial Mode 1 • Reception- START bit discarded

-8-Bit SBUF

-stop bit RB8

• Data received at programmed baud rate

fbaud =2smod /32 xT1

1/32 x T1 ----SMOD=0

1/16xT1 ----SMOD=1

Thursday, September 03, 2015 58 By AMRUTA CHINTAWAR

Page 59: 8051,chapter1,architecture and peripherals

Serial Mode 1

Thursday, September 03, 2015 59 By AMRUTA CHINTAWAR

Page 60: 8051,chapter1,architecture and peripherals

Serial Mode 2 • 11-bits per character

• 1-start(0),8-data,9th-programmable,1-stop

bit(1)

9th- RB8 and 8-SBUF ------reception

9th -TB8 and 8-SBUF------transmission

• Start and stop bit -----discard

• Baud rate controlled by oscillator frequency

fbaud =2smod /64,1/64,1/32 x OSC freq

Thursday, September 03, 2015 60 By AMRUTA CHINTAWAR

Page 61: 8051,chapter1,architecture and peripherals

Serial Mode 3

• Operates like Mode 2

only

• Baud rate is variable

Thursday, September 03, 2015 61 By AMRUTA CHINTAWAR

Page 62: 8051,chapter1,architecture and peripherals

Serial Mode 2 & 3

Thursday, September 03, 2015 62 By AMRUTA CHINTAWAR

Page 63: 8051,chapter1,architecture and peripherals

Interrupts

• It’s a signal generated y an event that auses the controller to stop temporarily its current

program

• Performs ISR to service that event(Interrupt

handler)

• These events are asynchronous generated by

peripherals

• It allows most efficient utilization of resources

and time

• It’s a H/W generated all Thursday, September 03, 2015 63

By AMRUTA CHINTAWAR

Page 64: 8051,chapter1,architecture and peripherals

Interrupts of 8051

• The source may be internal peripheral or

external devices

• Total 5---3 internal & 2 H/W

• Internal– Timer0 (TF0),Timer1(TF1),serial

port(TI/RI)

• External--INT0#,INT1#,also referred as IE0,IE1

• Each interrupt has fixed memory location that

contains its ISR

• ISRs are stored in IVT

Thursday, September 03, 2015 64 Thursday, September 03, 2015 64 By AMRUTA CHINTAWAR

Page 65: 8051,chapter1,architecture and peripherals

Interrupts of 8051

• All flags auto clear except RI/TI it has to be

cleared manually

Thursday, September 03, 2015 65 Thursday, September 03, 2015 65 By AMRUTA CHINTAWAR

Page 66: 8051,chapter1,architecture and peripherals

IP

Thursday, September 03, 2015 66 By AMRUTA CHINTAWAR

Page 67: 8051,chapter1,architecture and peripherals

IE

Thursday, September 03, 2015 67 By AMRUTA CHINTAWAR

Page 68: 8051,chapter1,architecture and peripherals

Power Saving Modes

• Two Power saving modes activated by

programming PCON

• IDLE and POWER DOWN mode

• Most important factor to save powe

consumption is to use crystal frequency just

sufficient for application

• Operating with higher frequency will consume

more power

Thursday, September 03, 2015 68 Thursday, September 03, 2015 68 By AMRUTA CHINTAWAR

Page 69: 8051,chapter1,architecture and peripherals

IDLE Mode

• By setting IDLE bit in PCON =1

• Stops program execution and contents of internal RAM are preserved

• Oscillator continues to run,but clock is disconnected from CPU

• Timer and serial port operates normally

• Come out by activation of any Interrupt or RESET,this will make IDLE=0

• After execution of ISR,program resume from instruction after set idle.

Thursday, September 03, 2015 69 Thursday, September 03, 2015 69

By AMRUTA CHINTAWAR

Page 70: 8051,chapter1,architecture and peripherals

Power Down Mode

• By setting PWDN=1

• Stops on chip oscillator

• Program execution, timers and serial port

operation also stops

• Content of internal RAM are preserved

• Come out of by RESET

Thursday, September 03, 2015 70 Thursday, September 03, 2015 70 By AMRUTA CHINTAWAR

Page 71: 8051,chapter1,architecture and peripherals

Power Saving Modes

Thursday, September 03, 2015 71 By AMRUTA CHINTAWAR

Page 72: 8051,chapter1,architecture and peripherals

PCON

Thursday, September 03, 2015 72 By AMRUTA CHINTAWAR

• Not bit addressable