0% found this document useful (0 votes)
26 views

Microcontroller 8051 Notes

The document discusses microcontrollers and their features. A microcontroller incorporates features found in a microprocessor such as RAM, ROM, I/O ports, timers, and interrupts. It is an entire computer manufactured on a single chip. Microcontrollers are embedded in applications like engine controllers and cameras. They have on-chip facilities like serial ports, timers, and analog-to-digital converters selected based on the target application. The 8051 was the first microcontroller in the MCS-51 family introduced by Intel in the 1970s.

Uploaded by

Pretty Fibber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Microcontroller 8051 Notes

The document discusses microcontrollers and their features. A microcontroller incorporates features found in a microprocessor such as RAM, ROM, I/O ports, timers, and interrupts. It is an entire computer manufactured on a single chip. Microcontrollers are embedded in applications like engine controllers and cameras. They have on-chip facilities like serial ports, timers, and analog-to-digital converters selected based on the target application. The 8051 was the first microcontroller in the MCS-51 family introduced by Intel in the 1970s.

Uploaded by

Pretty Fibber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

The microcontroller incorporates all the features that are found in microprocessor.

The microcontroller has built in ROM, RAM, Input Output ports, Serial Port, timers, interrupts
and clock circuit. A microcontroller is an entire computer manufactured on a single chip. Microcontrollers are usually dedicated devices embedded within an application. For
example, microcontrollers are used as engine controllers in automobiles and as exposure and focus controllers in cameras. In order to serve these applications, they have a high
concentration of on-chip facilities such as serial ports, parallel input output ports, timers, counters, interrupt control, analog-to-digital converters, random access memory, read
only memory, etc. The I/O, memory, and on-chip peripherals of a microcontroller are selected depending on the specifics of the target application. Since microcontrollers are
powerful digital processors, the degree of control and programmability they provide significantly enhances the effectiveness of the application. The 8051 is the first
microcontroller of the MCS-51 family introduced by Intel Corporation at the end of the 1970s.
CRITERIA FOR SELECTION OF A MICROCONTROLLERIN EMBEDDED SYSTEM
Criteria for selection of microcontroller in any embedded system is as following:
(a) Meeting the computing needs of task at hand efficiently and cost effectively

 Speed of operation
 Packing
 Power consumption
 Amount of RAM and ROM on chip
 No. of I/O pins and timers on chip Cost
(b) Availability of software development tools such as compiler, assembler and debugger
Bus System
A bus is a common electrical pathway between multiple devices
OR
A Bus is a set of physical connections used for communication between CPU and peripherals.
• Can be internal to the CPU to transport data to and from the ALU.
• Can be external to the CPU, to connect it to memory or to I/O devices.
Data Bus
Function of a data bus is to send data from one device to another
Data is passed in parallel or serial manner.
It is bidirectional.
Microcontroller 8051 has 8 bits of the data bus.
Address Bus
CPU needs to read an instruction (data) from a given location in memory. It is used to address memory locations and to transfer the address from CPU to Memory of the
microcontroller.
Identify the source or destination of data
Bus width determines maximum memory capacity of system
It is unidirectional.
Microcontroller 8051 has a 16-bit address bus
Control Bus
The control bus is used for sending control signals to the memory and I/O devices. It provides read or write signals to the device to indicate that the CPU is asking for information
or sending it information.

Address Bus Data Bus


It is used to address memory locations and to transfer the address from CPU to Memory The data bus is used to send data from one device to another
of the microcontroller.

Identify the source or destination of data Data is passed in parallel or serial manner.

It is unidirectional. It is bidirectional.

Microcontroller 8051 has a 16-bit address bus Microcontroller 8051 has 8 bits of the data bus.

Program Memory
It is used for storing the hexadecimal codes of the program to be executed i.e., instructions. In 8051 Microcontroller, the code or instructions to be executed are stored in the
Program Memory, which is also called as the ROM of the Microcontroller. The original 8051 Microcontroller by Intel has 4KB of internal ROM.
Program memory is generally non-volatile memory, meaning it holds information over time without a need of power source.
Data memory, which is required for temporary data and intermediate results storage while the instructions are being executed. Data memory is volatile, meaning the data it holds
is temporary and is only maintained if the device is connected to a power source. Original Intel’s 8051 Microcontroller had 128Bytes of internal RAM. But almost all modern
variants of 8051 Microcontroller have 256Bytes of RAM.
Program Memory Data memory
The code or instructions to be executed are stored in the Program Memory. Temporary data and intermediate results are stored in the Program Memory.
The original 8051 Microcontroller by Intel has 4KB of internal ROM. The original 8051 Microcontroller by Intel has 128Bytes of RAM.
Program memory is generally non-volatile memory. Data memory is generally non-volatile memory.

Von Neuman Architecture

 The Von Neumann Architecture follows the concept of a stored-program computer concept.
 The Von Neumann's architecture uses single memory for their instruction and data.
 It requires single bus for both instruction and data.
 The CPU is not able to read/write data and access instructions at the same time.
 Instructions and data have to be fetched in sequential order limiting the operation bandwidth.

Harvard Architecture

 Harvard Architecture is a modern type of computer architecture based on the relay-based model by
Harvard Mark I.
 The Harvard Architecture uses two separate memories for their instruction and data.
 It uses separate buses for the transfer of both data and instructions.
 The CPU is able to read/write data and access instructions at the same time.
 Instructions and data can be fetched simultaneously.

Parameters Von Neumann Architecture Harvard Architecture


Definition The Von Neumann Architecture follows the concept of a stored- Harvard Architecture is a modern type of computer architecture
program computer concept. based on the relay-based model by Harvard Mark I.
Physical It uses one single memory for accessing and storing both data It uses two separate memories for storing and accessing both
Address and instructions. instructions and data.
Buses One common signal path (bus) helps in the transfer of both It uses separate buses for the transfer of both data and instructions.
instruction and data.
Number of It requires two clock cycles for executing a single instruction. It executes any instruction using only one single cycle.
Cycles
Cost It is comparatively cheaper in cost than Harvard Architecture. It is comparatively more expensive than the Von Neumann
Architecture.
Access to CPU The CPU is not able to read/write data and access instructions at The CPU can easily read/write data as well as access the
the same time. instructions at any given time.
Uses This method comes to play in the case of small computers and This architecture is best for signal processing as well as
personal computers. microcontrollers.

Microprocessor Microcontroller
A Microprocessors is the heart of a computer system. A Microcontrollers is the heart of an embedded system.

It has only a memory so its memory and I/O components It has a processor along with its internal memory and the
required to connect externally I/O components.
It has not any ROM, RAM, and other peripherals. It has ROM, RAM, and other peripherals.
Large Circuit Smaller Circuit
Not compatible with compact systems Compatible with compact systems.
Higher cost Lower Cost
High Power Consumption Low Power Consumption
Mostly don’t have power Saving features Mostly have power saving features.
Mainly present in personal computers. Mainly present in washing machines, music players, and
embedded systems.
Less number of registers. More number of registers.
Made on a silicon-based integrated chip. By product microprocessors and peripherals.
Has a high speed. Speed depends on the architecture.
Ideal for general purpose to handle
Ideal for the specific applications.
more data.
Requires more instructions Requires less instructions

Complex and Expensive Simple and affordable


Features of 8051 Microcontroller are

 An 8-bit CPU with two registers A (ACC or accumulator) and B


 8-bit data bus.
 16-bit address bus - Address bus is of 16 bits (A0-A15) and can transfer maximum 16-bit address and hence can address 65,536 different memory locations.
 4KB on-chip programmable ROM (Program Memory) for storing program code
 128 bytes on-chip RAM (Data Memory) for temporary data storage
 40 pin IC in DIP packaging with 32 pins available for I/O (4 I/O ports)
 Two 16-bit timers – T0 and T1
 6 Interrupt sources – Two external and three internal and Reset
 Serial Data Transmitter and Receiver for Full-Duplex operation – SBUF
 Control Registers – SCON, PCON, TCON, TMOD, IP and IE
 The program counter in the 8051 is 16 bits wide
 64K external program memory can be read by PSEN
 64K external data memory can be read or write by RD and WR.
 Code memory is selectable by EA (internal or external)
Architecture of 8051

Accumulator: ACC is an 8-bit special function register. It acts an operand register. Result is temporarily stored in this register. It is used in parallel I/O transfer.
B Register: B register is 8-bit SFR. This register is used in only two instructions MUL AB and DIV AB. For other operations, it can be used as a scratch pad register.
PC-Program Counter: Points to the address of next instruction to be executed from ROM
• It is 16-bit register means the 8051 can access program address from 0000H to FFFFH. (64K bytes code)
Initial value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (0000H)
Final value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 (FFFFH)
• Initially PC has 0000H
• ORG instruction is used to initialize the PC ORG 0000H means PC initialize by 0000H
• PC is incremented after each instruction
Program Status Word (PSW): PSW register is 8-bit SFR. It contains program status information. It is also used to select any one of the required register banks.

Stack Pointer (SP): It is 8-bit register. It is used to point the stack memory. The stack may reside in anywhere in on-chip memory. It is incremented before data is stored
during PUSH & CALL instructions. After reset SP is initialized to 07h. This causes the stack begin at location 08h.
Data Pointer (DPTR): It is 16-bit register. It may be manipulated as a 16 bit register or as two independents 8-bit registers. Its function is to hold a 16-bit address.
This register is used for external reference. DPH for Higher order 8 bits, DPL for lower order 8 bit
Port 0 to Port 3: Each port contains separate address. Using this address, User can communicate with these ports. Each port contains latch, output driver & input buffer
Serial Data Buffer: Serial data buffer contains two independent registers of a transmit buffer register and a receiver buffer register.
Timer Registers: Register pairs (TH0, TL0) & (TH1, TL1) are the two 16-bit counting registers for Timer/Counter 0 and 1 respectively
Control Registers: The special function registers IP, IE, TMOD, TCON SCON and PCON contain control and status information for interrupts, timer/counters and serial
port.
Timing & Control Unit: This unit derives a necessary timing and control signals required for the internal operations of the circuit. It derives control signals required for
controlling the external system bus. The interrupt, serial port and timer circuits are controlled by the control signals generated by timing & control unit.
Oscillator: This circuit generates the basic timing clock signal for the operation of the circuit using crystal oscillator.
Instruction Register: This register decodes the opcode of an instruction to be executed and gives information to the timing & control unit, and to generate necessary
signals for the execution of the instruction.
ALU: The Arithmetic and Logic Unit performs 8 bits arithmetic and logical operations over the operands held by the temporary registers TMP 1 and TMP 2. User cannot
access these temporary registers
SFR Register Banks: It is a set of registers, which can be addressed using their respective addresses which lie in the range 80h to FFh.
Interrupts
 Interrupts are defined as requests because they can be refused (masked) if they are not used, that is when an interrupt is acknowledged. A special set of events or
routines are followed to handle the interrupts. These special routines are known as interrupt handler or interrupt service routines (ISR). These are located at a special
location in memory.
 INT0 and INT1 are the pins for external interrupts.

Pin Diagram of 8051

Pin-1 to Pin-8: PORT 1


Port 1 (P1) is an 8-bit bidirectional I/O port. Each of these pins can be configured as Input or output pins.

Pin 9: RESET pin is used to set the 8051 microcontrollers to its initial values, while the microcontroller is working or at the initial start of application. To reset the
microcontroller, the reset pin must be set high for 2 machine cycles. Program Counter value will be set to 0000H after reset signal is applied.
Port Pin Alternate Signal SFR P3 Bit Description
10 RXD SBUF P3.0 Serial Data Input
11 TXD SBUF P3.1 Serial Data Output
12 𝐈𝐍𝐓𝟎 TCON.1 P3.2 External Interrupt 0
13 𝐈𝐍𝐓𝟏 TCON.3 P3.3 External Interrupt 1
14 T0 TMOD P3.4 Timer/ Counter 0 external input
15 T1 TMOD P3.5 Timer/ Counter 1 external input
16 𝐖𝐑 - P3.6 Signal for writing to external memory
17 𝐑𝐃 - P3.7 Signal for reading from external memory

Pin 18 and Pin 19:


The oscillator circuit generates the clock pulses so that all the internal and external operations are synchronized. The 8051 has an on-chip oscillator but requires an external
crystal to run it. The pins XTAL1 & XTAL2 are used to connect quartz crystal. The Crystal is always connected along with the capacitors as shown in figure. Generally,
11.0592 MHz crystal oscillators are used so that the 8051 microcontroller systems are compatible with the serial port. One machine cycle comprises of 12 oscillator
periods. Hence to find the time for one machine cycle we need to consider 1/12th of Crystal frequency.

Pin-20: GND
It is a ground pin. The supply is connected with respect to this ground pin.

Pin-21 to Pin-28: PORT2


Like Port1, Port3 is also an 8-bit bidirectional I/O port. Port2 also acts a higher order address bus (A8 to A15) while accessing external ROM and RAM.
Pin 29: 𝐏𝐒𝐄𝐍 or Program Store Enable is used to read data from external program memory. Instructions MOVC A, @A+DPTR and MOVC A, @A+PC will activate
this signal.

Pin-30: ALE (Address Latch Enable) is used to demultiplex the address and data signal of port 0 (for external memory interfacing). When ALE=1, Port 0 is providing
lower order address (A0 - A7). When ALE=0, Port 0 is used as data lines.
Alternate function of this pin is 𝐏𝐑𝐎𝐆. It is a program input pulse used during on-chip flash memory programming. After reset, the 8051 checks this pin, if it is connected
to logic ‘0’ externally, it enters into flash programming mode.

Pin-31: 𝐄𝐀 (External Access) input is used to enable or disable external memory interfacing. It is low enable pin. When pin 30 is connected to ground, microcontroller
access External ROM memory. When pin30 is connected to +VCC, microcontroller access Internal ROM.
Alternate function of this pin is VPP it receives 12 V programming enable voltage during flash memory programming for chips that requires 12 V VPP.

Pin-32 to Pin-39: PORT0


Like Port1, Port2 and PORT3, it is also an 8-bit bidirectional I/O port. Port0 also acts a lower order address bus (A0 to A7) and Data Bus (D0 to D7) while accessing
external ROM and RAM.

Pin-40: VCC
It is a positive supply voltage pin. DC power supply +5V is connected to this pin.

Derivatives of 8051
Boolean Processor

 The 8051 processor contains a complete Boolean processor for single-bit operations.
 The internal RAM contains 128 addressable bits, and the SFR space supports up to 128 other addressable bits.
 All port lines are bit-addressable, and each can be treated as a separate single-bit port.
 The instructions that access these bits are not only conditional branches but also a complete set of set, clear, complement, OR, & AND instructions.
 The 8051-instruction set is optimized for the one-bit operations.
 The Boolean processor provides direct support for bit manipulation and testing of individual bit allows the use of single bit variable to perform logical operations
therefore 8051 can be used to solve Boolean expression. Bits may be set or cleared in a single instruction.
 E.g.: CLR C means clear the carry bit SETB 20h means set the memory bit with bit address 20h.
 It consists of Boolean processor which performs bit, set, test, clear and compliment.

Stack
A stack is a last in first out memory. The stack is a section of RAM used by the CPU to store information temporarily. RAM locations from 08H to 1FH can be used as
stack. Stack is used to store the data 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 bits wide, which means that it can take value of 00 to FFH. When the 8051 is powered up, the SP register contains value
07H. RAM location 08 is the first location begin used for the stack by the 8051.

Instructions PUSH and POP are used for stack operations. The storing of a CPU register in the stack is called a PUSH. Loading the contents of the stack back into a CPU
register is called a POP.

When a data is to be placed on the stack, the stack pointer increments before storing the data on the stack so that the stack grows up as data is stored (pre-increment). As
the data is retrieved from the stack the byte is read from the stack, and then SP decrements to point the next available byte of stored data (post decrement).
[SP]=07 //CONTENT OF SP IS 07 (DEFAULT VALUE)

MOV R6, #25H //CONTENT OF R6 IS 25H


MOV R1, #12H //CONTENT OF R1 IS 12H
MOV R4, #0F3H //CONTENT OF R4 IS F3H

PUSH 6 [SP]=08 [08] = [06] =25H //CONTENT OF 08 IS 25H


PUSH 1 [SP]=09 [09] = [01] =12H //CONTENT OF 09 IS 12H
PUSH 4 [SP]=0A [0A] = [04] =F3H //CONTENT OF 0A IS F3H
POP 6 [06] = [0A] =F3H [SP]=09 //CONTENT OF 06 IS F3H
POP 1 [01] = [09] =12H [SP]=08 //CONTENT OF 01 IS 12H
POP 4 [04] = [08] =25H [SP]=07 //CONTENT OF 04 IS 25H
Memory Organization:

8051 has 128 bytes of internal data memory (RAM) for data storage. RAM consists of Register Banks, Stack memory to handle interrupt operations. The 7 bits (or lines)
of address bus are changed or used to address up to 27 = 128 bytes of memory. The address location ranges from 00H to 7FH. Each memory location can hold maximum
of 1 byte of data.
The 128 bytes of RAM in 8051 is divided into three blocks as shown in Fig.

1. Register Banks (address location 00H to 1FH)


2. Bit- Addressable (address location 20H to 2FH)
3. General Purpose (address location 30H to 7FH)

1. Register Banks
The lower block (32 bytes) of RAM is used to accommodate general purpose register banks. 8051 has 4 register banks and are designated as RB0, RB1, RB2 and RB3.
Each bank has 8 general purpose registers named R0 to R7. These registers may be used to store data during arithmetic and logic operation, data movement and
manipulation, memory pointers or counter registers. Only one register bank can be accessed by 8051 at a time. Bits RS0 and RS1 of Program. Status Word (PSW) register
are used to select any one of the four registers banks.

2. Bit Addressable Memory


The next block of 16 bytes after register banks is used to accommodate Bit-addressable area, which means that each bit has its own address (00H-7FH) as
shown in Fig.
The 16 bytes (8 x 16 = 128 bits) contain individual bit address varying from 00H to 7FH. The bit addressable area usually used to store bit variables.
The main function of bit-addressing area is to support bit-level Boolean operations. These bitwise operations are performed with special instructions using the bit
addresses.

3. General purpose RAM


The upper block (80 bytes) of RAM is called general purpose RAM. This area is used for general purpose data storage. The general-purpose RAM can be accessed using
direct or indirect addressing mode.
Power Saving Modes
8051 has two power saving modes. They are a) Idle mode b) power down mode.
The two power saving modes are entered by setting two bits IDL and PD in the special function register (PCON) respectively

Power Control Register

SMOD X X X GF1 GF0 PD IDL

Bit 7 – SMOD

1 = Baud rate is doubled in UART mode 1, 2 and 3.

0 = No effect on Baud rate.


Bit 3:2 – GF1 & GF0:

These are general purpose bit for user.

Bit 1 – PD: Power Down

1 = Enable Power-Down mode.

0 = Disable Power-down mode.

Bit 0 – IDL: Idle

1 = Enable Idle mode.

0 = Disable Idle mode.

In Power Down mode, the oscillator clock provided to the system is OFF i.e., CPU and peripherals clock remains inactive in this mode. While the microcontroller is in
Power Down mode, the state of all SFR registers and I/O ports remains unchanged. By setting it back into the normal mode, the contents of the SFR register is lost, but
the content of internal RAM is saved. Hardware reset can cancel this mode.
In Idle Mode, only the clock provided to the CPU gets deactivated, whereas the peripherals clock will remain active in this mode. Interrupt and H/W reset can cancel this
mode. Hence power saved in power-down mode is more than in idle mode.

You might also like