Chapter1 dek3133 updated

766 views

Published on

chapter 1, microcontroller (dae32203), reused

Published in: Engineering, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
766
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
39
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Chapter1 dek3133 updated

  1. 1. Chapter 1 Introduction to Microcontroller
  2. 2. 2 Review on Microprocessor System  The P system components include a CPU, RAM, ROM and I/O ports  Its interconnections comprise an address bus, a data bus and control lines  These buses are required to handle the data transfer between the CPU, memory and ports
  3. 3. 3 Review on Microprocessor System Microprocessor EEPROM RAM Input and output ports Serial I/O Parallel I/O Timer PWM Input and output ports A/D D/A Analog I/O ROM Figure 1.1: Microprocessor-based system
  4. 4. 4 Review on Microprocessor System  Program execution- - The ROM and RAM contain program and data in numbered locations. - Each instruction and operand are stored in sequential locations. - The program instruction codes are fetched into the CPU and decoded.
  5. 5. 5 Review on Microprocessor System  Program execution (con..) - The CPU then sets up the internal and external control lines as necessary and carries out the operation specified in the program. - The instructions are executed in order of their addresses, unless the instruction itself causes a jump to another point in the program, or an interrupt is received.
  6. 6. 6 Review on Microprocessor System 3274 Inst. Code Operand Data Processing ResultData register Data register Instruction register Program counter CPU 3 5 7 Instruction Operand Operand Next instr. etc 3724 3725 3726 3727 3728 Data byte Data byte Data byte 5821 5822 5823 RAM 1 2 4 6 8 Contents Address Figure 1.2: Program execution sequence
  7. 7. 7 Review on Microprocessor System  PC Engineering Applications - Can be used as a standard hardware platform in a variety of engineering systems by fitting special interfacing hardware and programming the PC to control an external system through I/O. - increasingly used in manufacturing systems; control a machine tool, robot or assembly system. - considered to be powerful computer machines.
  8. 8. 8 Review on Microprocessor System  PC Engineering Applications - PC also has the advantage of using a standard operating system and programming languages that allow control programs to be written in high level languages such as ‘C’ or Visual Basic. - Graphical programming tools are also available for designing control and instrumentation applications without any conventional programming at all.
  9. 9. 9 The Microcontroller  The microcontroller can provide, in a simplified form, all the main elements of the conventional microprocessor system on one chip.  Less complex applications can be designed and built quickly and cheaply.  A working system can consist of a microcontroller chip and just a few external components for feeding data in and out, and generating the clock.
  10. 10. 10 The Microcontroller  A Microcontroller Application - Used to control a small system. - calculator, automatic washing machine, message display, electronic lock or similar application.
  11. 11. 11 The Microcontroller CPUCore EEPROM RAM Serial I/O Parallel I/O Timer PWM A/D ROM Filter Analog Out Digital PWM Microcontroller Analog In Figure 1.3: Microcontroller-based system
  12. 12. 12 The Microcontroller  Programming a Microcontroller - Normally have ROM program memory, into which the program must be loaded before the chip is placed in the application circuit. - The program is written and converted to machine code in the host, and downloaded via a serial data link. - The chip is then removed from the programming unit and inserted into the application hardware.
  13. 13. 13 Microcontroller Vs Microprocessor
  14. 14. 14 Microcontroller Vs Microprocessor Perspective Microprocessors Microcontrollers Hardware Architecture  Single-chip CPU  High RAM-ROM ratio  External components are required to implement interrupt, timer and I/O operations  Single-chip computer  High ROM-RAM ratio  Built-in interrupt, timer and I/O devices Applications  Used as CPU in computer systems for general processing  Used in control-oriented systems requiring minimum components Instructions Set Features  Powering and processing intensive instructions  More suitable for large volume data handlings  AND, OR, XOR operations at bit level is less easy  Simple and compact instructions  More suitable for single-bit I/O operations  AND, OR, XOR operations at bit level is easy
  15. 15. 15 Microcontroller Vs Microprocessor Microcontroller  Low density  Less PCB area  Low cost  Specific Architecture  Low power consumption  More reliable Microprocessor  high density  higher PCB area  high cost  Flexible  high power consumption
  16. 16. Picking a PIC Microcontroller Choosing a PIC microcontroller for your application requires taking into account a variety of factors. These factors include:  The number of I/O pins required  The peripherals needed (i.e. CCP module, USART, etc.)  The memory size (program memory, RAM, EEPROM)  Microcontroller speed  Physical size (form factor) 16
  17. 17. PIC16F87x 17 Features 16F87x Instruction width 14 bits Program Memory Up to 8K x 14 Data Memory (RAM) Up to 368 x 8 EEPROM Up to 256 x 8 Clock Speed Max 20 MHz Instruction Set 35
  18. 18. 18 8-bit Microcontroller  Motorola – M68HC05, HC08, HC11  Intel – 8051  Atmel  Philips  Dallas  Cygnal  Zilog  etc  Microchip – PIC  Atmel - AVR
  19. 19. PIC Product Overview 19
  20. 20. Current Main Architecture 20 Harvard Architecture Von Neuman Architecture
  21. 21. 8-bit PIC Microcontroller 21  PIC microcontroller architecture is based on a modified Harvard RISC instruction set that provides an easy migration path from 6 to 80 pins and from 384 bytes to 128K bytes of program memory.  By combining the RISC features with a modified Harvard dual-bus architecture, Microchip's fast and flexible 10 MIPS PIC16F core is the most popular architecture for new microcontroller designs. Reduced instruction set computing (RISC)
  22. 22. 22 Central Processing Unit (CPU)  CPU is the brain of a microprocessor where all of the arithmetic and logical operations are performed.  CPU has a role of connective element between other blocks in the microcontroller. It coordinates the work of other blocks and executes the user program.  The control unit controls the internal operations of the microprocessor and sends out control signals to other parts of the microprocessor to carry out the required instructions.  A generic CPU has a set of registers (memory of CPU), an arithmetic logic unit (ALU), memory interface and timing circuits
  23. 23. 23 Central Processing Unit (CPU) Registers Internal Bus ALU CU CPU Control and Status registers User-Visible Registers Program counter Instruction register …. …. Accumulator Address Register Data Register Flag Register ….
  24. 24. 24 Central Processing Unit (CPU) This is a unit which monitors and controls all processes inside the microcontroller. It consists of several smaller subunits, of which the most important are: •Instruction Decoder is a part of the electronics which recognizes program instructions and runs other circuits on the basis of that. The “instruction set” which is different for each microcontroller family expresses the abilities of this circuit. It decodes the binary code in an instruction and passes the necessary control signals to the CU to complete the operations specified by the instruction.
  25. 25. Central Processing Unit (CPU)  Arithmetical Logical Unit (ALU) performs all mathematical and logical operations upon data. o Example of arithmetic operations are add, subtract, multiply and divide. In low-end microprocessors, multiply and divide may not be implemented. o Example of logical operations are AND, OR, and XOR. o The ALU also performs shift and rotate operations that may either be arithmetic or logical in nature. 25
  26. 26. Central Processing Unit (CPU)  Accumulator is a SFR closely related to the operation of the ALU. It is a kind of working desk used for storing all data upon which some operation should be performed (addition, shift/move etc.). It also stores the results ready for use in further processing. One of the SFRs, called a Status Register (PSW), is closely related to the accumulator. It shows at any given moment the “status” of a number stored in the accumulator (number is greater or less than zero etc.). 26
  27. 27. 27 Central Processing Unit (CPU)  Register o Registers refer to a set of internal storage locations within the CPU. These include: 1. Control and Status Registers that are used by the control unit to control the operation of CPU, such as: - Program Counter (PC) - Instruction Register (IR)
  28. 28. 28 Central Processing Unit (CPU) 2. User-Visible Registers that can be accessed by programmer using machine language, such as: - General-purpose Register - Special Function Register - Address Register - Data Register - Flag Register
  29. 29. 29 Special Function Register (SFRs) & GPR.
  30. 30. Memory System 30 Each memory address corresponds to one memory location. The content of any location becomes known by its addressing. Memory can either be written to or read from. There are several types of memory within the microcontroller. Memory is part of the microcontroller used for data storage. The easiest way to explain it is to compare it with a filing cabinet with many drawers. Suppose, the drawers are clearly marked so that it is easy to access any of them. It is easy enough to find out the contents of the drawer by reading the label on the front of the drawer.
  31. 31. 31 Memory System  There are two groups of memory Program memory – stores all the program code and this memory is usually non-volatile (data is not lost after the removal of power) Data memory – stores the temporary user data during the arithmetic and logical operations.
  32. 32. 32 PIC Program Memory – Flash Program Memory 0000h -> 1FFFh = 8Kbyte of memory size 8K = 8192 lines of programming codes. Each line of code only take 1 word (14bits) of memory size.
  33. 33. 33 Memory System  RAM (Random Access Memory) – a general purpose memory which usually stores user data. RAM is volatile.  ROM (Read Only Memory) – usually holds program of fixed user data. ROM are programmed at the factory and their contents cannot be changed by the user. ROM are only useful if we have developed program and wish to order several thousand copies of it.
  34. 34. 34 Memory System  EPROM (Erasable Programmable ROM) – similar to ROM but it can be programmed using a suitable programming device.  Has a small clear window on the chip where the data can be erased under a UV light.  Many development versions of microcontrollers are manufactured with EPROM memories where the user program are usually stored.
  35. 35. 35 Memory System  Some versions of EPROM, known as OTP (One Time Programmable), can be programmed using a suitable programmer device but these memories cannot be erased.  OTP memories cost less than the EPROM and it is useful after a project has been developed completely and it is required to make hundred of copy of the program memory.
  36. 36. 36 Memory System  EEPROM (Electrical EPROM) – These memory can be erased and also can be programmed under program control. EEPROMs are used to save configuration information, maximum and minimum values, identification data etc.  Some microcontrollers have built-in EEPROM memories (e.g. PIC16F84 contains a 64-byte EEPROM memory where each byte can be program and erase directly by software).  EEPROM memories are usually very slow.
  37. 37. 37 Memory System  Flash EEPROM – very popular and is used in many microcontrollers (e.g. PIC16F77A contain 8K bytes of flash memory) to store the data program.  The data on a flash EEPROM is erased and programmed using a programming device.  The entire contents of the memory should be erased and then reprogrammed.  Flash EEPROMs are usually very fast.
  38. 38. 38 Bus  System bus is a collection of wires carrying information within a computer system. There are three types of system busses: address, data and control busses.  Address Busses are wires that carry the CPU-generated address signals out to memory and to I/O devices. It is an uni-directional.  The size of the memory space that a microprocessor can access depends on the number of address lines.
  39. 39. 39 Bus No of address lines Size of memory space 8 16 20 24 32 G442949672962 M16167772162 M110485762 K64655362 2562 32 24 20 16 8     
  40. 40. 40 Bus  Data buses refer to data signals that travel out of and into the microprocessor. Thus, data bus is bi-directional.  The number of wires in the data bus depends on the word size that the microprocessor operates with. An 8-bit microprocessor will have a data bus consisting of 8 wires while a 32-bit microprocessor will have a data bus with 32 wires.
  41. 41. 41 Bus  Control Bus consists of wires, some of which carry signals from the CPU to external devices, while other carry signals from external devices to the CPU. The number of wire present in the control bus varies from microprocessor to microprocessor.  Example of control buses signals are READ/WRITE, WAIT, READY and HOLD.
  42. 42. 42 Bus
  43. 43. 43 I/O Modules  I/O modules provide interface between the computer system and the ‘real world’. An external device connected to an I/O modules is often referred to as a peripheral device. Three broad classes of I/O devices are:  Human-readable I/Os: suitable for communication with the user. E.g. Monitor, keyboard, mouse, joystick, video display terminals, printer, scanner, microphone and speaker
  44. 44. 44 The Clock  All microcontrollers require an oscillator (clock) to operate.  Most microcontrollers will operate with a crystal and two capacitors. Some will operate with resonators or with external resistor-capacitor pair.  Some microcontrollers have built-in resistor-capacitor type oscillators and they do not require any external timing components
  45. 45. PIC Clock Source. 45 The value of capacitors ranges from 15pf to 33 pf
  46. 46. 46 The Clock
  47. 47. 47 Watchdog Timer  Watchdog is a mechanism which microcontroller uses to defend itself against programs getting stuck. As with any other electrical circuit, so with a microcontroller too can occur failure, or some work impairment. Unfortunately, microcontroller also has program where problems can occur as well. When this happens, microcontroller will stop working and will remain in that state until someone resets it. Because of this, watchdog mechanism has been introduced. After a certain period of time, watchdog resets the microcontroller (microcontroller in fact resets itself). Watchdog works on a simple principle: if timer overflow occurs, microcontroller is reset, and it starts executing a program all over again. In this way, reset will occur in case of both correct and incorrect functioning.
  48. 48. Watchdog Timer 48
  49. 49. 49 Analogue-to-digital Converter  Some microcontrollers are equipped with analogue-to- digital converter circuits. Usually these converters are 8 bits, but some microcontrollers have 10- or even 12-bit converters.  A/D converters usually generate interrupts when a conversion is complete so that the user program can read the converted data very quickly.  A/D converters are very useful in control and monitoring applications since most sensors produce analogue output voltages.
  50. 50. 50 Analogue-to-digital Converter
  51. 51. Analogue-to-digital Converter  External signals are usually fundamentally different from those the microcontroller understands (Ones and Zeros), so that they have to be converted in order for the microcontroller to understand them. An analogue to digital converter is an electronic circuit which converts continuous signals to discrete digital numbers. This module is therefore used to convert some analogue value into binary number and forwards it to the CPU for further processing. In other words, this module is used for input pin voltage measurement (analogue value). The result of measurement is a number (digital value) used and processed later in the program. 51
  52. 52. 52 Program  Microcontroller needs a program that would be executed.  A program is a logical sequence of instructions stored in the memory of the system.  In its operations, the CPU fetches an instruction from memory, decodes the instruction and carries out the operation or operations specified by the instruction.
  53. 53. 53 A Microcontroller 16F877A
  54. 54. World of Numbers 54
  55. 55. World of Numbers 55 Binary Number System Hexadecimal Number System
  56. 56. World of Numbers 56 Hexadecimal to Decimal Number Conversion Decimal to Binary Number Conversion
  57. 57. World of Numbers 57 Marking Numbers The hexadecimal numbering system is along with binary and decimal number systems considered to be the most important for us. It is easy to make conversion of any hexadecimal number to binary and it is also easy to remember it. However, these conversions may cause confusion. For example, what does the statement “It is necessary to count up 110 products on assembly line” actually mean? Depending on whether it is about binary, decimal or hexadecimal, the result could be 6, 110 or 272 products, respectively! Accordingly, in order to avoid misunderstanding, different prefixes and suffixes are directly added to the numbers. The prefix $ or 0x as well as the suffix h marks the numbers in hexadecimal system. For example, hexadecimal number 10AF may look as follows $10AF, 0x10AF or 10AFh. Similarly, binary numbers usually get the suffix % or 0b, whereas decimal numbers get the suffix D. Comparative table below contains the values of numbers 0-255 in three different numbering systems.
  58. 58. World of Numbers 58 Byte A byte or a program word consists of eight bits grouped together. All mathematical operations can be performed upon them, like upon common decimal numbers. The largest value has the leftmost bit called the most significant bit (MSB). The rightmost bit has the least value and is therefore called the least significant bit (LSB). Since eight zeros and units of one byte can be combined in 256 different ways, the largest decimal number which can be represented by one byte is 255 (one combination represents zero). A nibble is referred to as half a byte. Depending on which half of the byte we are talking about (left or right), there are “high” and “low” nibbles.
  59. 59. Basic Hardware Circuit 59
  60. 60. 60 Pin description
  61. 61. 61
  62. 62. 62
  63. 63. 63 Clock Generator - Oscillator  Oscillator circuit is used for providing a microcontroller a clock. Clock is needed so that microcontroller could execute a program.  The most frequently used is crystal and RC oscillator  We have the option of selecting one of the following modes:  LP – Low power crystal  XT – Crystal / resonator  HS – High speed crystal /resonator  RC – Resistor / capasitor
  64. 64. 64 XT Oscillator Connecting the quartz oscillator to give clock to a microcontroller Connection a resonator to a PIC
  65. 65. 65 RC Oscillator  In applications where great time precision is not necessary, RC oscillator offers additional savings during purchase  Resonant frequency of RC oscillator depends on supply voltage rate, resistance R, capacity C and working temperature.  The OSC2 pin outputs the RC oscillator frequency divided by 4. This signal may be used for calibration, synchronization or other application requirements.
  66. 66. 66 RC Oscillator  The frequency of oscillator is calculated according to the formula f = 1/T in which: f = frequency [Hz] T = R*C = time constant [s] R = resistor resistance [Ω] C = capacitor capacity [F]
  67. 67. RC Oscillator 67 Clock Frequency with RC
  68. 68. Oscillator 68
  69. 69. 69 Oscillator
  70. 70. 70 Reset  Reset is used for putting the microcontroller into a 'known' condition.  When microcontroller behave inaccurately under certain undesirable conditions, in order to continue its proper functioning it has to be reset meaning all register would be placed in a starting position.
  71. 71. 71 Reset Microcontroller PIC16F877A knows several sources of resets: a) Reset during power on, POR (Power-On Reset) b) Reset during regular work by bringing logical zero to MCLR microcontroller's pin. c) Reset during SLEEP regime d) Reset at watchdog timer (WDT) overflow e) Reset during at WDT overflow during SLEEP work regimeMaster Clear Pin
  72. 72. 72 Reset  On reset, the microcontroller immediately stops operation and clears its registers.  Reset signal may be generated externally at any moment (low logic level on the MCLR pin).  If needed it can be also generated by internal control logic.  Power-on always causes reset. Namely, because of many transitional events which take place when power supply is on ( switch contact flashing and sparkling, slow voltage rise, gradual clock frequency stabilization etc.), Oscillator Start-Up Time Delay
  73. 73. 73 Reset at supply voltage drop below the permissible (Brown-out Reset)  When power supply voltage drops slowly (typical example of that is battery), the internal electronics gradually stops operating and so called Brown-out reset occurs.  This is used to insure that the device will not try to run at a voltage that is too low for correct operation  If not, it can also causes fatal changes in the program itself because it is saved in on-chip flash memory.  The Brown-Out Reset can be enabled in the configuration bits. Once enabled, it is always active, even during sleep.  On some devices, the Brown-Out Reset voltage is fixed, but on others it can be selected from several different voltages.
  74. 74. 74 Reset at supply voltage drop below the permissible (Brown-out Reset)
  75. 75. 75 Ports  Port is a group of pins on a microcontroller which can be accessed simultaneously or on which we can set the desired combination of zeros and ones.  Physically, port is a register inside a microcontroller which is connected by wires to a pins.  Port represent physical connection of CPU and outside world.
  76. 76. 76 Ports  Microcontroller uses them in order to monitor or control other components or devices.  All port pins can be designated as input or output, according to the needs of the device that’s being developed.
  77. 77. Port A, B, C, D, E 77
  78. 78. 78 Port A and TRISA  Port A is an 6-bit wide, bidirectional port.  Bits of the TRISA and ADCON1 control the PORTA pins.  All Port A pins act as digital inputs/outputs. Five of them can also be analog inputs (denoted as AN)  The appropriate register for data direction is TRISA  Setting a bit in TRISA register defines the corresponding port pin as input and resetting a bit in TRISA register defines the corresponding port as output.
  79. 79. Port A and TRISA 79  By clearing some bit of the TRIS register (bit=0), the corresponding port pin is configured as output.  Similarly, by setting some bit of the TRIS register (bit=1), the corresponding port pin is configured as input.  This rule is easy to remember 0 = Output, 1 = Input.
  80. 80. 80 Port A and TRISA
  81. 81. Port A and TRISA  Similar to bits of the TRISA register which determine which of the pins will be configured as input and which as output, the appropriate bits of the ANSEL register determine whether the pins will act as analog inputs or digital inputs/outputs.  RA0 = AN0 (determined by bit ANS0 of the ANSEL register);  RA1 = AN1 (determined by bit ANS1 of the ANSEL register);  RA2 = AN2 (determined by bit ANS2 of the ANSEL register);  RA3 = AN3 (determined by bit ANS3 of the ANSEL register); and  RA5 = AN4 (determined by bit ANS4 of the ANSEL register). 81
  82. 82. 82 Port B and TRISB  Port B has adjoined 8 pins.  The appropriate register for data direction is TRISB  Setting (logic 1) a bit in TRISB register defines the corresponding port pin as input and resetting (logic 0) a bit in TRISB register defines the corresponding port as output.
  83. 83. 83 Port B and TRISB
  84. 84. 84 Eg: TRIS configuration in mikroC  PORTB is connected to various of devices.  Output: Speaker, LED & Motor.  Input: 2 buttons.  Output represent 0 & Input represent 1 PORTB direction setup is mikroc: TRISB = 0b00001010; TRISB Bit 7 6 5 4 3 2 1 0 Devices x x x Motor Button2 Led Button1 Spk Direction x x x 0 1 0 1 0
  85. 85. MikroC: Write and read the devices at PORTB 85  To buzz the speaker PORTB = 0b000000001; Or PORTB.F0 = 1;  To lid ON the LED PORTB = 0b00000100; Or PORTB.F2 = 1;  To rotate the motor PORTB = 0b00010000;  To activate buzz, led and motor simultaneously PORTB = 0b00010101;  To de-activate output devices simultaneously PORTB = 0b00000000; Here, 0 represent as 0V and 1 as +5V Output Devices  Read input Button1 if (PORTB.F1 == 0) { //do something }  Read input Button2 if (PORTB.F3 == 0) { //do something } Input Device (Button)
  86. 86. 86 Memory Organization  PIC16F877A has two separate memory blocks, one for data and the other for program.  The data memory is partitioned into multiple banks which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (Status<6>) and RP0 (Status<5>) are the bank select bits.
  87. 87. Memory Organization 87 Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for the Special Function Registers. Below the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.
  88. 88. 88 DATA MEMORY – SFR & GPR
  89. 89. 89 Program Memory  Program memory has been carried out in FLASH technology which makes it possible to program a microcontroller many times before it's installed into a device.  The size of program memory is 8192 locations with 14 width bits (8k x 14) where locations zero(00h) and four(04h) are reserved for reset and interrupt vector.
  90. 90. 90 Data memory  Data memory consists of EEPROM and RAM memories.  EEPROM memory consists of 256 bytes locations whose contents is not lost during loosing of power supply.  EEPROM is not directly addressable, but is accessed indirectly through EEADR and EEDATA registers  RAM memory for data occupies space on a memory map from location 0x0C to 0x4F which comes to 68 locations.  Locations of RAM memory are also called GPR registers
  91. 91. 91
  92. 92. 92 Program Counter  Program counter (PC) is a 13-bit register that contains the address of the instruction being executed.  It is physically carried out as a combination of a 5-bit register PCLATH for the five higher bits of the address, and the 8-bit register PCL for the lower 8 bits of the address.  After the instruction is being executed, next PC will show to CPU the next address of next instruction need to be executed.
  93. 93. 93 Stack  PIC16F877A has a 13-bit stack with 8 levels, or in other words, a group of 8 memory locations, 13 bits wide, with special purpose.  Its basic role is to keep the value of program counter after a jump from the main program to an address of a subprogram.  In order for a program to know how to go back to the point where it started from, it has to return the value of a program counter from a stack
  94. 94. Stack 94 • 13 bit stack size • 8 Level of stack
  95. 95. 95 Stack - Subroutine Call ……….. ………... Call Subroutine at 00F0 Next Instruction ………... ………... ………... Start of Subroutine ……………... Subroutine Instruction ……………... Return from Subroutine Address 0000 0001 0002 0003 0004 0005 0006 Subroutine 00F0 00F1 00F2 00F3 00F4 xxxx xxxx xxxx xxxx xxxx xxxx xxxx 0003 8 Level of 13 bit Stack Program Counter XXXX Main Program To call subroutine: Program counter loaded with destination address 00F0 and return address 0003 pushed onto stack automatically To return from subroutine: Program counter reloaded with 0003 pulled from stack …………...
  96. 96. 96 Addressing Mode (Direct Addressing)  Direct Addressing is done through a 9-bit address.  This address is obtained by connecting 7th bit of direct address of an instruction with two bits (RP1, RP0) from STATUS register as is shown on the following picture. Any access to SFR registers is an example of direct addressing.
  97. 97. 97
  98. 98. 98 Addressing Mode (Direct Addressing)  Example of using Direct Addressing mode bsf STATUS, 5 ;Bankl movlw FFh ;w=0xFF movwf TRISA ;address of ;TRISA 85h register is ;taken from ;instruction movwf
  99. 99. 99 Addressing Mode (Direct Addressing)
  100. 100. 100 Addressing Mode (Indirect Addressing)  Indirect Addressing unlike direct addressing does not take an address from an instruction but derives it from IRP bit of STATUS and FSR registers.  The desired 8 bit register file address must first be written into FSR(04h / 84h) using direct addressing. The FSR will serves as an address Pointer to any address throughout the entire register file. (FSR is a pointer)  Addressed location is accessed via INDF register (Bank 0 at 00h and Bank1 at 80h) which in fact holds the address indicated by a FSR.  The INDF register is not a physical register. Direct access of INDF will actually access the content of register file that pointed by the address in FSR. This is indirect addressing.  Indirect addressing is very convenient for manipulating data arrays located in GPR registers.
  101. 101. 101 Special Function Register File (SFR) for Indirect Addressing Mode Addr Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Bank0 00h INDF Uses contents of FSR to address Data memory …. …. 04h FSR Indirect Data memory Address Pointer Bank1 80h INDF Uses contents of FSR to address Data memory ….. ….. 84h FSR Indirect Data memory Address Pointer INDF = Indirect Address FSR = File Select Register
  102. 102. 102 Addressing Mode (Indirect Addressing)
  103. 103. 103 Addressing Mode (Indirect Addressing)  Example of using Indirect Addressing mode to Clear RAM between (20h – 30h)
  104. 104. 104  Example Addressing Mode (Indirect Addressing)

×