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.

coding question ( including port definitions )

Status
Not open for further replies.

nikouz

Newbie level 6
Joined
Feb 5, 2021
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
115
Hi all

i have a coding question. On my main.c file i have the following definitions:
Code:
#define ButtonSetClockDate  PORTCbits.RC0  //RED
#define ButtonPlus          PORTCbits.RC1  //YELLOW
#define ButtonSetAlarm      PORTCbits.RC2  //ORANGE
These are used in main.c but also i use them in another file RTC_ReadWriteEdit.c. When i am compiling comes up the following error:

RTC_ReadWriteEdit.c:130:8: error: (192) undefined identifier "PORTCbits"
RTC_ReadWriteEdit.c:130:21: error: (196) struct/union required

How can i go with this? Thanks.
 
Last edited by a moderator:

Hi,

for coding questions please always tell us
* your complier
* your IDE
* the target microcontroller

***
Every statement needs to be defined somewhere.
Thus my question:
Where in your case is "PORTCbits" defined?

Example:
Maybe "PORTCbits" is efined in STD_IO.h.
Then add the line: "#include "STD_IO.h"
at the top of your code file. (Exact syntax depends on IDE and compiler)

Klaus
 

Hi,

for coding questions please always tell us
* your complier
* your IDE
* the target microcontroller

***
Every statement needs to be defined somewhere.
Thus my question:
Where in your case is "PORTCbits" defined?

Example:
Maybe "PORTCbits" is efined in STD_IO.h.
Then add the line: "#include "STD_IO.h"
at the top of your code file. (Exact syntax depends on IDE and compiler)

Klaus
Hi
MPLAB with xc8 for pic 16F1829
--- Updated ---

Hi,

for coding questions please always tell us
* your complier
* your IDE
* the target microcontroller

***
Every statement needs to be defined somewhere.
Thus my question:
Where in your case is "PORTCbits" defined?

Example:
Maybe "PORTCbits" is efined in STD_IO.h.
Then add the line: "#include "STD_IO.h"
at the top of your code file. (Exact syntax depends on IDE and compiler)

Klaus
My definitions are on main.c file. Then i have a RTC_ReadWriteEdit.c and RTC_ReadWriteEdit.h files. When i am using the say the ButtonPlus definition in RTC_ReadWriteEdit.c file the compiler comes up with the fault i describe on my main post.
Thanks
--- Updated ---

Hi
I enclose the files for convenience.
 
Last edited:

Hi

Put the definition in a h-file. Then include this h-file in the top of every c-file where they have to be used.
 
Solution
Each compiler has its own syntax for accessing special function registers, e.g. port bits. PORTCbits is no XC8 standard, it's defined in old C18 compiler. You can either switch to the SFR defines defined with XC8 by default (when including xc.h) or need to enable C18 support. Review the doc or Microchip XC8 support forum.
 

Hi,

The compiler clearly talks about missing "PORTCbits" definition.

You still didn't answer my question:


Klaus
Was on main i have also posted the code files.Anyway is solved.

Hi

Put the definition in a h-file. Then include this h-file in the top of every c-file where they have to be used.

tyassin is right. I had already tried this way but didn't work and the reason was that i was included the .h file in the end of all the other includes. Should be in the very beginning.​

Thank you all for your time. Have nice day.
 

Hi
Was on main i have also posted the code files.Anyway is solved.

Respectfully .. but you are wrong. I guess you mix "use" with "define".
* you defined "ButtonPlus" (this was not my question)
* you use "ButtonPlus" else where (Not my question)
* you used "PORTCbits" it in your C code (to define ButtomPlus). (not my question)
* but you never showed where "PORTCbits" is defined. This is what I was asking for

Klaus
 

Hi


Respectfully .. but you are wrong. I guess you mix "use" with "define".
* you defined "ButtonPlus" (this was not my question)
* you use "ButtonPlus" else where (Not my question)
* you used "PORTCbits" it in your C code (to define ButtomPlus). (not my question)
* but you never showed where "PORTCbits" is defined. This is what I was asking for

Klaus
Hi Klaus
i misread my bad sorry. Is in user.c. I enclose you the file to take a look. If you have something to add please do i will be grateful to learn one more thing.
 

Attachments

  • user.rar
    1 KB · Views: 90

Hi,

the attached files does not contain "PORTCbits" at all.

I expect something like
... PORTCbits = xxxx
or
#define PORTCbits xxxx

... thus it´s still unclear where PORTCbits is defined.

***
But I don´t want to spend more time on it.

Klaus
 
You should add all these general port defines into a unique header file ( e.g: port.h ) and include it everywhere.
But all the port.h file content should be enclosed within a structure like this:

Code:
#ifndef PORT_H
#define PORT_H
// Port definitions here
#endif
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top