Published:2011/8/5 6:08:00 Author:Amy From:SeekIC
By Ron Coates
Direct addressing
Direct addressing is much easier than with the P1C16F series and we’ve reasons to doubt if most programs will need to use banking commands at all.
As you will see from the memory map, the first half of bank 0 and the second half of bank 15 have been designated as the Access Bank. From reading the Microchip data sheet, you would think that this gave you 128 General Purpose Registers and all the Special Function Registers which you could access directly without using banking commands.
This would be good, but the reality is even better, since you can, in practice, use all 256 registers in bank zero and all the Special Function Registers without using banking commands and without running into conflicts. Since we just said above that you could only ever access 256 bytes without a banking command, how does this work? It works by using the access bit (a) to select either the access bank or the bank selected by the BSR.
Suppose we define a register call TESTREG as follows
TESTREG
EQU
0x84
A look at the Special Function Register map will show you that 84 in the Access bank is Port E. You would think that a conflict would then exist between these, and indeed it could but for the way Microchip have defined the default value of the access bit.
Consider the following code:
MOVLW 02
MOVWF TESTREG
MOVLW 04
MOVWF PORTE
Although we have not used the access bit, these lines will be translated by the compiler as if we had written:
MOVLW 02
MOVWF TESTREG, 1
MOVLW 04
MOVWF PORTE, 0
For the first MOVWF command the access bit is 1 which means use the bank specified by the BSR, the default value of which is zero. The 02 will thus be put in location 0x084.
For the second MOVWF command the access bit is 0 which means use the access bank. The 04 will then be stored in 0xF84.
The clever bit is that we don’t have to think about this at all, the compiler does it all for us, provided, of course, all the necessary ’declarations’ (label and/or function statements) are present at the start of the program code. Don’t worry if you don’t fully understand all of the above, all that matters is that you can use all the General Purpose Registers you want from 00 to FF, and all the Special Function Registers that you need to, without having to worry about banking at all. If you need more than 256 registers, you should probably be using indexed addressing anyway.
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)_2.html
Print this Page | Comments | Reading(727)
Author:Ecco Reading(30199)
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(3531)
Author:Ecco Reading(3936)
Author:Ecco Reading(3708)
Author:Ecco Reading(3678)
Author:Ecco Reading(3715)
Author:Ecco Reading(6029)
Author:Ecco Reading(3693)
Author:Ecco Reading(4479)