Wednesday, 29 August 2018

8051 Special Function Register

8051 consists of 8-bit and 16-bit registers. These registers can be accessed using software instructions, some of these registers are bit addressable and some are byte addressable.There are some special function registers used to perform specific task.

SizeAddressRegister NameType
8-bitE0*A RegisterMath Register
8-bitF0*B Register
8-bitB8*IPInterrupt Register
8-bitA8*IE
8-bit89TMODTimer Control
8-bit88*TCON
8-bit8CTH0Timer and control register
8-bit8ATL0
8-bit8DTH1
8-bit8BTL1
8-bit98*SCONSerial Data registers
8-bit99SBUFF
8-bit87PCON
8-bitD0*PSW
8-bit81SPStack Pointer
8-bit83DPHData pointer
8-bit82DPL
16-bitNo AddressPCPort Register
8-bit80*P0
8-bit90*P1
8-bitA0*P2
8-bitB0*P3


*- bit addressable 


  1. Accumulator A - It is a 8-bit register used to store results of arithmetic operations.
  2. B Register - It is an 8-bit register used to store results of multiplication and division and acts as temporary storage.
  3. IP Register - Interrupt Priority, it is a 8-bit register. It is used to set the priorities of interrupts in 8051.
  4. IE Register - Interrupt Enable, It is used to enable/disable interrupts in 8051, the lower four bits are used to enable/disable specific interrupts, whereas, the last bits are used to disable/enable all the interrupts.
  5. TMOD - Timer Mode, this fucntion is used to set the mode of timers into either 16 bit timer, 8bit auto reload timer, 13 bit timer.
  6. TCON - Timer Control, Used to configure and modify the timers to work in specific functionality. It is used to enable disable timer, timer or counter.
  7. Timer 0 and Timer 1 - These are used perform timing and counter operation.
  8. SCON - Serial Control, it has one serial port, it is used to configure propoerties such as Baud Rate of the serial communication.
  9. SBUF - Serial Buffer, used to receiver and transmit data to the serial port. The data written into SBUF register is transmitted to TX pin and data is read from RX pin. 
  10. PCON - Power Control, this register control the various power modes of 8051, it can be put to sleep state to minimize power consumption.
  11. PSW - Program Status Word, stores the important bits of results of accumulator.
  12. SP - Stack Pointer, locate from where the next data is to be taken from Stack.
  13. DPTR - Data Pointer, used to access external RAM memory and program code memory.
  14. PC - Program counter, stores the address of programs next step.



8051 Architecture

8051 Architecture means defining the internal hardware design of 8051. Is is manufactured by various manufacturers like INTEL, FreeScale e.t.c. eith variety of features. The features vary with respect to manufacturing Technology (PMOS or NMOS), capacity of memory, number of timers, interrupts e.t.c.

The 8051 architecture consists of the following components


  • 8-bit CPU with registers and A (accumulator)
  • 16-bit program counter (stores address) and DPTR (points to current data)
  • Internal RAM which is divided into :-
    • Four register banks containing eight registers each of 1 byte.
    • 16-byte of bit addressable memory.
    • 80-byte of general purpose memory.
  • 16-bit Stack pointer.
  • Special Function Registers (SFR) to perform special functions in 8051 such as control and timer.
  • Four I/O ports.
  • Internal Rom Memory.
  • Two Timers.
  • Six Interrupts.
  • System timing and control circuit, clock oscillator e.t.c.
  • 8-bit data lines and 16-bit address lines.     

8051 Assembly Language Programming

Assembly and  Running 8051 Micro-Controller


  • Editor- It is a source file where the programmer writes 8051 assembly language program.
    • This file is saved as "filename.asm" (asm = assembly)
  • Assembler - It converts assembly language into machine language 
    • It generates two files-
      • "filename.lst" -list file which contains sources of error and comments by programmers.(lst = list)
      • "filename.obj" - file containing machine language code. (obj = object)
  • Linker program - It relocates and links all the related files to create one absolute file
    • It create one file named "filename.abs" (abs = absolute) 
  • OH program - It converts the object code to hexadecimal code which can be burnt into target machine.
    • It generate file called "filename.hex" (hex = hexadecimal)

8051 Assembly Directives

They are the instruction directly gives to assembler
  • ORG - Origin, It denotes the starting address of the program
    • ORG 2000H
  • END - End, It denotes the end of program. 
    • END
  • EQU - Equal, associates a number with variable which can later be used in the program.
    • COUNT EQU 25
    • MOV R3 , #COUNT
Note - Without # it is a memory location. With # it is data.

Instructions

  • ACALL - Absolute Call
  • ADD, ADDC - Add Accumulator (With Carry)
  • AJMP - Absolute Jump
  • ANL - Bitwise AND
  • CJNE - Compare and Jump if Not Equal
  • CLR - Clear Registerr
  • CPL - Complement Register
  • DA - Decimal Adjust
  • DEC - Decrement Register
  • DIV - Divide Accumulator by B
  • DJNZ - Decrement Register and Jump if Not Zero
  • INC - Increment Register
  • JB - Jump if Bit Set
  • JBC - Jump if Bit Set and Clear Bit
  • JC - Jump if Carry Set
  • JMP - Jump to Address
  • JNB - Jump if Bit Not Set
  • JNC - Jump if Carry Not Set
  • JNZ - Jump if Accumulator Not Zero
  • JZ - Jump if Accumulator Zero
  • LCALL - Long Call
  • LJMP - Long Jump
  • MOV - Move Memory
  • MOVC - Move Code Memory
  • MOVX - Move Extended Memory
  • MUL - Multiply Accumulator by B
  • NOP - No Operation
  • ORL - Bitwise OR
  • POP - Pop Value From Stack
  • PUSH - Push Value Onto Stack
  • RET - Return From Subroutine
  • RETI - Return From Interrupt
  • RL - Rotate Accumulator Left
  • RLC - Rotate Accumulator Left Through Carry
  • RR - Rotate Accumulator Right
  • RRC - Rotate Accumulator Right Through Carry
  • SETB - Set Bit
  • SJMP - Short Jump
  • SUBB - Subtract From Accumulator With Borrow
  • SWAP - Swap Accumulator Nibbles
  • XCH - Exchange Bytes
  • XCHD - Exchange Digits
  • XRL - Bitwise Exclusive OR