Published:2011/8/5 6:34:00 Author:Amy From:SeekIC
By Ron Coates
Indirect addressing
If you thought, direct addressing was good, things get even better with indirect addressing. This is because we have a 12-bit number to use for addressing, giving us direct access to all 16 banks. After all, both 2** and 16x256 equal 4,096.
First of all, there are now three FSR registers, FSR0, FSR1 and FSR2. Associated with these are three INDF registers.
For the purpose of this explanation we shall only talk about FSR0 and INDF0 but exactly the same rules apply to the other two.
The big difference is that there is now an FSROL (L= low) register which is an 8-bit register and is equivalent to the FSR register in the 16F series. We now also have an FSR0H (H= high) register of which only the lowest four bits are available, as these are all that are needed to address the sixteen banks.
By using these two registers together we can point to anywhere in the RAM memory space. Belter still, if we are incrementing FSROL, then when we get to OFF and increment FSROL again, FSROL changes to 00 and FSR0H is automatically incremented so we can move seamlessly from, say, FF in bank 2 to 00 in bank 3.
It gets better still because additional ways of manipulating indirect addressing have been introduced.
These are: (where n is 0, 1 or2)
INDFn: Carries out the command to the indirect register and does nothing else. The same as the 16 series INDF.
POSTDECn: As above, but after carrying out the command, the FSR is automatically decremented.
POSTINCn: After carrying out the command the FSR is incremented.
PREINCn: The FSR is incremented before carrying out the command.
PLUSWn: The value in the W register is used as an offset to the FSR. After the command both the FSR and W registers remain the same.
An example of the last of these commands would be:
INCF PLUSW0
If the value in FSR0 was 0x023 and the value in W was 04, then the effect of the above command would be to increment the value in location 0x027. After the command the values in FSR0 and W would be unchanged. Consider the following pieces of code which you should always use in the initialization part of any program to clear the RAM.
For the 16F series we would have written:
NEXT
MOVLW 0X20
MOVWF FSR
CLR INDF
INCF FSR
BTFSS FSR, 7
GOTO NEXT
This segment of code starts at RAM location 0x20 (after the Special Function Registers) and clears each RAM location until 0x7F i.e. the whole of bank 1. Because 0x8O-Ox9F are Special Function Registers, you would have had to write similar separate segments for banks 2, 3 and 4. For the PIC1 8F devices we can write
NEXT
LFSR FSRO, 0x000
CLRF POSTINC0
BTFSS FSROH, 0
GOTO
Examining this line by line, line 1 starts with a new instruction LFSR. You can put values in FSROL and FSROH separately using the normal MOVLW and MOVWF commands. However you can also initialize both registers at once using the LFSR command, followed by FSRO (or 1 or 2), then a comma followed by a three digit hex number. The first digit will go into the low byte of FSROH and the other two into FSRL. So the effect of our first line is to ensure that the FSR is pointing to the first register in our RAM space.
The next line is a label, NEXT, followed by the familiar CLRF. The POSTINCO operand would result in the register at location 000 being cleared and the FSRO register then being incremented. After the
GOTO NEXT
instruction the value in 0x001 will be cleared and this sequence will be continued until the
BTFSS FSROH, 0
command causes the program to jump out of the loop when the value in FSRO reaches 0x100. The last memory location to be cleared will be 0xOFF.
With the PIC18F series, only four lines of code have cleared all 256 bytes of bank 0. To clear this much memory on the PIC16 series we would have had to repeat the six lines shown twice more for bonks 1 and 2 making a total of eighteen lines.
Next month...
The next instalment will look at the improvements to ROM addressing and the implementation of long look up tables.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/05/Goodbye_'16_welcome_PIC_18F__meet_the_PIC18F_series_(part1)_3.html
Print this Page | Comments | Reading(977)
Author:Ecco Reading(30195)
Author:Ecco Reading(3462)
Author:Ecco Reading(3182)
Author:Ecco Reading(3662)
Author:Ecco Reading(5233)
Author:Ecco Reading(3249)
Author:Ecco Reading(3390)
Author:Ecco Reading(3530)
Author:Ecco Reading(3936)
Author:Ecco Reading(3708)
Author:Ecco Reading(3678)
Author:Ecco Reading(3715)
Author:Ecco Reading(6028)
Author:Ecco Reading(3693)
Author:Ecco Reading(4479)