Jump to content

Recommended Posts

Just wondering why register names need be referred to in lower case when the datasheets are capitalised?

Guess that the register name is needed to precede the bit to help bank switch for compiler.

 

EG expected setting bit would be TRISA0=0; rather than trisa0.0=0;

Unfortunately, dont have luxury of library.

Thanks,

Al.

Edited by Alistair George
Link to post
Share on other sites

Look at the header files. 'PICxxxxxxx.h' (not 'Pxxxxxx.h'; which are the C2C ones)

 

The upper case name is #defined as a number equal to the address of the register and the lower case name is a C variable defined at that address. Which you use depends on the context but is almost always the C one.

 

The BoostC compiler extends the language with the '.' operator used on variables that aren't structures or unions. It avoids the need to define each register as the union of a byte and a custom bitfield to get the bit names.

 

...

Register mapped variables

Variables can be forced to be placed at certain addresses. Syntax is the same as in the legacy C2C compiler:

char var@<addr>;

where <addr> is an hex or decimal address.

This technique is used to access target specific registers from code.

Please note that system header files already contain all target specific registers, so there is no need to define them again in the user's code.

Bit variables can also have fixed addresses. Their address includes bit position and can be made in 2 forms:

bit b; //variable will be placed by linker at arbitrary position
bit b1@0x40.1; // dotted: access bit 1 of register 0x40
bit b2@0x202; // bit offset: access bit 2 of register 0x40 (0x40*8 + 2)

Bit access

Besides 'bit' variables, individual bits of every variable can be accessed using the '.' operator:

char var;
var.2 = 1; //set bit 2 of variable 'var'

...

 

N.B. the RH operand of '.' used on an ordinary variable must be a numeric constant (or #define of the same). Use shift and mask techniques if you really need to access a changeable bit and watch the hex file bloat . . .

Edited by IanM
Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...