Page 1 :
CHAPTER, 2, 8051 Microcontroller, INSIDE THIS CHAPTER, 21. Introduction 2.2. Architecture of MCS-51 2.3. Registers of MCS-51 24. Se, Function Registers (SFR) 2.5. MCS-51 Pin Details 2.6. VO Port Structure 27, Organization 2.8. Extemal Memory, 2.1. INTRODUCTION, Intel developed MCS-51 commonly referred as 8051 Microcontroller in 19, It is a 8 bit microcontroller. It is based on Harvard Architecture. Originally lni, developed MCS-51 with NMOS technology but later version were developed wit, CMOS technology to save power. Despite it's relatively old age, the 8051 is one d, the most popular microcontrollers in use today. Many derivative microcontmles, have since been developed that are based on-and compatible with-the S051, Intel MCS-51 offer following features:, · Four 8 bit bi-directional I/O port, • 128 byte RAM, - 4K bytes of ROM, I Serial Interface (UART), - Two 16 bit timers/counters, 1 210 bit addressable locations, 1 64 K external data memory space, 1 64 K external code memory space, 1 Boolean Processor (bitwise operation), 10, Scanned by CamScanner
Page 2 :
8051 MICROCONTROLLER, 11, 12 MHz operating frequency, - 4 us divide/multiply instructions, • On chip clock oscillator, - Four register bank, • One us instruction cycle., Atmel corporation have developed mierocontrollers compatible to MCS-51., Most widely used Atmel microcontroller is AT898CS1. It is used in almost all, practical application and in colleges/Universities lab kit. Three important, mierocontroller from Atmel are listed in Table 2.1., Table 2.1. Comparison of Atmel Family Microcontroller., Product, Code Memory, Data Memory, Timers/Counters, 1/O Pins, AT89C51, ATS9CS2, ATS9C2051, 128, 4K, 2, 40, 256, 8K, 3, 40, 128, 2K, 20, Intel MCS-51 Family, Intel has developed various version of Microcontrollers. These are called Intel, MCS-51 family. All microcontrollers have different code memory, data memory, and timers. These family members are shown in Table 2.2., Table 2.2. Comparison of Intel Family Microcontroller., Microcontroller, Code, Data Memory, Timers/, Interrupts, Memory, (bytes), Counters, 8031, 128, 2, 8051, 4 K ROM, 128, 8052, 8K ROM, 256, 3, 6, 8751, 4 K EPROM, 128, 2, 5, 8752, 8K EPROM, 256, 3, 6., 8032, 256, All these microcontroller are based on HMOS (High Speed Metal Oxide, Semiconductor) technology., Leading 8051 Manufacturer, Intel, • Philips, - Atmel, • Cygnal, - Dallas Semiconductor, I ISSI., Scanned by CamScanner
Page 3 :
FUNDAMENTALS OF MICROCONTROLLER AND EMBEDDED SYSTEMS, 12, 2.2. ARCHITECTURE OF MCS - 51, The simplified block diagram of 8051 microcontroller is shown in Fig, 21, The various block of MCS-51 microcontroller are oscillator, central processing, unit, Data memory (RAM), Coxde memory (ROM/EPROM), Ports, special function, register and oscillator. These clements communicate through 8 bit data bus. This, bud is buffered to outside world through 1/0 ports., External, Interrupts, Timer 0, Program, Momory, (4k), RAM, Counter, (128 bytes), Inputs, Timer 1, Internupt, Contrl, Central, Processing, Unit, Four, VO Ports, (PO P1 P2 P3), Serial, Port, OSC, Bus, Control, TxD, RxD, PO P2 P1 P3, Address, Data, FIGURE 2.1. Simplified Internal Architecture of Intel MCS-51., ALU: Arithmetic Logie Unit, ALU is one of the many components within a, computer processor. The ALU performs mathematical, logical, and decision, operations in a computer and is the final processing performed by the processor., After the information has been processed by the ALU, it is sent to the computer, memory., Program and Data Memories: Program (code) memory is non-volatile read, only memory. In Intel 8051 on chip program memory is 4K byte. This memory, can be extended up to 64K data memory is used for temporarily storing data and, intermediate results created and used during the operation of the microcontroller., RAM memory is used as data memory. In Intel 8051 on chip 128 byte of RAM is, available., Port: In the 8051 there are total 4 ports for 1/0 operations. Upon reset all 4, ports are configured as input port. When the first 0 is written to the port, it, becomes an output. All 4 ports are bi-directional. All the ports consist of three, common components:, (1) D type Latch, (2) O/P driver, (3) I/P buffer, Scanned by CamScanner
Page 4 :
8051 MICHOCONTROLLER, 13, Each port has a D type 0/P latch for cach pin, Two data path read the latch or, data pin using two separate buffer. When latch data is read top buffer is enabled,, and when pin state is read lower buffer is read, Out of 4 ports, port 1 does not, support alternate function while PO, P2 and P3 are programmable., The Oseillator: All mierocontrollers require a clock (or an oscillator) to operate., On most micro-controller there is built in circuitry to allow a simple connection of, a crystal or other hardware, such as ceramic resonator or an external clock source., The clock is usually pro-vided by connecting external timing devices to the, microcontroller., Timing and Control Unit: This unit drives necessary timing and control, sircuitry for internal circuit and external system bus., Timer: Both these timers are 16 bit wide. As 8051 is 8 bit microcontroller,, each timer is accessed as two separate register of low byte and high byte. For, Timer 0 low byte register is called TLO (Timer 0 Low byte) and high byte register, is called as TH0 (Timer 0 High Byte). In the same way Timer I is split in two, bytes, called as TLI (Timer I Low byte) and THI(Timer I High byte). Their exact, behavior depends on how the timer is configured in the TMOD register' however,, these timers always count up., 2.3. REGISTERS OF MCS-51, There are general purpose registers and special purpose registers (SPRS)., Working Registers, Stack Pointer, Program Counter are CPU registers. These registers, are discussed in the following paragraphs., 2.3.1. General Purpose Register, Register A (Accumulator): The Accumulator is one of the most used SFRs, on the 8051 since it is involved in so many instructions. It is mathematical core of, MCS-51 CPU. Accumulator is a versatile register used in various operation like, addition, subtraction, division, multiplication, Boolean and logical operations. It is, also used for data transfer between 8051 and external memory., B Register: It is also a general purpose register. After accumulator this is, the most versatile register of 8051. Register B is bit addressable. The "B" register, is used in two instructions: the multiply and divide operations. The B register is, also commonly used by programmers as an auxiliary register to temporarily store, values., Register RO through R7: There are four register bank in 8051 microcontroller., Each register bank has 8 registers RO-R7. User can switch in any register bank, using program status word. Be default register bank 0 is selected., 2.3.2. Stack Pointer and Program counter, SP (Stack Pointer): The Stack pointer is a 8 bit register used to access the, stack. The stack is an area of RAM used to store and retrieve data or address, temporarily. When microcontroller is power up the SP register contains value 07., PUSH and POP instruction are used with this. If you push a value onto the stack,, the value will be written to the RAM location 08. Whenever PUSH or CALL, Scanned by CamScanner
Page 5 :
in byte. For 8051 it can address 2 = 64 K bytes of memory. There is no internal, to be executed. The size of program counter decides the maximum program length, Program Counter: It is a 16 bit address. It holds the address of next instruction, instruction is used content of SP register are incremented and when POP or RET, FUNDAMENTALS OF MICNOCONTROLLER AND EMBEDDED S, 14, instructions are executed content of SP register are decremented., address defined for this register., 2.4. SPECIAL FUNCTION REGISTERS (SFR), The 128 byte of on chip Ram locations from address 80H to 0FFH are reserved, for the special functions and therefore these are called as Special function Register, (SFR). These addresses are above 80H, since the addresses 00H to 7FH are addresses, of RAM inside the 8051. The SFR can be accessed by their names or by their, addresses. Figure 2.2 lists the 8051 SFR and their addresses., PSW (Program Status Word, Addresses DOh, Bit-Addressable), The Program Status Word is used to store a number of important bits that are, set and cleared by 8051 instructions. The PSW SFR contains the carry flag, the, auxiliary carry flag, the overflow flag, and the parity flag. Additionally, the PSW, register contains the register bank select flags which are used to select which of the, "R" register banks are currently selected., PSW.7, PSW.6, PSW.5, PSW4, PSW.3, PSW2, PSW.1, PSW.O, D7, D6, D5, D4, D3, D2, D, DO, CY, AC, FO, RSI, RSO, OV, FIGURE 2.2. PSW Register of 8051, CY-Carry Flag, The carry flag has two functions., Firstly, it is used as the carry-out in 8-bit addition/subtraction. For example, if, the accumulator contains FDH and we add five to its contents, it will then contain, two and the carry flag will be set. It is also set if a subtraction causes a borrow into, bit 7. In other words, if a number is subtracted from a number smaller than it, the, carry flag will be set. For example, if A contains 3DH and R3 contains 4BH, the, instruction SUBB A, R3 will result in the carry bit being set (4BH is greater than, 3DH)., The carry flag is also used during Boolean operations. For example, we could, AND the contents of bit 73H with the carry flag, the result being placed in the, carry flag-ANL C, 73H (the bit at address 73H is logically anded with the carry,, the result placed in the carry)., AC-Auxiliary Carry Flag, The auxiliary carry flag is set or cleared after an add instruction (ADD A, operand or ADDC A, operand) only. The condition that results in AC being set ir, Scanned by CamScanner