new device files and register bit names

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1493
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

new device files and register bit names

Post by Jerry Messina » Thu Sep 26, 2024 2:02 pm

The device register bit files in SF v2.2.4.1 now contain structure definitions similar to the examples shown in the wiki Using Bitname Structures
These files are automatically generated from the MPLABX DFP files by the new SystemConvert V2 utility

For example, the file "P18F26Q43.bas" contains

Code: Select all

// PIE1
public const
  INT0IE = 0,
  ZCDIE = 1,
  ADIE = 2,
  ACTIE = 3,
  C1IE = 4,
  SMT1IE = 5,
  SMT1PRAIE = 6,
  SMT1PWAIE = 7

public structure PIE1bits_t
  b as byte
  INT0IE as b.0
  ZCDIE as b.1
  ADIE as b.2
  ACTIE as b.3
  C1IE as b.4
  SMT1IE as b.5
  SMT1PRAIE as b.6
  SMT1PWAIE as b.7
end structure
public dim PIE1bits as PIE1bits_t absolute $049F
The PIE1bits structure allows you to address the bits using the format

Code: Select all

PIE1bits.INT0IE = 1
or using the const bit definitions

Code: Select all

PIE1.bits(INT0IE) = 1
Using the structure method has the advantage that only valid bitnames for that register can be used, while the const bit definitions don't offer that protection since they're just numbers.

The structure and bit names are typically consistant with the ones from the XC8 compiler, so this should make porting any C code a bit easier.
There are some exceptions, such as reserved SF keywords or C multiple bitfields (which are not supported in SF)

Post Reply