Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051...

32
Intel 8051 Intel 8051 Another family of Another family of microcontroller is the Intel microcontroller is the Intel 8051 family. The basic 8051 8051 family. The basic 8051 microcontroller has four microcontroller has four parallel input/output ports, parallel input/output ports, port 0, 1, 2 and 3. The 8051AH port 0, 1, 2 and 3. The 8051AH version has 4K x 8 bytes ROM , version has 4K x 8 bytes ROM , 128 x 8 bytes RAM, two 16-bit 128 x 8 bytes RAM, two 16-bit timers and interrupt control for timers and interrupt control for five interrupt sources. five interrupt sources.

Transcript of Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051...

Page 1: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

Another family of microcontroller is Another family of microcontroller is the Intel 8051 family. The basic 8051 the Intel 8051 family. The basic 8051 microcontroller has four parallel microcontroller has four parallel input/output ports, port 0, 1, 2 and 3. input/output ports, port 0, 1, 2 and 3. The 8051AH version has 4K x 8 bytes The 8051AH version has 4K x 8 bytes ROM , 128 x 8 bytes RAM, two 16-bit ROM , 128 x 8 bytes RAM, two 16-bit timers and interrupt control for five timers and interrupt control for five interrupt sources. interrupt sources.

Page 2: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

The 8051 is a second-generation Intel The 8051 is a second-generation Intel 8-bit microcontroller. The first Intel 8-8-bit microcontroller. The first Intel 8-bit microcontroller was the 8048.bit microcontroller was the 8048.

Later, Intel introduced the 8049, which Later, Intel introduced the 8049, which double the amount of ROM and RAM. double the amount of ROM and RAM. Its architecture is the same as the 8048Its architecture is the same as the 8048

A later introduction, the 8052, expands A later introduction, the 8052, expands the size of ROM and RAM, but the size of ROM and RAM, but otherwise the architecture is the same otherwise the architecture is the same as the 8051.as the 8051.

Page 3: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 An 8-bit ALUAn 8-bit ALU 4K x 8 ROM (or EPROM)4K x 8 ROM (or EPROM) 128 x RAM128 x RAM Dual 16-bit timer event counterDual 16-bit timer event counter 32 I/O lines (4 I/O ports, 8-bit each)32 I/O lines (4 I/O ports, 8-bit each) Powerful 111-instruction setPowerful 111-instruction set Full-featured serial portFull-featured serial port Up to 12-Mhz clockUp to 12-Mhz clock Two external interruptsTwo external interrupts

Page 4: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

The 8051 can address external The 8051 can address external memory if there is not enough memory if there is not enough internal RAM and/or ROM. When used internal RAM and/or ROM. When used to address external memory, two to address external memory, two ports provide the memory addressing.ports provide the memory addressing.

The 8051 internal ROM is for program The 8051 internal ROM is for program memory space. The program memory memory space. The program memory space is a read-only space. The space is a read-only space. The processor cannot write data or read processor cannot write data or read data from these memory locations.data from these memory locations.

Page 5: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 The RAM is the data memory space. It is The RAM is the data memory space. It is

a read-write memory space.a read-write memory space. The processor can read data from this The processor can read data from this

memory space and can write data to this memory space and can write data to this memory space. It cannot execute memory space. It cannot execute program instructions from this memory program instructions from this memory space.space.

The 128 bytes of internal RAM (00H to The 128 bytes of internal RAM (00H to 7FH) provide general read-write data 7FH) provide general read-write data storage. Part of this memory space is storage. Part of this memory space is often referred to as general purpose often referred to as general purpose registers.registers.

Page 6: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

The 8051 also has 22 special-function The 8051 also has 22 special-function registers occupy data memory space registers occupy data memory space from 80H to F8H. Although addressable from 80H to F8H. Although addressable as memory locations, these registers as memory locations, these registers must be used for their intended purpose.must be used for their intended purpose.

If more program memory (ROM) is If more program memory (ROM) is needed, the internal 4-Kbyte memory needed, the internal 4-Kbyte memory can be expanded by additional 60-can be expanded by additional 60-Kbytes, giving the 8051 a full 64-kbytes Kbytes, giving the 8051 a full 64-kbytes program memory space. (see figure 9.1)program memory space. (see figure 9.1)

Page 7: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

If the 8051 EA pin is connected to If the 8051 EA pin is connected to ground, it does not use the internal ground, it does not use the internal 4K ROM. The external memory must 4K ROM. The external memory must start at memory location 0000H and start at memory location 0000H and can be up to a full 64kbytes. (8031 can be up to a full 64kbytes. (8031 does not have internal ROM)does not have internal ROM)

Intel 8051Intel 8051

Page 8: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Figure 9.1Figure 9.1

Page 9: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Figure 9.2Figure 9.2

Page 10: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

If you need more RAM, you can add If you need more RAM, you can add external data memory. You always external data memory. You always have full use of all 64-kbytes of the have full use of all 64-kbytes of the external memory space. This memory external memory space. This memory is addressed separately from the is addressed separately from the internal 128 bytes of RAM.internal 128 bytes of RAM.

Page 11: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Downloaded ProgramDownloaded Program

Although the 8051 normally operates Although the 8051 normally operates with separate program memory and with separate program memory and data memory space, there are data memory space, there are applications where 8051 can input a applications where 8051 can input a block of data through its serial block of data through its serial communications port, load that data communications port, load that data into memory, and then execute that into memory, and then execute that data as a program. It is a very common data as a program. It is a very common technique used to change the program technique used to change the program operating in a remote microprocessor-operating in a remote microprocessor-based controller.based controller.

Page 12: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051 Internal RAMIntel 8051 Internal RAM The first 32 RAM locations are addressable The first 32 RAM locations are addressable

as registers or as memory locations. By as registers or as memory locations. By calling some memory locations registers, we calling some memory locations registers, we can access them with single-byte instruction.can access them with single-byte instruction.

16 bytes of 8051 RAM are both bit and byte-16 bytes of 8051 RAM are both bit and byte-addressable. The general instructions can addressable. The general instructions can address a byte of data at these memory address a byte of data at these memory locations. Other special instructions can locations. Other special instructions can address any individual bit in these memory address any individual bit in these memory locations. Bit instructions are very powerful locations. Bit instructions are very powerful tools when you need to process data words tools when you need to process data words from external hardware devices.from external hardware devices.

Page 13: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051 Internal Intel 8051 Internal RAM ..RAM ..

Figure 9.2 is a memory map of the first Figure 9.2 is a memory map of the first 128 internal memory locations. The first 128 internal memory locations. The first 32 memory locations can be used as four 32 memory locations can be used as four register banks. There are eight registers register banks. There are eight registers in each bank. A register is an 8-bit read-in each bank. A register is an 8-bit read-write memory location which is write memory location which is addressed in a single-byte instruction. addressed in a single-byte instruction. Because these single-byte instructions Because these single-byte instructions have only 3 bits available to address the have only 3 bits available to address the register, they address only one of eight register, they address only one of eight registers.registers.

Page 14: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Special Function Special Function RegistersRegisters

Special-function registers (SFRs). Each Special-function registers (SFRs). Each special-function register is dedicated to special-function register is dedicated to a single job.a single job.

The microprocessor’s SFRs are the The microprocessor’s SFRs are the accumulator (ACC E0H), the B register accumulator (ACC E0H), the B register (B F0H), the program status word (PSW (B F0H), the program status word (PSW D0H), the stack pointer (SP 81H), the D0H), the stack pointer (SP 81H), the data pointer (DPTR) which is a 2 bytes data pointer (DPTR) which is a 2 bytes register (DPL 82H and DPH 87H), and register (DPL 82H and DPH 87H), and the power control register (PCON 87H).the power control register (PCON 87H).

Page 15: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Special Function Special Function RegistersRegisters

Some of these SFRs are bit- and byte-Some of these SFRs are bit- and byte-addressable and others are only byte-addressable and others are only byte-addressable.addressable.

The accumulator is byte- or bit-The accumulator is byte- or bit-addressable. It contains the operands or addressable. It contains the operands or one of the operands of arithmetic or one of the operands of arithmetic or logical instruction and holds the result of logical instruction and holds the result of that instruction.that instruction.

The B register is used during multiply The B register is used during multiply and divide operations as one 8-bit source and divide operations as one 8-bit source and to hold the high-order 8 bits. It also and to hold the high-order 8 bits. It also can be as a simple scratch-pad register.can be as a simple scratch-pad register.

Page 16: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Special Function Special Function RegistersRegisters

The program status word (PSW) is the 8051 The program status word (PSW) is the 8051 status register. It is a bit-addressable status register. It is a bit-addressable register.register.

77 CYCY PSW.7PSW.7 Carry flagCarry flag66 ACAC PSW.6PSW.6 Auxiliary carry flagAuxiliary carry flag55 F0F0 PSW.5PSW.5 For general purpose useFor general purpose use44 RS1RS1 PSW.4PSW.4 Register bank selector bit 1Register bank selector bit 133 RS0RS0 PSW.3PSW.3 Register bank selector bit 0Register bank selector bit 022 OVOV PSW.2PSW.2 Overflow bitOverflow bit11 -- PSW.1PSW.1 ReservedReserved00 PP PSW.0PSW.0 Parity flagParity flag

Page 17: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Special Function Special Function RegistersRegisters

Note that the 8051 PSW does not have zero bit.Note that the 8051 PSW does not have zero bit.

Two special bits in the PSW (RS1 and RS0) Two special bits in the PSW (RS1 and RS0) indicate the current register bank. These bits indicate the current register bank. These bits can be set to select the current register bank can be set to select the current register bank or can be read to find out what register bank is or can be read to find out what register bank is selectedselected

The 8051 stack pointer register is an 8-bit The 8051 stack pointer register is an 8-bit register, so it only addresses memory locations register, so it only addresses memory locations within the internal 128-bytes memory. It is within the internal 128-bytes memory. It is incremental just before data is stored by using incremental just before data is stored by using the push or call instruction, or the interrupt. the push or call instruction, or the interrupt.

Page 18: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Data PointerData Pointer

The data pointer (DPTR) is a 16-bit The data pointer (DPTR) is a 16-bit register. It is made up of a High byte register. It is made up of a High byte (DPH) and a Low byte (DPL). The data (DPH) and a Low byte (DPL). The data pointer holds a 16-bit address used pointer holds a 16-bit address used when addressing external memory. The when addressing external memory. The 8051 instructions let you work with the 8051 instructions let you work with the data pointer as a 16-bit register or as data pointer as a 16-bit register or as two separate 8-bit registers. If needed, two separate 8-bit registers. If needed, a single- or double-byte instruction can a single- or double-byte instruction can operate on either the High or Low byte.operate on either the High or Low byte.

Page 19: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Power Control RegisterPower Control Register Two bits of this register, PD (Power Two bits of this register, PD (Power

Down) and IDL (Idle), are only used in Down) and IDL (Idle), are only used in CMOS versions of the 8051.CMOS versions of the 8051. Bit 7 Bit 7 SMODSMOD Double baud rate bitDouble baud rate bitBit 3Bit 3 GF1GF1 General purpose flag General purpose flag bitbitBit 2Bit 2 GF0GF0 General purpose flag General purpose flag bitbitBit 1Bit 1 PDPD Power down bitPower down bitBit 0Bit 0 IDLIDL Idle mode bitIdle mode bit

Page 20: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Counter-Timer Control Counter-Timer Control RegisterRegister

TCON is used to control the function TCON is used to control the function of counter-timer.of counter-timer.

TF1TF1 TCON.7TCON.7 Timer 1 overflow flagTimer 1 overflow flagTR1TR1 TCON.6TCON.6 Timer 1 run control bitTimer 1 run control bitTF0TF0 TCON.5TCON.5 Timer 0 overflow flagTimer 0 overflow flagTR0TR0 TCON.4TCON.4 Timer 0 run control bitTimer 0 run control bitIE1IE1 TCON.3TCON.3 External interrupt 1 flagExternal interrupt 1 flagIT1IT1 TCON.2TCON.2 Interrupt 1 type controlInterrupt 1 type controlIE0IE0 TCON.1TCON.1 External interrupt 0 flagExternal interrupt 0 flagIT0IT0 TCON.0TCON.0 Interrupt 0 type controlInterrupt 0 type control

Page 21: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Counter-Timer Mode Control Counter-Timer Mode Control RegisterRegister

It is used to set the mode of counter-timers.It is used to set the mode of counter-timers.

BitBit 77 (Timer 1) Gate, when TR1 of (Timer 1) Gate, when TR1 of TCON is TCON is set and Gate=1, Timer1 will set and Gate=1, Timer1 will run only run only while INT1 pin is high.while INT1 pin is high.

Bit 6Bit 6 (Timer 1), C/T, timer or counter (Timer 1), C/T, timer or counter selectorselector

Bit 5Bit 5 (Timer 1) M1, Mode selector bit 1(Timer 1) M1, Mode selector bit 1

Bit 4Bit 4 (Timer 1) M0, Mode selector bit 0(Timer 1) M0, Mode selector bit 0

Page 22: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

8051 Interrupt System8051 Interrupt System

There are five different ways to There are five different ways to interrupt an 8051. Two of these are interrupt an 8051. Two of these are from external electrical signals. The from external electrical signals. The other three are caused by internal other three are caused by internal 8051 I/O hardware operations.8051 I/O hardware operations.

The two external inputs come from The two external inputs come from the INT0 and INT1 inputs. A logic 0 the INT0 and INT1 inputs. A logic 0 on INT0 sets bit IE0 (interrupt on INT0 sets bit IE0 (interrupt external 0) in the timer control external 0) in the timer control register. A logic 0 on INT1 sets bit IE1register. A logic 0 on INT1 sets bit IE1

Page 23: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

Page 24: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Page 25: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051 Intel 8051

Port 0 is at address 80H, port 1 at Port 0 is at address 80H, port 1 at address 90H, port 2 at address A0H address 90H, port 2 at address A0H and port 3 at address B0H. When a and port 3 at address B0H. When a port is to be used as an output port port is to be used as an output port the data is put into the corresponding the data is put into the corresponding special register. When a port is to be special register. When a port is to be used as an input port, the value FFH used as an input port, the value FFH must first be written to it.must first be written to it.

Page 26: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 RXD is the serial input portRXD is the serial input port TXD is the serial output portTXD is the serial output port INT0 is the external interrupt 0INT0 is the external interrupt 0 INT1 is the external interrupt 1INT1 is the external interrupt 1 T0 is the timer/counter 0 external inputT0 is the timer/counter 0 external input T1 is the timer/counter 1 external inputT1 is the timer/counter 1 external input WR is the external memory write strobe WR is the external memory write strobe RD is the external memory read strobeRD is the external memory read strobe

Page 27: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

The term strobe describes a connection The term strobe describes a connection used to enable or disable a particular used to enable or disable a particular function.function.

ALEALE

The The address latch enableaddress latch enable pin provides pin provides an output pulse for latching the low-an output pulse for latching the low-order byte of the address during order byte of the address during access access to external memoryto external memory. This allows 16-bit . This allows 16-bit addresses to be used. (see next slide)addresses to be used. (see next slide)

Page 28: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Use of ALEUse of ALE

Page 29: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 PSENPSEN

The The program store enableprogram store enable pin is the read pin is the read signal pin for external program memory and is signal pin for external program memory and is active when low. It is connected to the output active when low. It is connected to the output enable pin of external ROM or EPROM.enable pin of external ROM or EPROM.

EAEAThe external access pin is taken low for the The external access pin is taken low for the microprocessor to access only external microprocessor to access only external program code; when high it automatically program code; when high it automatically accesses internal or external code, depending accesses internal or external code, depending on the address. This pin also used on a on the address. This pin also used on a microcontroller with EPROM to receive the microcontroller with EPROM to receive the programming supply voltage for programming programming supply voltage for programming the EPROMthe EPROM

Page 30: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051

XTAL1, XTAL2XTAL1, XTAL2

These are the connecting pins for a These are the connecting pins for a crystal or external oscillator.crystal or external oscillator.

RESETRESETA high signal for a minimum of two A high signal for a minimum of two machine cycles on this pin resets the machine cycles on this pin resets the microcontroller.microcontroller.

Page 31: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 Serial input/outputSerial input/output

Writing to the serial data buffer SBUF at Writing to the serial data buffer SBUF at address 99H load data for transmission; address 99H load data for transmission; reading SBUF accesses received data.reading SBUF accesses received data.

TimingTimingThe timer mode register TMOD at The timer mode register TMOD at address 89H is used to set the operating address 89H is used to set the operating mode for timer 0 and timer 1. The timer mode for timer 0 and timer 1. The timer control register TCON contains status control register TCON contains status and control bit for timer 0 and timer 1.and control bit for timer 0 and timer 1.

Page 32: Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,

Intel 8051Intel 8051 InterruptsInterrupts

Interrupts force program to call a Interrupts force program to call a subroutine located at a specified address in subroutine located at a specified address in memory; they are enable by writing to the memory; they are enable by writing to the interrupt enable register IE at address A8H.interrupt enable register IE at address A8H.

Bit 7 = EA (Global Enable/Disable)Bit 7 = EA (Global Enable/Disable)Bit 4 = ES (Enable serial port interrupt)Bit 4 = ES (Enable serial port interrupt)Bit 3 = ET1 (Enable Timer 1 interrupt)Bit 3 = ET1 (Enable Timer 1 interrupt)

Bit 2 = EX1 (Enable external 1 interrupt)Bit 2 = EX1 (Enable external 1 interrupt)Bit 1 = ET0 (Enable timer 0 interrupt)Bit 1 = ET0 (Enable timer 0 interrupt)Bit 0 = EX0 (Enable external 0 interrupt)Bit 0 = EX0 (Enable external 0 interrupt)