User Tools

Site Tools


pic_asm:pic_register_bank_switching

PIC Register BANK and flash PAGE switching.

Some nice macros that make fast switching of register banks.

Some of these are postscripted with “F” and are fast versions but they make assumptions. Only use these if you are sure about the given state and they don't take care of the INDF register pointer bits.. The BANKx versions are longer execution but always safe.

Some could be shortened by AND/OR operations but this would mean trashing W so we do it one bit at a time.

; Bank Switching Macros
;
;These macros do not impact any registers except where stated
;
; Macros:
;		BANK0		Switch to Bank0 by manipulating the status bits
;		BANK0F		Fast switch to Bank0 by trashing STATUS
;		BANK1		Switch to Bank1 by manipulating the status bits
;		BANK1F		Fast switch to Bank1 by setting single bank bit - assumes we are in Bank0. Watch out for INDF!
;		BANK2		Switch to Bank2 by manipulating the status bits
;		BANK2F		Fast switch to Bank2 by setting single bank bit - assumes we are in Bank0. Watch out for INDF!
;		BANK3		Switch to Bank3 by manipulating the status bits
;
;		PAGE0		Set flash Page0 by setting PCLATH bits
;		PAGE1		Set flash Page1 by setting PCLATH bits
;		PAGE2		Set flash Page2 by setting PCLATH bits
;		PAGE3		Set flash Page3 by setting PCLATH bits
;

BANK0	MACRO
	NOLIST
	BCF		STATUS,RP0	; clear bank select bits
	BCF		STATUS,RP1
	BCF		STATUS,IRP	; clear indirect addressing bit
	LIST
	ENDM

BANK0F	MACRO		; fast bank0 destroys fags
	NOLIST
	CLRF	        STATUS
	LIST
	ENDM

BANK1	MACRO
	NOLIST
	BSF		STATUS,RP0
	BCF		STATUS,RP1
	BCF		STATUS,IRP	; clear indirect addressing bit
	LIST
	ENDM

BANK1F	MACRO		; fast bank1 assumes we are in bank0
	NOLIST
	BSF		STATUS,RP0
	LIST
	ENDM

BANK2	MACRO
	NOLIST
	BCF		STATUS,RP0
	BSF		STATUS,RP1
	BSF		STATUS,IRP	; set bit for indirect addressing
	LIST
	ENDM

BANK2F	MACRO		; fast bank2 assumes we are in bank0
	NOLIST
	BSF		STATUS,RP1
	LIST
	ENDM

BANK3	MACRO
	NOLIST
	BSF		STATUS,RP0
	BSF		STATUS,RP1
	BSF		STATUS,IRP	; set bit for indirect addressing
	LIST
	ENDM

BANK3F	MACRO		; only changes bank bits, not IRP
	NOLIST
	BSF		STATUS,RP0
	BSF		STATUS,RP1
	LIST
	ENDM

; macros for accessing page's directly
PAGE0	MACRO
	NOLIST
	BCF		PCLATH,3
	BCF		PCLATH,4
	LIST
	ENDM

PAGE1	MACRO
	NOLIST
	BSF		PCLATH,3
	BCF		PCLATH,4
	ENDM

PAGE2	MACRO
	NOLIST
	BCF		PCLATH,3
	BSF		PCLATH,4
	LIST
	ENDM

PAGE3	MACRO
	NOLIST
	BSF		PCLATH,3
	BSF		PCLATH,4
	LIST
	ENDM


pic_asm/pic_register_bank_switching.txt · Last modified: 2024/01/19 09:40 by 127.0.0.1