Maker Pro
Maker Pro

PIC TRISA 05 or 85 ?

I'm a bit confused about programming a PIC chip.

Some code I've seen has equates for the TRISA and TRISB registers as
05,06 or 85,86.
If Bank 1 is selected, does it matter whether address 05 or 85 is
chosen?
Are the higher addresses used just for code readability?
 
A

Andy Wood

I'm a bit confused about programming a PIC chip.

Some code I've seen has equates for the TRISA and TRISB registers as
05,06 or 85,86.
If Bank 1 is selected, does it matter whether address 05 or 85 is
chosen?
Are the higher addresses used just for code readability?

What PIC ar you using?

For the ones I have used, MPASM would generate the same code for an
instruction like
CLRF TRISA
regardless of whether TRISA was equated to h'05' or h'85'. However, if
you did something like
BANKSEL TRISA
you could get into trouble if TRISA was equated to 05.


Andy Wood
[email protected]
 
Thanks,

Its a PIC16F84A . I'm trying to get my head around the bank switching.
I understand that reading/writing GPRs whilst bank 1 is selected will
read/write their bank 0 values.
Consensus seems to be to use address 85 (86 for TRISB).
 
A

Andy Wood

Thanks,

Its a PIC16F84A . I'm trying to get my head around the bank switching.
I understand that reading/writing GPRs whilst bank 1 is selected will
read/write their bank 0 values.
Consensus seems to be to use address 85 (86 for TRISB).

If you look at fig 2.2 in the PIC16F84A data sheet you will see that
the ram bytes 8C-CF are the same as 0C-4F, so it does not matter what
bank you are in when you access them. Some of the SFRs work the same
way, for example INTCON and PCLATH, but for other SFRs including TRISA
and TRISB you have to have the correct bank selected. One way to
select the bank is to use BANKSEL, which for the 16F84A will generate
BCF or BSF instructions to clear or set RP0 in the STATUS register -
if TRISA is incorrectly equated to 05 BANKSEL will select the wrong
bank. If you don't use BANKSEL you might get away with it, but I don't
see any reason to live dangerously.


Andy Wood
[email protected]
 
Thanks, that has cleared it up.

Andy said:
If you look at fig 2.2 in the PIC16F84A data sheet you will see that
the ram bytes 8C-CF are the same as 0C-4F, so it does not matter what
bank you are in when you access them. Some of the SFRs work the same
way, for example INTCON and PCLATH, but for other SFRs including TRISA
and TRISB you have to have the correct bank selected. One way to
select the bank is to use BANKSEL, which for the 16F84A will generate
BCF or BSF instructions to clear or set RP0 in the STATUS register -
if TRISA is incorrectly equated to 05 BANKSEL will select the wrong
bank. If you don't use BANKSEL you might get away with it, but I don't
see any reason to live dangerously.


Andy Wood
[email protected]
 
Top