OPTION is in banks 1 & 3 and TMR0 is in banks 0 & 2.
When using banksel for things like OPTION_REG or TMR0 and considering that these exist in two different sets of banks, which bank does it select?
I've been using banksel for these registers for a little while and not knowingly come across a problem doing it - just curious as to possible problems, if any.
When I programmed in Asm I kept away from banksel as it always produces two instructions when one or even none are needed. I now realise that it's irrelevant as the processor is so fast (fast enough to use C).
I know you can do it either way but why not use the option instruction (now deprecated) to set the option register?
A quick simulation (MPLAB SIM) with this code:
Showed RP1 and RP0 bits of STATUS for TMR0 as 00 ( Bank 0) and for OPTION_REG was as 01 (Bank 1). I don't usually use the banksel directive, as I track what bank I am in to minimize switching when practical.
Mike, at some stage, I forget if it was an older PIC or a newer enhanced one, I kept getting an error message when trying to use the 'option' instruction, hence I've used option_reg ever since.
JP, thanks for that, answers the question.
I also do my best to group as much code as possible to minimise switching banks.
Mike, at some stage, I forget if it was an older PIC or a newer enhanced one, I kept getting an error message when trying to use the 'option' instruction, hence I've used option_reg ever since.
The 16F628 datasheet mentions it was left in to be compatible with 16C5X chips and should not be used for newer chips.
As to when it actually stopped working I don't know, I'm incapacitated at the moment, so might compile for a few different PICs tomorrow and see where it stops.