26
Embedded Systems 1 2-1 8051 Architecture 8051 Microcontroller The 8051, Motorola and PIC families are the 3 leading sellers in the microcontroller market. The 8051 microcontroller was originally developed by Intel in the late 1970’s. Today many other companies manufacture the 8051 and it’s derivatives e.g. Philips, Atmel, Dallas, Infineon, Analog Devices These derivatives support the standard 8051 architecture along with some additional features e.g. Faster instruction execution times More data and program memory Additional timers On-chip EEPROM memory On-chip ADC and DAC On-chip real time clock Support of I2C and SPI serial interfaces 3V power supply for lower power consumption

8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embed Size (px)

Citation preview

Page 1: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-1 8051 Architecture

8051 Microcontroller• The 8051, Motorola and PIC families are the 3 leading sellers in the microcontroller

market.• The 8051 microcontroller was originally developed by Intel in the late 1970’s.• Today many other companies manufacture the 8051 and it’s derivatives

– e.g. Philips, Atmel, Dallas, Infineon, Analog Devices– These derivatives support the standard 8051 architecture along with some

additional features e.g.• Faster instruction execution times• More data and program memory• Additional timers• On-chip EEPROM memory• On-chip ADC and DAC• On-chip real time clock• Support of I2C and SPI serial interfaces• 3V power supply for lower power consumption

Page 2: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-2 8051 Architecture

8051 Features• 8 bit CPU• 4Kbytes of on chip program memory• 128 bytes of on chip data memory• 32 input output pins arranged as 4 8-bit ports P0 to P3• 2 16-bit timers/counters• Serial data communication - Full duplex UART • 5 source interrupt structure• 16 bytes of bit addressable RAM• 64K bytes external program memory space• 64K bytes external data memory space• On chip oscillator• Boolean processor

Page 3: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-3 8051 Architecture

8051 Architecture

Source : Philips 80C51 Family Architecture

Page 4: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-4 8051 Architecture

8051 Pin-out• 8051 is a 40 pin device• Apply 5V to VCC• Crystal connects to XTAL1, XTAL2• Need external reset circuit• EA tied high for internal program memory,

low for external memory• ALE and PSEN only used for external

memory

P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7

P3.0P3.1P3.2P3.3P3.4P3.5P3.6P3.7

XTAL1XTAL2

RESET

P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

EAALEPSEN

VCC

GND

Page 5: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-5 8051 Architecture

8051 Clock• The 8051 requires an external clock source

– Usually a crystal oscillator is used (up to 50MHz)• Connected to the XTAL1 and XTAL2 pins• A 33pF capacitor must also be tied from each pin to ground

– All operations performed by the 8051 take 1 or more machine cycles to execute. A machine cycle is the smallest interval of time in which the micro can accomplish any task. A machine cycle is 12 clock periods

– All 8051 instructions take 1, 2 or 4 machine cycles to execute– Instruction execution time = (12 * No. of machine cycles)/ (clock frequency)

Page 6: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-6 8051 Architecture

8051 Clock• If the 8051 is operating off a 12MHz crystal, What is the maximum number of

instructions that can execute in 1 second?

• How long does the following assembly language code take to execute if the 8051 is operating from a 16MHz crystal?

MOV A, #12 (1 machine cycle)MOV R1, #8 (1 machine cycle)ADD A, R1 (1 machine cycle)

Page 7: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-7 8051 Architecture

8051 Reset• On power-up a reset signal must be applied to the 8051 reset pin

– The 8051 reset input is active high– Resetting the 8051 will load the Program Counter register (PC) with 0 and force

the 8051 to start program execution from address 0 in program memory– The reset pin must be brought low before program execution can begin.– An external circuit must be used to apply the reset pulse.

Reset

8051

5V

10uF

10K

Page 8: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-8 8051 Architecture

8051 I/O Ports• 32 of the 8051’s pins are dedicated as I/O lines• The 8051 has 4 I/O ports labelled P0, P1, P2, P3. Each port is bi-directional.• Each port is 8 bits wide

– A port’s pins are labelled 0 to 7 – P0.0 is pin 0 of port 0, P0.7 is pin 7– All port pins may be used as inputs or outputs– Note: -If using Port 0 as an output pull-up resistors must be used

• Some port pins have alternate uses (see next slide)• The 8051 is a CMOS device

– i.e. it cannot interface directly to large current loads– IOL max. per pin is 10mA– IOL max. for Port 0 is 26mA– IOL max. for the other 3 ports is 15mA– IOL max. for device is 71mA– e.g. an LED circuit sinks 7mA into an 8051 pin

• Can only connect 2 LED circuits to Port 1

Page 9: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-9 8051 Architecture

8051 Alternative Pin-out• Some 8051 pins have alternate applications• Ports 0 and 2 are used to supply the address and

data bus when interfacing to external devices• P3.6 and P3.7 supply the write and read strobes

for external memory interfacing• P3.0 and P3.1 are the serial port interface pins• P3.2 and P3.3 are the external interrupt pins• P3.4 and P3.5 are the external timer inputs

Page 10: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-10 8051 Architecture

8051 Features• The 8051 is an 8-bit device

– The internal and external 8051 data buses are 8-bits wide• i.e. all data transfers can move a maximum of 1 byte of information

– All registers with 2 exceptions are 8-bits wide– While the 8051 can operate quickly with 8-bit variables (chars), operation with

larger variables (e.g. ints) can be quite slow as the variables need to be broken into 8-bit sub-units

Page 11: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-11 8051 Architecture

8051 Memory Organisation• 8051 has 3 types of memory

– Program (Code) Memory– On-chip memory – External data memory (RAM)

8051µController

InternalRAM

SFRs

CodeMemory

ExternalDataMemory

ExternalProgramMemory

Page 12: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-12 8051 Architecture

8051 Program Memory

• Used to store application code and constants• Limited to 64KBytes maximum• 8051 has 4KBytes of program memory on-chip

– On-chip program memory may be ROM, EPROM or Flash– Code may be programmed onto the 8051 using a PROM programmer– Some 8051 derivatives are In-System Programmable (ISP)

• i.e. they may be programmed in-circuit using the serial port• Program memory may be expanded by adding external memory chips

Page 13: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-13 8051 Architecture

8051 External Data Memory• 8051 has only 128 Bytes of internal data memory

– This may not be sufficient to hold the variables used in some applications– An external RAM chip may be connected to the 8051 to increase data memory

capacity• 8051 can support up to 64KBytes of external data memory

Page 14: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-14 8051 Architecture

8051 Internal Memory• The 8051 microcontroller contains 128 Bytes of data memory (RAM)• This memory may be used for variable storage or for the stack

– Address range is 00H to 7FH• The 8051 also contains 128 Bytes of memory area assigned to SFRs (Special Function Registers)

– Address range 80H to FFH

SpecialFunctionRegisters

User RAM& Stack

Bit-AddressableMemory

Register Bank 3

Register Bank 2

Register Bank 1

Register Bank 0

FFH

80H

7FH

30H2FH

20H1FH18H17H10H0FH08H07H00H

4 banks of 8 registersLabelled R0 to R7

Used for storingBit variables

Used for 8051 peripheralconfiguration and status info

Page 15: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-15 8051 Architecture

8051 Registers• The 8051 has 3 types of registers

– 2 16-bit registers PC and DPTR• The PC (Program Counter) holds the address of the next instruction to be

executed. The PC is automatically incremented after each instruction is executed.

• The DPTR (Data Pointer) is used to hold the address of external program or data memory locations.

– 8051 Working Registers• The 8051 has 34 general purpose working registers• The A (accumulator) register is used for arithmetic and boolean operations• The B register is used for multiply and divide operations• 32 working registers are contained in internal data memory

– Special Function Registers (SFRs)• these registers are used to control and monitor the status of the 8051 internal

peripherals

Page 16: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-16 8051 Architecture

8051 Register Banks• The lower 32 bytes of internal data memory is divided into 4 register banks

– Each register bank contains 8 registers labelled R0 to R7– These registers are used by many of the 8051 instructions– On power-up the 8051 defaults to using register bank 0

• The current register bank is selected by changing bits RS0 and RS1 in the Program Status Word (PSW) register.

• Bank switching may be used to improve the efficiency of applications that use interrupts.

Page 17: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-17 8051 Architecture

PSW Register

Page 18: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-18 8051 Architecture

Bit Addressable Memory• 16 bytes of internal data memory may be accessed at the bit level• This is useful for applications that use flags to reflect the status of certain events

– This saves memory space as a flag can be declared as a single bit rather than using a full byte of memory

– A single memory location can be used to store 8 flags• The bit addressable area of memory can also be used to store byte wide (or larger)

variables

Page 19: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-19 8051 Architecture

The Stack• The stack is an area of internal data memory that is used for:-

– Storage of return addresses for function calls– Backup of memory locations that may be altered by an interrupt service routine

(ISR)• The stack pointer (SP) SFR points to the top of the stack.• When a function is called in a C program, the microcontroller needs to remember the

return address from the function– i.e. what is the next instruction to be executed when the function is complete– As the PC register contains the address of the next instruction to be executed, the

contents of the PC register (2 Bytes) is pushed onto the stack– When the function is complete the return address is popped off the stack and the

microcontroller will execute the next instruction after the function call

Page 20: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-20 8051 Architecture

Special Function Registers (SFRs)• The SFRs are registers in internal data memory that allow control of the 8051

µController functionality– SFRs P0 to P3 allow access to the 8051’s I/O pins

• e.g. P1 = 0xFF //write all ‘1’s to the 8 Port 1 pins– The SFRs shown in blue are used to configure the 8051 timers, serial port and

interrupts– The remaining SFRs can be used for arithmetic/logic operations (ACC and B

registers), control or status.• All SFRs whose address is divisible by 8 are bit addressable.

Page 21: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-21 8051 Architecture

Special Function Registers (SFRs)

F8H

BF0H

E8H

ACCE0H

D8H

PSWD0H

C8H

C0H

IPB8H

P3B0H

IEA8H

P2A0H

SBUFSCON98H

P190H

TH1TH0TL1TL0TMODTCON88H

PCONDPHDPLSPP080H

Page 22: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-22 8051 Architecture

8051 Memory Quiz• How many register banks does the 8051 have?• How much internal program memory does an 8051 contain?• Where is the 8051 stack located?• What is the function of the stack?• How much external data memory may be connected to the 8051?

Page 23: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-23 8051 Architecture

8051 Timers• The 8051 has 2 internal 16-bit timers named Timer 0 and Timer 1• The timers have 2 modes of operation

– Timer mode allows the timer to count internal clock pulses• The timer register is updated every machine cycle (12 oscillator clocks)• Applications include delays, real time clocks etc

– In counter mode the timer can be used to count external events• The timer register is incremented every time an external timer pin goes high

to low• Applications include pulse width and frequency measurement

Page 24: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-24 8051 Architecture

8051 Serial Port• The 8051 has an on-board UART that may be used to provide a serial interface to

external devices– Example serial devices are GPS receivers, GSM MODEMs

• 2 Port 3 pins (TXD and RXD) provide the external interface• The Baud rate can be programmed using timer 1

Page 25: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-25 8051 Architecture

8051 Interrupt Structure• The 8051 has 5 interrupt sources

– 2 external interrupt pins• An interrupt is generated when the pin goes low• These pins may be used to allow an external device to interrupt the 8051

– e.g. keypad, analog to digital converter– 2 timer interrupts

• 8051 is interrupted when a timer register overflows– Serial port interrupt

• Interrupt occurs when a character has been transmitted or received over the serial port

• Interrupts may be individually enabled or disabled• Interrupts may be prioritised

Page 26: 8051 Microcontroller - Welcome to gmitWEBgmitweb.gmit.ie/electronics/nokeeffe/Semester 1 2009/Embedded...8051 Microcontroller • The 8051, ... • Some 8051 pins have alternate applications

Embedded Systems 1 2-26 8051 Architecture

Atmel 89C51RE2