PIC: change of bank

Status
Not open for further replies.

folarinv

New Member
To change from Bank 0 to bank 1, nigel's tutorial suggests that I do

bsf STATUS, RP0

but another tutorial suggest that i do

BSF 03h,5

so, which one is more appropriate.
 
Go with Nigel's.

If I saw bsf 03h,5 I would have no idea what it did and would have to refer to the datasheet.

On the other hand,

BSF STATUS,RP0

is self explanatory.

Mike
 
Bank switching is sometimes annoying, but there is a simplier way to do that BSF/BCF instructions. There is a banksel dirrective/macro in MPLAB, that helps a lot, so for example "old" bank switching code:

Code:
BSF STATUS,RP0 ;go to TRISA bank

Can be changed to:

Code:
banksel TRISA

or to

Code:
banksel 1

This is pretty usefull when your PIC has more than 2 banks, so you don't have to read the datasheet every time you want to use new SFR

The banksel dirrective/macro is producing BSF/BCF instruction(s) for you, so this is much easier.
 
folarinv said:
To change from Bank 0 to bank 1, nigel's tutorial suggests that I do

bsf STATUS, RP0

but another tutorial suggest that i do

BSF 03h,5

so, which one is more appropriate.

As already suggested, you should use the labels from the MicroChip include files, this tells you (at least vaguely!) what the line is doing. 'STATUS' is far more informative than '03h', as Jay has suggested, you can also use the inbuilt macros which will generate the lines for you with a 'banksel' instruction - but for tutorial purposes I thought this might be more confusing?.
 
It hasn't been said explicitly yet, but just so their is no confusion, both segments of code you gave will do precisely the same thing.

When you use MPLAB it will replace "STATUS" with 03h and "RP0" with 5 when it assembles, making the code identical.
 
I agree. It is better to learn to crawl before you learn to walk, ie. the finer points can be learnt later.
 

Yes, all the include file does is act as a data file for 'text replacement' during assembly, so each word that matches one in the include file will be replaced by the value in the file.

It's well worth having a quick look through the include file, it can help you understand better what's happening.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…