8051 micro controller. architecture of 8051 features of 8051

35
8051 Micro controller

Upload: tracey-heath

Post on 04-Jan-2016

422 views

Category:

Documents


16 download

TRANSCRIPT

Page 1: 8051 Micro controller. Architecture of 8051 Features of 8051

8051

Micro controller

Page 2: 8051 Micro controller. Architecture of 8051 Features of 8051

Architecture of 8051

Page 3: 8051 Micro controller. Architecture of 8051 Features of 8051

Features of 8051

Page 4: 8051 Micro controller. Architecture of 8051 Features of 8051

Code memory

• the memory that holds the actual 8051 program that is to be run

• is limited to 64K • possible to have 4K of code

memory on-chip and 64k of code memory off-chip in an EPROM.

• most commonly implemented as off-chip EPROM.

Page 5: 8051 Micro controller. Architecture of 8051 Features of 8051

Program Memory Structure

Page 6: 8051 Micro controller. Architecture of 8051 Features of 8051
Page 7: 8051 Micro controller. Architecture of 8051 Features of 8051

On-chip memory

• Internal RAM • Special Function Register (SFR)

Page 8: 8051 Micro controller. Architecture of 8051 Features of 8051

• 128 bytes of Internal RAM. - on-chip

• is volatile

• The 128 bytes of internal ram is subdivided as shown on the memory map.

– The first 8 bytes (00h - 07h) are "register bank 0". By manipulating certain SFRs, a program may choose to use register banks 1, 2, or 3. These alternative register banks are located in internal RAM in addresses 08h through 1Fh.

– Bit Memory - 20h through 2Fh.

– The 80 bytes remaining from addresses 30h through 7Fh, may be used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack

Internal RAM

Page 9: 8051 Micro controller. Architecture of 8051 Features of 8051

Internal Memory Map

REG_BANK 3

REG_BANK 2

REG_BANK 1

REG_BANK 0

1FH 2Fh

18H17H

10h0FH

08H07H

00H 20H

7F 78

77

6F

67

5F

57

4f

47

3f

37

2F

27

1F

17

0F

07 00

General Purpose Memory

7FH

30H

BIT Addressable Memory

Page 10: 8051 Micro controller. Architecture of 8051 Features of 8051

Register Banks

• The 8051 uses 8 "R" registers • are numbered from 0 through 7 (R0, R1,

R2, R3, R4, R5, R6, and R7). • are generally used to assist in

manipulating values and moving data from one memory location to another.

• For example, to add the value of R4 to the Accumulator, we would execute the following instruction:

» ADD A, R4

Page 11: 8051 Micro controller. Architecture of 8051 Features of 8051

Bit Memory

• gives the user the ability to access a number of bit variables. These variables may be either 1 or 0.

• There are 128 bit variables available to the user,

– numbered 00h through 7Fh. • make use of these variables with commands such as SETB and CLR. • For example, to set bit number 24 (hex) to 1 you would execute the

instruction: » SETB 24h

##128 bit variables occupy the 16 bytes of Internal RAM from 20h-2Fh. Thus, the instruction

MOV 20h,#0FFh • is equivalent to:

» SETB 00hSETB 01hSETB 02hSETB 03hSETB 04hSETB 05h

SETB 06hSETB 07h

Page 12: 8051 Micro controller. Architecture of 8051 Features of 8051

‘A’ Register (Accumulator, Addresses E0h, Bit-

Addressable) • is one of the most-used SFRs on the

8051 since it is involved in so many instructions.

Page 13: 8051 Micro controller. Architecture of 8051 Features of 8051

The "B" Register (address – F0H)

• is very similar to the Accumulator

• is only used by two 8051 instructions:

MUL AB and DIV AB.

• May be used as yet another temporary storage register much like a ninth "R" register.

Page 14: 8051 Micro controller. Architecture of 8051 Features of 8051

Special Function Register (SFR) Memory

• are areas of memory that control specific functionality of the 8051 processor.

• For example,– permit access to the 8051’s 32 input/output

lines.– allows a program to read or write to the 8051’s

serial port.– allow the user to set the serial baud rate,

control and access timers, and configure the 8051’s interrupt system.

• any address of 80h through FFh refers to an SFR control register.

Page 15: 8051 Micro controller. Architecture of 8051 Features of 8051

SFR MAP

Page 16: 8051 Micro controller. Architecture of 8051 Features of 8051

Different SFRs

• SP (Stack Pointer, Address 81h): – is the stack pointer of the microcontroller. – indicates where the next value to be taken from the

stack will be read from in Internal RAM. – When a value is pushed onto the stack, the value will be

written to the address of SP + 1. – SFR is modified by all instructions which modify the

stack, such as PUSH, POP, LCALL, RET, RETI, and whenever interrupts are invoked by the microcontroller.

• Programming Tip: The SP SFR, on startup, is initialized to 07h. This means the stack will start at 08h and start expanding upward in internal RAM.

Page 17: 8051 Micro controller. Architecture of 8051 Features of 8051

DPL/DPH (Data Pointer Low/High, Addresses 82h/83h)

• DPL and DPH work together to represent a 16-bit value called the Data Pointer - DPTR

• is used in operations regarding external RAM and some instructions involving code memory.

• can represent values from 0000h to FFFFh

Programming Tip:• There is no instruction that decrements

DPTR. If you wish to decrement the value of DPTR, you must write your own code to do so.

Page 18: 8051 Micro controller. Architecture of 8051 Features of 8051

TCON (Timer Control, Addresses 88h, Bit-Addressable)

• is used to configure and modify the way in which the 8051's two timers operate.

• controls whether each of the two timers is running or stopped

• contains a flag to indicate that each timer has overflowed.

• Additionally, some non-timer related bits are located in the TCON SFR. These bits are used to configure the way in which the external interrupts are activated and also contain the external interrupt flags which are set when an external interrupt has occured.

Page 19: 8051 Micro controller. Architecture of 8051 Features of 8051

TCON

TF1 - Timer 1 overflow flag. Set by hardware when the Timer/Counter 1 overtlows. 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 & TR0 - same as above but for TIMER 0IE1 - External Interrupt 1 edge flag. Set by hardware when External Interrupt edge is detected. Cleared by hardware when interrupt is processed.IT1 - Interrupt 1 type control bit. Set/cleared by sotware to specify falling edge low level triggered External Interrupt.

IE0, IT0 – for type 0 external interrupt

Page 20: 8051 Micro controller. Architecture of 8051 Features of 8051

TMOD (Timer Mode, Addresses 89h):

• used to configure the mode of operation of each of the two timers.

• Using this SFR your program may configure each timer to be a 16-bit timer, an 8-bit autoreload timer, a 13-bit timer, or two separate timers.

• Additionally, you may configure the timers to only count "events" that are indicated on an external pin.

Page 21: 8051 Micro controller. Architecture of 8051 Features of 8051

TMOD

Page 22: 8051 Micro controller. Architecture of 8051 Features of 8051

TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch):

• two SFRs, taken together, represent timer 0.

• These timers always count up. • User can configure how and when they

increment in value.

TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh):

SAME as above but for Timer 1

Page 23: 8051 Micro controller. Architecture of 8051 Features of 8051

• P0 Port 0 , Address 80H, Bit addressable )– 8 bit I/O Port– Multiplexed with Lower byte of address A7-A0 and

bidirectional Data Bus D7-D0

• P1 (Port 1, Address 90h, Bit-Addressable) – 8 bit I/O port

• P2 (Port 2, Address A0h, Bit-Addressable) – 8 bit I/O– Is multiplexed with higher byte of address bus : A15-

A7

##Port pins may be identified as P1.0 to P1.7

PORTS

Page 24: 8051 Micro controller. Architecture of 8051 Features of 8051

• P3 (Port 3, Address B0h, Bit-Addressable):– 8 bit I/O– Port Pins Multiplexed as

P3.0 - RxDP3.1 - TxDP3.2 - /INT0P3.3 - /INT1P3.4 - T0P3.5 - T1P3.6 - /WRP3.7 - /RD

Page 25: 8051 Micro controller. Architecture of 8051 Features of 8051

Interrupts

• Supports 5 hardware interrupts• 2 external and 3 internal• The internal interrupts are –

– Timer 0 overflow– Timer 1 overflow– Serial Communication (a byte transmitted or

received)– The vectors defined are

IE0 - 0003hTF0 – 000BHIE1 – 0013HTF1 – 001bHSerial – 0023H

Page 26: 8051 Micro controller. Architecture of 8051 Features of 8051

IE (Interrupt Enable, Addresses A8h):

• is used to enable and disable specific interrupts.

• The low 7 bits of the SFR are used to enable/disable the specific interrupts,

• the highest bit is used to enable or disable ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

Page 27: 8051 Micro controller. Architecture of 8051 Features of 8051

IE register

Page 28: 8051 Micro controller. Architecture of 8051 Features of 8051

IP (Interrupt Priority, Addresses B8h, Bit-Addressable):

• is used to specify the relative priority of each interrupt.

• an interrupt may either be of low (0) priority or high (1) priority.

• If multiple interrupts with same priority are generated then the default priority is –

IE0TF0IE1TF1SERIAL – RI or TI

Page 29: 8051 Micro controller. Architecture of 8051 Features of 8051

IP register

Page 30: 8051 Micro controller. Architecture of 8051 Features of 8051

SCON (Serial Control, Addresses 98h, Bit-Addressable)

• Is used to configure the behavior of the 8051's on-board serial port.

• controls the baud rate of the serial port, whether the serial port is activated to receive data

• also contains flags that are set when a byte is successfully sent or received

Page 31: 8051 Micro controller. Architecture of 8051 Features of 8051

SCON register

Page 32: 8051 Micro controller. Architecture of 8051 Features of 8051

SBUF (Serial Control, Addresses 99h):

• used to send and receive data via the on-board serial port.

• These are two physical registers – one as Write only and the other is Read only

• When SBUF is written with data Transmission starts

• To receive a data byte, 8051 has to be enabled explicitly for “Receive” operation

SBUF

SBUF

TxD

RxD

Page 33: 8051 Micro controller. Architecture of 8051 Features of 8051

PSW (Program Status Word, Addresses D0h, Bit-Addressable)

• is used to store a number of important bits that are set and cleared by 8051 instructions.

• contains the carry flag, the auxiliary carry flag, the overflow flag, and the parity flag.

• Additionally, contains the register bank select flags which are used to select which of the "R" register banks are currently selected.

Page 34: 8051 Micro controller. Architecture of 8051 Features of 8051

PSW – Register

Page 35: 8051 Micro controller. Architecture of 8051 Features of 8051

The Program Counter (PC)

• is a 2-byte register• Always points to the next instruction to

execute• On reset, PC always starts at 0000h and is

incremented each time an instruction is executed.

• there is no way to directly modify it’s value. Except with JMPs and CALLs

• there is no way to read the value of PC.