Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How do we find what registers have been defined for PIC when using XC8 in MPLABX

Status
Not open for further replies.

matrixofdynamism

Advanced Member level 2
Advanced Member level 2
Joined
Apr 17, 2011
Messages
593
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,681
I see PIC Programs making use of CMCON, TRISA, PORTA, TRISB, PORTB e.t.c without declaring them. They can't be constants since we assign them a value. I think they represent an address of some sort. But am not sure how we can set them equal to some value :bang:

What are these things and where are they declared? What do they represent and how do we know how many of them exist?

I further see codes of line which look like this LATAbits.LATA0 = 1. This looks more like a struct to me. Where does LATAbits come from?

I got these names from hello world programs for PICs on the internet. I am using MPLABX IDE with XC8 compiler.
 

I think he is looking for the labels given to each register which the datasheet does not give. I had to find the xc8.h file and open it in notepad to find how they labeled each register in order for the compiler to recognize them.
 
You have included the required header file that contains all the definitions. On the XC8, I think you add xc.h that adds the required device-specific header file for you. Hold CTRL on your keyboard and click on the header file name in MPLABX. Find your device specific header file and again, click on it while holding down CTRL. You can see the contents in MPLABX then.
 
This means that I can take it for granted that in the header files there are arleady labels defined for everything that is present in the Special Function Registers part of the datasheet for a microcontroller. Therefore, e.g what I see in Table 4-1 "Special Function Register Map" in https://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf#page=47, I can take it for granted that they all are already described in the header files in the XC8 compiler with the correct address values?

I just want to know one thing. As far as I know all these registers are described in the header file using #define statements. The #define actually defines a constant and a constant cannot be used on LHS of a statement. However, in the XC8 we can simply write PORTB=0xA0. How does the compiler know that PORTB refers to a specific point in the memory and is not a constant?
 

I have moved through the hierarchy of the header files in the XC8 compiler starting from xc.h and going upto the header file for a specific PIC18F device.

It declares a lot of variables using a syntax which looks like this:

extern volatile typename variable_name @ address_value

it does the same using assembly level instruction depending on the evaluation of a #ifndef statement which looks like this

asm("variable_name equ hex_address_value")

In order to make it possible to access single bits, it also declares a union for each port making it possible to control each individual bit and also using different names for the same pin as a pin may have multiple functions.

The variable name above follows the name of a SFR in the datasheet of that device and so does the address value follow what is given in the datasheet.

Now it all makes sense. Thanks for the help guys.

- - - Updated - - -

The #define that also exist in the same header file actually define constants that can be used in function calls when for example setting the properties of a peripheral. They only make the code more readable and serve no other purpose.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top