'xxxx' undeclared (first use in this function)

Status
Not open for further replies.

helmi_mjd

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)
 

Its better if you Zip and post the complete project files before asking for help.
 

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

Cookies are required to use this site. You must accept them to continue using the site. Learn more…