You are on page 1of 38

Design By: Harman S.

Gahir AP,MCA CGC-Gharuan

Overview
Introduction Block Diagram and Pin Description of the 8051 Registers Memory mapping in 8051 Stack in the 8051 Interrupts Applications

Why do we need to learn Microcontrollers ?


Its not an exaggeration if I say that ,today

there is no electronic gadget on the earth which is designed without a Microcontroller. Ex: communication devices, digital entertainment, portable devices etc

Not believable ??? See the next slide

Personal information products: Cell phone,

pager, watch, pocket recorder, calculator Laptop components: mouse, keyboard, modem, fax card, sound card, battery charger Home appliances: door lock, alarm clock, thermostat, air conditioner, TV remote, VCR, small refrigerator, exercise equipment, washer/dryer, microwave oven Industrial equipment: Temperature/pressure controllers, Counters, timers, RPM Controllers Toys: video games, cars, dolls, etc.

Microcontroller Applications

Then What is a Microcontroller ?


A smaller computer On-chip RAM, ROM, I/O ports... Example Motorolas 6811, Intels 8051, Zilogs Z8

and PIC 16X

CP U

RAM

ROM Seri I/O Time al Port r COM Port

A single chip Microcontrolle r

How is it different from a Microprocessor ??


General-purpose microprocessor

CPU for Computers No RAM, ROM, I/O on CPU chip itself Example Intels x86, Motorolas 680x0 CPU GeneralPurpose Microprocesso r Data Bus RAM ROM I/O Port Time r Seri al COM Port

Address Bus

Microprocessor vs. Microcontroller


Microprocessor CPU is stand-alone, RAM, ROM, I/O, timer are separate designer can decide on the amount of ROM, RAM and I/O ports. expansive general-purpose Microcontroller CPU, RAM, ROM, I/O and timer are all on a single chip fix amount of on-chip ROM, RAM, I/O ports for applications in which cost, power and space are critical single-purpose

Original 8051 Microcontroller


Oscillator and timing 4096 Bytes
Program Memory

(ROM)

128 Bytes Data Memory (RAM)

Two 16 Bit Timer/Event Counters

8051 CPU 64 K Byte Bus Expansion Control


subsystem interrupts External interrupts Control

Internal data bus


Programmable I/O Programmable Serial Port Full Duplex UART Synchronous Shifter

Parallel ports Address Data Bus I/O pins

Serial Output Serial Input

8051 Microcontroller Block Diagram

A and B CPU Register


The 8051 contains 34 general purpose or working registers. Two of these Register A and B. The immediate result is stored in the accumulator register (Acc) for next operation. The B register is a register just for multiplication and division operation which requires more register spaces for the product of multiplication and the quotient and the remainder for the division.

The 8051 Architecture consist of these specific features


The 8 bit CPU with Registers A and B Internal ROM 16-bit program counter(PC) and data pointer(DPTR) Internal RAM of 128 bytes 8-bit Program Status word(PSW) Two 16 bit Counter / timers 4 eight-bit ports 3 internal interrupts and 2 external interrupts. Control register Oscillator and clock circuits.

Program status word(PSW)


The PSW contain the math flags, User program flag F0,and the register select bits that identify which of the four General-purpose register banks is currently in use by the program. The math flags include carry(c),auxiliary carry(AC), overflow(OV) and parity(p)

Program Status Word (PSW)

The 8051 oscillator and clock


The 8051 requires an external oscillator circuit. The oscillator circuit usually runs around 12MHz. The crystal generates 12M pulses in one second. A machine cycle is minimum amount time must take by simplest machine instruction An 8051 machine cycle consists of 12 crystal pulses (clock cycle). The first 6 crystal pulses (clock cycle) is used to fetch the Opcode and the second 6 pulses are used to perform the operation on the operands in the ALU. This gives an effective machine cycle rate at 1MIPS (Million Instructions Per Second).

Program counter (PC)


The program counter points to the address of the next instruction to be Executed As the CPU fetches the opcode from the program ROM, the program counter is increasing to point to the next instruction. The program counter is 16 bits wide This means that it can access program addresses 0000 to FFFFH, a total of 64K bytes of code

Data pointer (DPTR)


The data pointer is 16 bit register. It is used to hold the address of the data in the memory. The DPTR register can be accessed separately as lower eight bit(DPL) and higher eight bit (DPH). It can be used as a 16 bit data register or two independent data register.

The stack and The stack pointer (SP)


The stack is a section of RAM used by the CPU to store information temporarily This information could be data or an address The register used to access the stack is called the SP (stack pointer) register The stack pointer in the 8051 is only 8 bit wide.

Operation of stack
push pop

stack pointer stack

8051 Pin Diagram

Pin Diagram Description


Port 0 Port 0(pins 32 to 39) is a dual purpose port. In minimum component designs, it is used as general purpose IO port and for larger design with external memory, it functions as multiplexed address/data bus. Port 1 Port 1(pin 1 to pin 8) is a dedicated IO port Port 2 It is a dual purpose port as well as general purpose IO poer or as the higher byte of the address bus Port 3 It acts as a dual purpose port as well as general purpose IO Port. These pins are multifunctional

Pin Diagram Description


Bit P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3,7 P1.0 P1.1 Name RxD TxD INT0 INT1 T0 T1 WR RD T2 T2EX Alternate Function Receive data for serial port Transmit data for serial port External Interrupt 0 External Interrupt 1 Timer/Counter 0 external input Timer/Counter 1 external input External data memory write strobe External data memory read strobe Timer/Counter 2 external input Timer/Counter Capture/reload

PSEN(Program Store Enable)

Pin Diagram Description


It is an output signal on pin 29 which enables external program

memory and generally connects to an EPROM The PSEN signals goes LOW during an instruction fetch and remains HIGH during execution of an instruction.

ALE
Address Latch Enable is used by 8051 for de-multiplexing the

address and data bus

EA(External Access)
If the EA pins goes HIGH, the 8051 execute program from internal

ROM, otherwise execute program from external memory only.

RST(Reset)
It is used to reset 8051 microcontrollers

Power Connection
8051 requires a single +5V power supply for its operations

Internal Memory
There are 128 bytes of RAM in the 8051 Assigned addresses 00 to 7FH The 128 bytes are divided into three different groups as follows: A total of 32 bytes from locations 00 to 1F hex are set aside for register banks and the stack.
Bits RS0 and RS1 in the PSW determine which bank of register is currently Is use. Bank 0 is selected upon reset.

A total of 16 bytes from locations 20H to 2FH are set aside for bit-addressable read/write memory. A total of 80 bytes from locations 30H to 7FH are used for read and write storage. Four register banks: 00 to 1F hexadecimal.

Sachin Bhalavat (9409049436)

External memory
External memory is used in cases when the internal ROM and RAM memory Available On chip is not sufficient. Two separate are made available by the 16-bit PC and the DPTR and by different control pins for enabling external ROM and RAM chips. If the 128 bytes of internal RAM is insufficient, the external RAM is accessed by the DPTR. In the 8051 family, external RAM of upto 64 KB can be added to any chip.

Timer/Counters
Two 16-bit up counters, named T0 and T1, are provided for the general use of the programmer. The 8051 has two timers/counters, they can be used either as Timers to generate a time delay or as Event counters to count events happening outside the microcontroller Both Timer 0 and Timer 1 are 16 bits wide Since 8051 has an 8-bit architecture, each 16-bits timer is accessed as two separate registers of low byte and high byte The counters are divided into two 8-bit registers called the timer low (TL0,TL1) and high (TH0, TH1) bytes.

8051 Interrupts
An interrupt is the occurrence of a condition an

event - which interrupts normal program flow


Interrupts allow a system to respond to

asynchronous events (not in program flow) and handle the events while another task is running. called an Interrupt Service Routine (ISR) or an interrupt handler of either an external or an internal event.

The routine that deals with a specific interrupt is

Interrupts routines are activated by the occurrence

Interrupt routines are said to run in the

background while the main system program

Interrupts allow the 8051 to respond to asynchronous events

Interrupt Service

(external or internal) only when required.


Interrupts introduce the concept of priority where one

interrupt is given preference over another simultaneous interrupt


Interrupt Vectors--where is the address of the ISR when a

particular interrupt occurs? 8051 Interrupt Vector Table (Atmel 89C51RD2 has 3 more not covered) Interrup Vector Number Pin Flag Comment
t Reset INT0 TF0 INT1 TF1 RI/TI TF2/EXF 2 Address 0000H 0003H 000BH 0013H 001BH 0023H 002Bh Bytes 3 8 8 8 8 8 3 P3.3 P3.2 Clearing Auto Auto Auto Auto Auto Programmer Programmer Power-on External Hardware Timer 0 External Hardware Timer 1 Serial Communication Timer 2

Interrupt Service Sequence


When an interrupt is activated the 8051
Finishes the instruction currently being executed Saves the current status of all the interrupts and stores the

current PC Stack Vectors (i.e. jumps) to the corresponding location within the interrupt vector table, i.e. PC Vector Table address Option 1: If the ISR fits in the available space you can immediately service the interrupt Option 2: If the ISR is too large then the vector table contains a long jump (ljmp) to the Interrupt Service Routing (ISR) The last instruction of the ISR is a reti (Return from Interrupt) Responsibility of ISR to save/restore any registers that it uses, including the PSW, having the same number of pushes and pops to/from the stack for the reti instruction

Interrupt 5 Interrupt Sources (in order of priority): System


1 2 3 4 5 External Interrupt 0 (IE0) Timer 0 (TF0) External Interrupt 1 (IE1) Timer 1 (TF1) Serial Port (RI/TI)

Each interrupt type has a separate vector address. Each interrupt type can be programmed to one of two priority levels.

Interrupt vector Addresses


Source IE0 TF0 IE1 TF1 RI&TI Address 03H 0BH 13H 1BH 23H

The 8051 starts execution at 0000H after Reset.

You might also like