Review Question : 1. Explain the addressing modes supported by PIC18 with the help of suitable examples.
Addressing Modes
•
Part of the programming flexibility is the different kind of ways the
programmer can refer to data stored in the memory. The different ways that can
access data are referred to as addressing modes.
•
The PIC 18 microcontroller supports following addressing modes :
1.
Immediate addressing mode
2.
Direct addressing mode
3.
Register indirect addressing mode
4.
Register Indirect/Indexed ROM addressing mode
1.
Immediate addressing mode
•
In immediate addressing mode, the immediate data is specified in the
instruction. Immediate data is also called literal in PIC18.
•
The immediate addressing mode is used to load the data into PIC registers and
WREG register. However, we cannot use immediate addressing mode to load data
into any of the file register.
•
Examples:
1.
MOVLW 0x50 ; Load 50 H into WREG
2.
ANDLW D '18' ; Logically AND WREG with 18 decimal
3.
ADDLW B' 01100000' ; Add 60 H in WREG
•
The
letter 'L' in the instruction means literal (immediate).
•
To
load immediate data in file register data RAM, we have to load immediate data in
WREG register and then it can be copied to file register data RAM location.
•
We
can use the EQU directive to access immediate data as shown below. NUM EQU 0x50
…
MOVLW
NUM ; Load 50H in WREG
2.
Direct addressing mode
In
direct addressing mode, the operand data is in the file register (RAM) data
memory. The address of this memory location is specified in the instruction.
•
Examples:
1.
MOVWF 0X10 ; Copy contents of WREG into File Register RAM location 10 H
2.
MOVFF 0X10, 0X20 ; Copy contents of location 10 H to 20 H dip elde
3.
MOVFF 0X30, PORTC ; Copy contents of location 30 H to PORTC
•
The
letter 'F' in the instruction means the address of the file register location.
•
The
letter 'FF" in the instruction means the both source and destination
addresses are file register locations.
3.
Register indirect addressing mode
•
Register indirect addressing mode is used for accessing data stored in the file
register (RAM) data memory.
•
In
this addressing mode, three file select registers - FSRO, FSR1, and FSR2 are
used as pointers to the memory locations of the file register (RAM) data
memory.
•
Each of the FSRO, FSR1, and FSR2 registers has an INDF register associated with
it, and these are called INDFO, INDF1, and INDF2. When we move data into INDFX
we are moving data into a RAM location pointed to by the FSRX.
Examples:
1.
LFSR 1, 0x55 ; Load FSR1 with 55H
MOVWF
INDF1 ; copy contents of WREG into RAM location
;
whose address is held by FSR1 register, i.e. 55H
2.
LFSR 0, 0x40 ; Load FSR0 with 40H
MOVF
INDFO,W ; Copy the contents of RAM location pointed by FSRO to WREG
4.
Register Indirect/Indexed ROM addressing mode
•
We use code space to store fixed data along with the code. This addressing mode
is used for accessing the fixed data from look up tables that reside in the
PIC18 program ROM. This process is often called table processing.
•
Directive DB is used to define an 8-bit fixed data in data ROM. Here, we have
to use special function register to point the data to be fetched from the code
space.
•
Two registers are used in the table processing: TBLPTR (TaBLe PoinTR)
and TABLAT (TABle LATch). eisibemmi bol ol
•
The 21 bit register TBLPTR is used to access byte from PIC18 program ROM. With
21 bit register TBLPTR we can cover the entire 2M program (code) space for
PIC18.
•
TBLPTR register in divided into three parts: TBLPTRL (Low), TBLPTRH (High), and
TBLPTRU (Upper). These parts are of the SFRS.
•
TABLAT register is used for keeping the byte read from code space pointed by
TBLPTR.
•
Example :
MOVLW
0x0 ; WREG = 10 Look-up Table low -byte address
MOVWF
TBLPTRL ; Load Look-up Table low -byte
address in TBLPTRL register
MOVLW
0x10 ; WREG = 10 Look-up Table high -byte address
MOVWF
TBLPTRH ; Load Look-up Table high-byte
address in TBLPTRH register
MOVLW 0x0 ; WREG = 0 Look-up Table upper-byte
address
MOVWF TBLPTRU ; Load Look-up Table upper-byte address
in TBLPTRH
;
register
TBLRD*
; Read byte pointed by TBLPTR
MOVFF
TABLAT, PORTB ; Send the read byte to PORTB
Review Question
1. Explain the addressing modes supported by PIC18 with the help of suitable examples.
Microprocessors and Microcontrollers: Unit V: (b) Introduction to RISC Based Architecture : Tag: : Introduction to RISC Based Architecture - Addressing Modes