KEMBAR78
btech 8051 Microcontroller Programing.pptx
8051 Microcontroller (A to Z)
What is a Microprocessor?
Computer's Central Processing Unit (CPU) built on a single Integrated Circuit (IC) is called a
microprocessor.
It is a programmable, multipurpose, clock -driven, register-based electronic device that reads binary
instructions from a storage device called memory, accepts binary data as input and processes data
according to those instructions and provides results as output.
A microprocessor consists of an ALU, control unit and register array. Where ALU performs arithmetic
and logical operations on the data received from an input device or memory. Control unit controls the
instructions and flow of data within the computer. And, register array consists of registers identified by
different names and addresses.
The microprocessor is made from millions of tiny components like transistors, registers, and diodes that
work together.[1]
Block Diagram of a General Purpose Microprocessor
Figure 1: General purpose Microprocessor. [2]
What is the difference between a microprocessor and
microcontroller?
Figure 2: a. Microprocessor b. Microcontroller. [2]
By microprocessor is meant the general-purpose microprocessors such as Intel’s x86 family (8086,
80286, 80386, 80486, and the Pentium) or Motorola’s 680x0 family (68000, 68010, 68020, 68030, 68040,
etc.).
These microprocessors contain no RAM, no ROM, and no I/O ports on the chip itself. For this reason, they
are commonly referred to as general-purpose microprocessors.
A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add
RAM, ROM, I/O ports, and timers externally to make them functional.
Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier and much more
expensive, they have the advantage of versatility such that the designer can decide on the amount of
RAM, ROM, and I/O ports needed to fit the task at hand.
On the contrary
A microcontroller has a CPU (a microprocessor) in addition to a fixed amount of RAM, ROM, I/O ports,
and a timer all on a single chip. In other words, the processor, RAM, ROM, I/O ports, and timer are all
embedded together on one chip; therefore, the designer cannot add any external memory, I/O, or timer to
it.
The fixed amount of on-chip ROM, RAM, and number of I/O ports in microcontrollers makes them ideal for
many applications in which cost and space are critical. In many applications, for example a TV remote
control, there is no need for the computing power of a 486 or even an 8086 microprocessor because the
space it takes, the power it consumes, and the price per unit are much more critical considerations than
the computing power.
These applications most often require some I/O operations to read signals and turn on and off certain
bits. For this reason some call these processors IBP, “itty-bitty processors”
It is interesting to note that some microcontroller manufacturers have gone as far as integrating an ADC
(analog-to digital converter) and other peripherals into the microcontroller.
Examples of Devices that use microntrollers.
In the literature discussing microprocessors, we often see the term embedded system. Microprocessors
and microcontrollers are widely used in embedded system products. An embedded product uses a
microprocessor (or microcontroller) to do one task and one task only.
A printer is an example of embedded system since the processor inside it performs only one task—
namely, getting the data and printing it. Contrast this with a Pentium-based PC (or any x86 IBM-
compatible PC). A PC can be used for any number of applications such as word processor, print server,
bank teller terminal, video game player, network server, or internet terminal.
Software for a variety of applications can be loaded and run. Of course the reason a PC can perform
myriad tasks is that it has RAM memory and an operating system that loads the application software into
RAM and lets the CPU run it. In an embedded system, there is only one application software that is
typically burned into ROM.
The x86 PC contains or is connected to various embedded products such as the keyboard, printer,
modem, disk controller, sound card, CD-ROM driver, or mouse. Each one of these peripherals has a
microcontroller inside it that performs only one task. For example, inside every mouse there is a
microcontroller that performs the task of finding the mouse position and sending it to the PC.
Home Appliances:Intercom Telephones Security systems Garage door openers Answering machines Fax
machines Home computers TVs Cable TV tuner VCR Camcorder Remote controls
Video games Cellular phones Musical instruments Sewing machines Lighting control Paging Camera
Pinball machines Toys Exercise equipment
Office: Telephones Computers Security systems Fax machine Microwave Copier Laser printer Color
printer Paging
Engine control Air bag ABS Instrumentation Security system Transmission control Entertainment Climate
control Cellular phone Keyless entry.
Very often the terms embedded processor and microcontroller are used interchangeably.
Choosing a microcontroller
There are four major 8-bit microcontrollers. They are: Freescale’s 6811, Intel’s 8051, Zilog’s Z8, and PIC
16X from Microchip Technology. Each of these microcontrollers has a unique instruction set and register
set; therefore, they are not compatible with each other.
Programs written for one will not run on the others. There are also 16-bit and 32-bit microcontrollers
made by various chip makers. With all these different microcontrollers, what criteria do designers
consider in choosing one?
Three criteria in choosing microcontrollers are as follows: (1) meeting the computing needs of the task at
hand efficiently and cost-effectively, (2) availability of software development tools such as compilers,
assemblers, and debuggers, and (3) wide availability and reliable sources of the microcontroller. Next, we
elaborate further on each of the above criteria.
A brief history of the 8051
In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. This microcontroller had
128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four ports (each 8-bits wide)
all on a single chip. At the time, it was also referred to as a “system on a chip.”
The 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time. Data
larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. The 8051 has a total of
four I/O ports, each 8-bits wide.
The 8051 became widely popular after Intel allowed other manufacturers to make and market any flavors
of the 8051 they please with the condition that they remain code-compatible with the 8051. This has led
to many versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than
half a dozen manufacturers.
The 8051 is the original member of the 8051 family. Intel refers to it as MCS-51
Inside 8051 microcontroller
Figure 3: Inside 8051 block diagram representation.
The 8052 is another member of the 8051 family. The 8052 has all the standard features of the 8051 as
well as an extra 128 bytes of RAM and an extra timer. In other words, the 8052 has 256 bytes of RAM and
three timers. It also has 8K bytes of on-chip program ROM instead of 4K bytes.
The 8051 is a subset of the 8052; therefore, all programs written for the 8051 will run on the 8052, but the
reverse is not true.
Another member of the 8051 family is the 8031 chip. This chip is often referred to as a ROM-less 8051
since it has 0K bytes of on-chip ROM. To use this chip, you must add external ROM to it. This external
ROM must contain the program that the 8031 will fetch and execute. Contrast that to the 8051 in which
the on-chip ROM contains the program to be fetched and executed but is limited to only 4K bytes of code.
The ROM containing the program attached to the 8031 can be as large as 64K bytes. In the process of
adding external ROM to the 8031, you lose two ports. That leaves only two ports (of the four ports) for I/O
operations. To solve this problem, you can add external I/O to the 8031. There are also various speed
versions of the 8031 available from different companies.
Comparison of 8051 Family Members
Feature 8051 8052
8031
ROM 4K
8K 0K
(on-chip program space in bytes)
RAM (bytes) 128
256 128
Timers 2
3 2
I/O pins 32
Various 8051 microcontrollers
Although the 8051 is the most popular member of the 8051 family, you will not see “8051” in the part
number of a microcontroller manual.
This is because the 8051 is available in different memory types, such as UV-EPROM, Flash, and NV-RAM,
all of which have different part numbers. The UV-EPROM version of the 8051 is the 8751.
The flash ROM version is marketed by many companies including Atmel Corp. and Dallas Semiconductor.
The Atmel Flash 8051 is called AT89C51, while Dallas Semiconductor calls theirs DS89C4x0
(DS89C430/440/450). The NV-RAM version of the 8051 made by Dallas Semiconductor is called DS5000.
There is also an OTP (one-time programmable) version of the 8051 made by various manufacturers.
Most popular is ATMEL
Versions of 8051 From Atmel (All ROM Flash)
Part No. ROM RAM I/O Pins Timer Interrupt
Vcc Packaging
AT89C51 4K 128 32 2
6 5V 40
AT89LV51 4K 128 32 2
6 3V 40
AT89C1051 1K 64 15 1
3 3V 20
AT89C2051 2K 128 15 2
6 3V 20
AT89C52 8K 128 32 3
8 5V 40
AT89LV52 8K 128 32 3
8 3V 40
AT89C51 from Atmel Corporation The Atmel Corp. has a wide selection of 8051 chips.
8051 Programing
Before we go for programing lets understand what are the resources that we are going to use for
programing:
we examine the major registers of the 8051 and show their use with the simple instructions MOV and
ADD.
A) Registers: In the CPU, registers are used to store information temporarily. The vast majority of
8051 registers are 8-bit registers. In the 8051, there is only one data type: 8 bits. The 8 bits of a
register are shown in the diagram from the MSB (most significant bit) D7 to the LSB (least
significant bit) D0.
Figure 4: Eight bits of a register.
8 BIT Registers in 8051 are :
(8 bit register ) Register A (Accumulator)
(8 bit register ) Register B
(8 bit register ) Register R0
(8 bit register ) Register R1
(8 bit register ) Register R2
(8 bit register ) Register R3
(8 bit register ) Register R4
(8 bit register ) Register R5
(8 bit register ) Register R6
(8 bit register ) Register R7
The accumulator, register A, is used for all arithmetic and logic instructions. To understand the
use of these registers, we will show them in the context of two simple instructions, MOV and ADD
16 BIT Registers in 8051 are :
DPTR(16 bit data pointer register) ,
PC (16 bit program counter register),
SP(16 bit stack pointer register)
Writing the first program:
An Assembly language instruction consists of four fields:
[label:] [mnemonic] [operands] [;comment]
Note: Label part is optional generally we see instructions as:
MOV destination,source ;copy source to dest.
NOTE: This instruction tells the CPU to move (in reality, copy) the source operand to the destination operand. For example, the instruction “MOV A,R0” copies the contents of register R0 to register A. After this instruction is executed,
register A will have the same value as register R0. The MOV instruction does not affect the source operand.
—------------------------------------------Playing with the MOV instruction ------------------------------------------------------------------------------------
MOV A,#55H ;load value 55H into reg. A
MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H)
MOV R1,A ;copy contents of A into R1 ;(now A=R0=R1=55H)
MOV R2,A ;copy contents of A into R2 ;now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3 ;(now R3=95H)
MOV A,R3 ;copy contents of R3 into A ;now A=R3=95H)
MOV R5,#0F9H ;load F9H into R5 (R5=F9H)
Rule 1: Values can be loaded directly into any of registers A, B, or R0–R7. However, to indicate that it is an
immediate value it must be preceded with a pound sign (#).
Rule 2: If we want to load a HEX number in a reg the number must be followed by H, other wise it will be
considered as decimal number.
MOV A,#12H ;moves hex 12 in reg A
MOV A,#12 ;moves Decimal number 12 in reg A
Rule 3: Notice in instruction “MOV R5,#0F9H” , a 0 is used between the # and F to indicate that F is a hex
number and not a letter. In other words, “MOV R5,#F9H” will cause an error.
Rule 4: If values 0 to F are moved into an 8-bit register, the rest of the bits are assumed to be all zeros. For
example, in “MOV A,#5” the result will be A = 05: that is, A = 00000101 in binary.
Rule 5: Moving a value that is too large into a register will cause an error.
MOV A,#7F2H ;ILLEGAL: 7F2H > 8 bits (FFH)
MOV R2,#456 ;ILLEGAL: 456 > 255 decimal (FFH)
References:
1. What is Microprocessor: Block Diagram, Evolution, Working, Features - javatpoint
2. Ali, Mazidi Muhammad. The 8051 Microcontroller and Embedded Systems: Using Assembly and C. Pearson Education India, 2007.

btech 8051 Microcontroller Programing.pptx

  • 1.
  • 2.
    What is aMicroprocessor? Computer's Central Processing Unit (CPU) built on a single Integrated Circuit (IC) is called a microprocessor. It is a programmable, multipurpose, clock -driven, register-based electronic device that reads binary instructions from a storage device called memory, accepts binary data as input and processes data according to those instructions and provides results as output. A microprocessor consists of an ALU, control unit and register array. Where ALU performs arithmetic and logical operations on the data received from an input device or memory. Control unit controls the instructions and flow of data within the computer. And, register array consists of registers identified by different names and addresses. The microprocessor is made from millions of tiny components like transistors, registers, and diodes that work together.[1]
  • 3.
    Block Diagram ofa General Purpose Microprocessor Figure 1: General purpose Microprocessor. [2]
  • 4.
    What is thedifference between a microprocessor and microcontroller? Figure 2: a. Microprocessor b. Microcontroller. [2]
  • 5.
    By microprocessor ismeant the general-purpose microprocessors such as Intel’s x86 family (8086, 80286, 80386, 80486, and the Pentium) or Motorola’s 680x0 family (68000, 68010, 68020, 68030, 68040, etc.). These microprocessors contain no RAM, no ROM, and no I/O ports on the chip itself. For this reason, they are commonly referred to as general-purpose microprocessors. A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM, I/O ports, and timers externally to make them functional. Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier and much more expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM, and I/O ports needed to fit the task at hand.
  • 6.
    On the contrary Amicrocontroller has a CPU (a microprocessor) in addition to a fixed amount of RAM, ROM, I/O ports, and a timer all on a single chip. In other words, the processor, RAM, ROM, I/O ports, and timer are all embedded together on one chip; therefore, the designer cannot add any external memory, I/O, or timer to it. The fixed amount of on-chip ROM, RAM, and number of I/O ports in microcontrollers makes them ideal for many applications in which cost and space are critical. In many applications, for example a TV remote control, there is no need for the computing power of a 486 or even an 8086 microprocessor because the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power. These applications most often require some I/O operations to read signals and turn on and off certain bits. For this reason some call these processors IBP, “itty-bitty processors” It is interesting to note that some microcontroller manufacturers have gone as far as integrating an ADC (analog-to digital converter) and other peripherals into the microcontroller.
  • 7.
    Examples of Devicesthat use microntrollers. In the literature discussing microprocessors, we often see the term embedded system. Microprocessors and microcontrollers are widely used in embedded system products. An embedded product uses a microprocessor (or microcontroller) to do one task and one task only. A printer is an example of embedded system since the processor inside it performs only one task— namely, getting the data and printing it. Contrast this with a Pentium-based PC (or any x86 IBM- compatible PC). A PC can be used for any number of applications such as word processor, print server, bank teller terminal, video game player, network server, or internet terminal. Software for a variety of applications can be loaded and run. Of course the reason a PC can perform myriad tasks is that it has RAM memory and an operating system that loads the application software into RAM and lets the CPU run it. In an embedded system, there is only one application software that is typically burned into ROM. The x86 PC contains or is connected to various embedded products such as the keyboard, printer, modem, disk controller, sound card, CD-ROM driver, or mouse. Each one of these peripherals has a microcontroller inside it that performs only one task. For example, inside every mouse there is a microcontroller that performs the task of finding the mouse position and sending it to the PC.
  • 8.
    Home Appliances:Intercom TelephonesSecurity systems Garage door openers Answering machines Fax machines Home computers TVs Cable TV tuner VCR Camcorder Remote controls Video games Cellular phones Musical instruments Sewing machines Lighting control Paging Camera Pinball machines Toys Exercise equipment Office: Telephones Computers Security systems Fax machine Microwave Copier Laser printer Color printer Paging Engine control Air bag ABS Instrumentation Security system Transmission control Entertainment Climate control Cellular phone Keyless entry. Very often the terms embedded processor and microcontroller are used interchangeably.
  • 9.
    Choosing a microcontroller Thereare four major 8-bit microcontrollers. They are: Freescale’s 6811, Intel’s 8051, Zilog’s Z8, and PIC 16X from Microchip Technology. Each of these microcontrollers has a unique instruction set and register set; therefore, they are not compatible with each other. Programs written for one will not run on the others. There are also 16-bit and 32-bit microcontrollers made by various chip makers. With all these different microcontrollers, what criteria do designers consider in choosing one? Three criteria in choosing microcontrollers are as follows: (1) meeting the computing needs of the task at hand efficiently and cost-effectively, (2) availability of software development tools such as compilers, assemblers, and debuggers, and (3) wide availability and reliable sources of the microcontroller. Next, we elaborate further on each of the above criteria.
  • 10.
    A brief historyof the 8051 In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. This microcontroller had 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four ports (each 8-bits wide) all on a single chip. At the time, it was also referred to as a “system on a chip.” The 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. The 8051 has a total of four I/O ports, each 8-bits wide. The 8051 became widely popular after Intel allowed other manufacturers to make and market any flavors of the 8051 they please with the condition that they remain code-compatible with the 8051. This has led to many versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than half a dozen manufacturers. The 8051 is the original member of the 8051 family. Intel refers to it as MCS-51
  • 11.
    Inside 8051 microcontroller Figure3: Inside 8051 block diagram representation.
  • 12.
    The 8052 isanother member of the 8051 family. The 8052 has all the standard features of the 8051 as well as an extra 128 bytes of RAM and an extra timer. In other words, the 8052 has 256 bytes of RAM and three timers. It also has 8K bytes of on-chip program ROM instead of 4K bytes. The 8051 is a subset of the 8052; therefore, all programs written for the 8051 will run on the 8052, but the reverse is not true. Another member of the 8051 family is the 8031 chip. This chip is often referred to as a ROM-less 8051 since it has 0K bytes of on-chip ROM. To use this chip, you must add external ROM to it. This external ROM must contain the program that the 8031 will fetch and execute. Contrast that to the 8051 in which the on-chip ROM contains the program to be fetched and executed but is limited to only 4K bytes of code. The ROM containing the program attached to the 8031 can be as large as 64K bytes. In the process of adding external ROM to the 8031, you lose two ports. That leaves only two ports (of the four ports) for I/O operations. To solve this problem, you can add external I/O to the 8031. There are also various speed versions of the 8031 available from different companies.
  • 13.
    Comparison of 8051Family Members Feature 8051 8052 8031 ROM 4K 8K 0K (on-chip program space in bytes) RAM (bytes) 128 256 128 Timers 2 3 2 I/O pins 32
  • 14.
    Various 8051 microcontrollers Althoughthe 8051 is the most popular member of the 8051 family, you will not see “8051” in the part number of a microcontroller manual. This is because the 8051 is available in different memory types, such as UV-EPROM, Flash, and NV-RAM, all of which have different part numbers. The UV-EPROM version of the 8051 is the 8751. The flash ROM version is marketed by many companies including Atmel Corp. and Dallas Semiconductor. The Atmel Flash 8051 is called AT89C51, while Dallas Semiconductor calls theirs DS89C4x0 (DS89C430/440/450). The NV-RAM version of the 8051 made by Dallas Semiconductor is called DS5000. There is also an OTP (one-time programmable) version of the 8051 made by various manufacturers. Most popular is ATMEL
  • 15.
    Versions of 8051From Atmel (All ROM Flash) Part No. ROM RAM I/O Pins Timer Interrupt Vcc Packaging AT89C51 4K 128 32 2 6 5V 40 AT89LV51 4K 128 32 2 6 3V 40 AT89C1051 1K 64 15 1 3 3V 20 AT89C2051 2K 128 15 2 6 3V 20 AT89C52 8K 128 32 3 8 5V 40 AT89LV52 8K 128 32 3 8 3V 40 AT89C51 from Atmel Corporation The Atmel Corp. has a wide selection of 8051 chips.
  • 16.
    8051 Programing Before wego for programing lets understand what are the resources that we are going to use for programing: we examine the major registers of the 8051 and show their use with the simple instructions MOV and ADD. A) Registers: In the CPU, registers are used to store information temporarily. The vast majority of 8051 registers are 8-bit registers. In the 8051, there is only one data type: 8 bits. The 8 bits of a register are shown in the diagram from the MSB (most significant bit) D7 to the LSB (least significant bit) D0. Figure 4: Eight bits of a register.
  • 17.
    8 BIT Registersin 8051 are : (8 bit register ) Register A (Accumulator) (8 bit register ) Register B (8 bit register ) Register R0 (8 bit register ) Register R1 (8 bit register ) Register R2 (8 bit register ) Register R3 (8 bit register ) Register R4 (8 bit register ) Register R5 (8 bit register ) Register R6 (8 bit register ) Register R7 The accumulator, register A, is used for all arithmetic and logic instructions. To understand the use of these registers, we will show them in the context of two simple instructions, MOV and ADD
  • 18.
    16 BIT Registersin 8051 are : DPTR(16 bit data pointer register) , PC (16 bit program counter register), SP(16 bit stack pointer register)
  • 19.
    Writing the firstprogram: An Assembly language instruction consists of four fields: [label:] [mnemonic] [operands] [;comment] Note: Label part is optional generally we see instructions as: MOV destination,source ;copy source to dest. NOTE: This instruction tells the CPU to move (in reality, copy) the source operand to the destination operand. For example, the instruction “MOV A,R0” copies the contents of register R0 to register A. After this instruction is executed, register A will have the same value as register R0. The MOV instruction does not affect the source operand. —------------------------------------------Playing with the MOV instruction ------------------------------------------------------------------------------------ MOV A,#55H ;load value 55H into reg. A MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H) MOV R1,A ;copy contents of A into R1 ;(now A=R0=R1=55H) MOV R2,A ;copy contents of A into R2 ;now A=R0=R1=R2=55H) MOV R3,#95H ;load value 95H into R3 ;(now R3=95H) MOV A,R3 ;copy contents of R3 into A ;now A=R3=95H) MOV R5,#0F9H ;load F9H into R5 (R5=F9H)
  • 20.
    Rule 1: Valuescan be loaded directly into any of registers A, B, or R0–R7. However, to indicate that it is an immediate value it must be preceded with a pound sign (#). Rule 2: If we want to load a HEX number in a reg the number must be followed by H, other wise it will be considered as decimal number. MOV A,#12H ;moves hex 12 in reg A MOV A,#12 ;moves Decimal number 12 in reg A Rule 3: Notice in instruction “MOV R5,#0F9H” , a 0 is used between the # and F to indicate that F is a hex number and not a letter. In other words, “MOV R5,#F9H” will cause an error. Rule 4: If values 0 to F are moved into an 8-bit register, the rest of the bits are assumed to be all zeros. For example, in “MOV A,#5” the result will be A = 05: that is, A = 00000101 in binary. Rule 5: Moving a value that is too large into a register will cause an error. MOV A,#7F2H ;ILLEGAL: 7F2H > 8 bits (FFH) MOV R2,#456 ;ILLEGAL: 456 > 255 decimal (FFH)
  • 21.
    References: 1. What isMicroprocessor: Block Diagram, Evolution, Working, Features - javatpoint 2. Ali, Mazidi Muhammad. The 8051 Microcontroller and Embedded Systems: Using Assembly and C. Pearson Education India, 2007.