Bit Functions Introduction

All bit functions use absolute bit addressing.

The absolute bit address is the address of the bit within the PIC data space.

Each byte (RAM or SFR location) within the PIC data space has a unique address.

The relative address of a bit within a data byte is between 0 and 7 and is relative to the byte.

BYTE relative BIT address
63 76543210
64 76543210
65 76543210
66 76543210

The absolute address of a bit within the entire data space is between 0 and 65535 The absolute bit address is calculated as ((N * 8) + M) where N is the byte address of the byte within the PIC data space and M is the relative bit address of the bit within byte N

BYTE absolute BIT address
63 511510509508507506505504
64 519518517516515514513512
65 527526525524523522521520
66 535534533532531530529528

NOTE: XCSB can accomodate absolute bit addresses upto 32 bit but given that currently no PICs are available with more than 8K of RAM the user is advised to use 16 bit variables to manipulate absolute bit addresses.

NOTE2: XCSB can efficiently convert constant absolute bit addresses to single PIC instructions.

The expression ((&PORTA * 8) + 3) has no runtime overhead when used as an argument to the set_bit, reset_bit and test_bit functions

e.g.

set_bit(((&PORTA * 8) + 3))
generates only 1 PIC instruction
if test_bit(((&PORTA * 8) + 3)) != 0 then
generates only 2 PIC instructions

constant absolute bit addresses can be carried efficiently through function calls if the called function is defined as inline. If the called function is not defined as inline then there is a runtime overhead invloved in accessing the byte where the bit is located then the bit itself. The user cannot define functions as inline within the LITE edition of XCSB. This is a restricted feature. However the set_bit, reset_bit and test_bit library functions defined within bit_lib.bas are not restricted and are defined as inline functions.