Author Topic: Where are register 'shortcuts' defined MPlabX  (Read 870 times)

0 Members and 1 Guest are viewing this topic.

Offline EteslaTopic starter

  • Regular Contributor
  • *
  • Posts: 149
  • Country: us
Where are register 'shortcuts' defined MPlabX
« on: January 13, 2019, 08:04:58 pm »
Hey guys, this post is dealing with PIC micro controllers and the MPlabX IDE.
I always have trouble figuring out which things I need to type to access certain registers (PORTA, TRISA, T1CON, CCP1R, etc) in C, especially when I'm moving from mcu to mcu. For example, for one chip to access the third bit of PORTD, I type PORTD.RD0, and for another I just need to type RDO. Is there a document MPlabX is pulling from to give these definitions, and if so, where do I find it? Thanks!
« Last Edit: January 13, 2019, 08:10:57 pm by Etesla »
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 822
Re: Where are register 'shortcuts' defined MPlabX
« Reply #1 on: January 13, 2019, 08:31:02 pm »
microchip/xc8/v2.00/pic/include/your_pic.h

They are trying to get you to use the LATAbits.LATA0 versions (unions), but they also have LATA0  declared as a __bit to keep old code working and anyone happy who wants to use that way.

You can type LATA in your code anywhere, right click, select navigate, Go to Declaration/Definition and you will have found your header file.
 
The following users thanked this post: Etesla

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: Where are register 'shortcuts' defined MPlabX
« Reply #2 on: January 14, 2019, 02:23:40 pm »
Hey guys, this post is dealing with PIC micro controllers and the MPlabX IDE.
I always have trouble figuring out which things I need to type to access certain registers (PORTA, TRISA, T1CON, CCP1R, etc) in C, especially when I'm moving from mcu to mcu. For example, for one chip to access the third bit of PORTD, I type PORTD.RD0, and for another I just need to type RDO. Is there a document MPlabX is pulling from to give these definitions, and if so, where do I find it? Thanks!

I would suggest putting some time in to learning how to use bit masks and logic operations (OR, AND, XOR). Once you know how to do that, you can manipulate anything in any way you need/want, sometimes more efficiently.

Need to test whether two bits are active? You can test both bits individually using friendly names, or you can simply AND the variable with the appropriate mask and test for the appropriate resulting value. e.g.

Code: [Select]
#define BUTTON_1 0x01
#define BUTTON_2 0x02
#define BUTTON_3 0x04
#define BUTTON_4 0x08
#define SECRET_BUTTONS (BUTTON_1 | BUTTON_4)

/* Test for super secret button combination */
if ((PORTA & SECRET_BUTTONS) == SECRET_BUTTONS) {
    /* Do something super special */
}

vs

Code: [Select]
/* Test for super secret button combination */
if (PORTA.RA0 == 1 && PORTA.RA3 == 1) {
    /* Do something super special */
}

Perhaps the first example looks more complicated, but a lot of the variables used are computed at compile time and the resulting values simply used throughout. Depending on how smart the compiler is, the second example could result in many more instructions being generated.

Otherwise, what cv007 said. Right click any variable name and you can nagivate to where it has been declared. For internal register names it should take you straight to your processors header file.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf