Knowledge base

Setting IRP bit for P16 and P16ENH

Pointers with PIC16 are “near”: they carry only the lower 8 bits of the address. Compiler will automatically clear the 9th bit upon startup, so that pointers will refer to banks 0 and 1. To access the objects in banks 2 or 3 via pointer, user should manually set the IRP, and restore it to zero after the operation. The stated rules apply to any indirect approach: arrays, structures and unions assignments, etc.


EXAMPLE:

From datasheet for PIC16F887: 

http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf#page=27

IRP: Register Bank Select bit (used for indirect addressing). 

1 = Bank 2, 3 0 = Bank 0, 1
Before access to component of an array need to set IRP to 1, and after access, manually return to 0.


CODE:
IRP_bit = 0 ; ' set IRP bit to read from bank 0 and 1 FSR = 0x20 ; ' set pointer to the address 0x20 

a = FSRPTR^; ' read pointed location

IRP_bit = 1 ; ' set IRP bit to read from bank 2 and 3

FSR = 0x30 ; ' set pointer to the address 0x130

b = FSRPTR^ ; ' read pointed location

Contact Support

No file selectedChoose File