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.

'xxxx' undeclared (first use in this function)

Status
Not open for further replies.

helmi_mjd

Member level 2
Member level 2
Joined
Feb 20, 2011
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Visit site
Activity points
1,668
Hi!

I have simple c program but i could find the problem. The compiler give me error:

'PORTBbits' undeclared (first use in this function)

Where is my mistake?

1. File: main.c

#include<p30f4013.h>
#include "HardwareProfile.h"

void subroutine1(void);
void subroutine2(void);

int main()
{
LED1 = 0;
}


void subroutine1(void)
{
LED1 = 1;
}


2. File: subroutine.c

#include "HardwareProfile.h"

void subroutine2(void)
{

LED2 = 0;

}

3. File: HardwareProfile.h

#define LED1 PORTBbits.RB1
#define LED2 PORTBbits.RB10
 

See if replacing PORTx with LATx solves the problem.


Code C - [expand]
1
2
#define LED1 LATBbits.LATB1
#define LED2 LATBbits.LAT10

 

It not solve the problem. Instead it gives the error:
error: 'LATBbits' undeclared (first use in this function)
 

You are clearly missing a header file, the one that defines PORTBits. What compiler are you using?

Brian.

Thanks for your reply. I'm using C30 compiler...I think you are right..but i'm not sure which header file should I add since I'm still new to this compiler.
 

I don't use C30 so I'll have to pass the question to other board users. It might be useful to look at other C30 programs to see how they do it. I would guess there is a common header with the missing information in it.

Alternatively, you could make your own, for example changing:
#define LED1 PORTBbits.RB1
into
#define LED1 PORTB,1
(or #define LED1 LATB,1 if that is more appropriate)

Brian.
 

thanks betwixt...i solved the problem by inserting:

#include <p30F4013.h>

in the subroutines.c files.
This is very silly mistake i made. Thanks again for help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top