• AVR Freaks

AnsweredHot!How or where to cross reference C++ register naming convention with hardware registers?

Author
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
2020/07/01 18:53:57 (permalink)
0

How or where to cross reference C++ register naming convention with hardware registers?

Hi,
Working with XC8 I have never figured out how to determine what program naming convention refers to what hardware registers or segments.  For example with a PIC18F45K50 going in to the configuration bits yields a register name, field, and option for configuration.  There are many points in the past where I have researched what register configuration elements I need to use to accomplish an outcome and looking back at it I can't remember where SSPCON for example came from without crossreferencing the user manual.  Is there some kind of environment where this is centrally contained in?  Searching through program doesn't yield the origin of say SSPCON however it does show me instances of where I used it.  Or like UCFGbits.FSEN?  Where is it defined?  I'm looking at some kind of hashmap file that is showing FSEN as like a member of UCFG, but the nomenclature "UCFGbits." eludes me...kind of like a new discovery session every time I want to configure another register parameter.  Is there a clear listing of this stuff somewhere or am I just not seeing it?
#1
ric
Super Member
  • Total Posts : 28009
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 19:21:27 (permalink) ☼ Best Answerby IBrokeIt 2020/07/01 19:49:54
+1 (1)
XC8 is "C", not "C++"
Register names should be exactly the same as in the datasheet.
For configuration bits, the config editor built into MPLABX is by far the fastest way to find the allowable settings.
 
I think you will find what you are looking for in
C:\Program Files\Microchip\xc8\v2.20\pic\include\proc\pic18f45k50.h
or
C:\Program Files (x86)\Microchip\MPLABX\v5.40\packs\Microchip\PIC18F-K_DFP\1.4.87\xc8\pic\include\proc\pic18f45k50.h
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
Aussie Susan
Super Member
  • Total Posts : 3737
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 19:24:56 (permalink) ☄ Helpfulby IBrokeIt 2020/07/01 19:49:58
+1 (1)
You were right when you mentioned the data sheet. Lets take the MCU you reference and go from there.
Register 24-2 on page 340 of the data sheet version linked to the MCU web page is all about the UCFG register.
FSEN is bit 2 of that register with the description of the bit and its possible values and their interpretation are on the same page.
A search of the data sheet shows that UCFG is mentioned 13 times and FSEN 10 times. Of course some of those are related to the register definition but others are also mentioned in diagrams and descriptions within the datasheet.
Susan
#3
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 19:49:45 (permalink)
0
Got it.  My main confusion was in looking at the data sheet I guess.  On page 340 it references an entity called "UCFG" along with itemizing configuration parameters.  I see an FSEN there.  My gut instinct based on that would be to try to compile a reference to "UCFG.FSEN" subsequently.  However the C convention in actuality is "UCFGbits.FSEN" so there is still a bit of a discrepancy unless you know that you are searching for "UCFGbits.xyz" in XC8 nomenclature.  I do see the typedef in the include that ric mentions and this makes sense now.  I can use this which references memory address at0xF6F and append the const parameter I intend to modify.  Let's pull another arbitrary example.  I want to go to TRISBbits.xyz.  I see that in the header file.  Check.
 
Now I want to modify an entity called SSPCON because I am trying to I2C stuff.  I can do that in main() no problem.  But when I go to look at PIC_CHIP_WHATEVER.H I don't see a reference to it.  I don't see reference to it either when I go to set configuration bits.  Browse data sheet, not there.  Digging through, I remember it's probably in section 17.0.  Five minutes later I am on page 249 looking at a SSP1CON1.  Oh, yeah, that's probably it.  Now how did I end up referencing SSPCON to set this mask in the program?  Nuances like that are a (smaller) part of what I was questioning.  Not that I can't drop program references like //SSPCON XC8 -> SSP1CON1 datasheet pg. 249.  I'm trying to figure out where the one offs like SSPCON originate in XC8.
 
So like 95% of the way there now knowing this .h file exists and I can live with the other 5% digging...just really curious where this is defined.  Unless it is right in front of my face all along.
 
And to your note ric, yes, I had intended to write C rather than C++.  Partially have Win32 API on my mind too.  Doh.
#4
ric
Super Member
  • Total Posts : 28009
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 20:01:16 (permalink)
+1 (1)
IBrokeIt
I see an FSEN there.  My gut instinct based on that would be to try to compile a reference to "UCFG.FSEN" subsequently.  However the C convention in actuality is "UCFGbits.FSEN" so there is still a bit of a discrepancy unless you know that you are searching for "UCFGbits.xyz" in XC8 nomenclature.

XC8 started out based on a fairly old version of C, which simply doesn't support using the same name with and without "bitfield" references.
So, the convention adopted by its predecessor (HITECH C), and now all versions of XC8 is to add a "bits" suffix to the register name, and define a second variable that overlays the same register address to give you a version with the bitfields attached.
 

Now I want to modify an entity called SSPCON because I am trying to I2C stuff.

You won't find any register by that name in the PIC18F45K50 datasheet.
It may exist in a simpler PIC that only has a single SSP peripheral controlled by a single register.
Many newer PICs have multiple SSP peripherals, so they now have a peripheral number in the register name, and there are multiple registers controlling each peripheral, so SSPxCONy is for peripheral#x, register number y
 

I'm trying to figure out where the one offs like SSPCON originate in XC8.

Some device header files may #define SSPCON to overlay to one of the newer register names to be compatible with older software. You are free to do the same yourself if it suits you.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 20:16:28 (permalink)
0

Some device header files may #define SSPCON to overlay to one of the newer register names to be compatible with older software. You are free to do the same yourself if it suits you.
 
 
Ahhh crud.  I missed this in the header file for my device...there all along.  Starting on line 10217 three mnemonics refer to the same 0xFC6, "SSP1CON1, SSPCON, and SSPCON1."  Unsurprisingly they all build the same.  That clears up the last 5%.  Thanks!
#6
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/01 20:17:29 (permalink)
+1 (1)
Note to self: figure out how quoting works.
 
#7
mlp
boots too small
  • Total Posts : 946
  • Reward points : 0
  • Joined: 2012/09/10 15:12:07
  • Location: previously Microchip XC8 team
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/07 08:31:06 (permalink)
+1 (1)
ric
a fairly old version of C, which simply doesn't support using the same name with and without "bitfield" references.

Unless I've been seriously misled, even the latest (2011) C standard, which XC8 does not yet support, has not changed this aspect of the C language.
 
(HI-TECH PICC previously used its own naming convention for whole-SFRs versus bitfield-parts-of-SFRs, but we changed to match C18's convention some time during my tenure there. That change caused lots of people to jump up and down because it broke old code, too.)

Mark (this opinion available for hire)
#8
ric
Super Member
  • Total Posts : 28009
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/07 13:39:36 (permalink)
0
That's for correcting my terminology Mark.
I wasn't sure if it was now possible using "anonymous unions".
I was trying to make clear that you cannot do it in XC8, without making a blanket "you can't do it in C" statement.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#9
mlp
boots too small
  • Total Posts : 946
  • Reward points : 0
  • Joined: 2012/09/10 15:12:07
  • Location: previously Microchip XC8 team
  • Status: offline
Re: How or where to cross reference C++ register naming convention with hardware registers 2020/07/09 06:38:17 (permalink)
0
ric
That's for correcting my terminology Mark.
I wasn't sure if it was now possible using "anonymous unions".
I was trying to make clear that you cannot do it in XC8, without making a blanket "you can't do it in C" statement.

Even with "anonymous unions"1 you still need to use the object.member syntax, so it's not the same as wholeSFR = 23; other = wholeSFR.partial; as some non-C compilers allow - it'd be more like SFR.whole = 23; other = SFR.partial;.
 
1 I'm not sure of the real term for these either - I was immersed in C90 for a long time, and now I'm not doing C in my day job at all so have had little incentive to absorb the newer standards to the same extent.

Mark (this opinion available for hire)
#10
Jump to:
© 2020 APG vNext Commercial Version 4.5