Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 
Nigel Goodwin said:
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?.
I agree. It is better to learn to crawl before you learn to walk, ie. the finer points can be learnt later.
 
adamthole said:
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.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top