include header question

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi

Sorry if my question sounds stupid but i can't find an answer anywhere.
I have the winavr installed and i create my projects using AVR studio (4.16).
I usually use header/source library's , for example lcd.h and lcd.c .
I include the header file lcd.h in the start of my source code (.h and .c located in the project folder and i use #include "lcd.h") but when i try to use a function it says "undefined reference".
The only way it works is if i include both files (#include "lcd.h" #include "lcd.c") but I'm sure that this is the wrong way.
I have tried to see examples but unfortunately they were made with winavr (not as a avr studio project) and they use a make file which has the .c sources included from there.
All i see in the avr project configuration options is
include directories, library search path and they don't seem to help.
I have also tried to add the file to source files, external dependencies, other files (to the left folder tree in AVR studio) but nothing works.

Thank you
Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Include the header file (.h file) in your source. Add the .c file to the project (right-click on the folder Source Files and select Add Existing Source File(s).

Read Dean's tutorial on "managing large projects" in the tutorials section: https://www.avrfreaks.net/index.p...
Read my post here: https://www.avrfreaks.net/index.p...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just add "lcd.c" to the "Source files" in your project.
Add "lcd.h" to the Header Files.

Alternatively you can just add the search path to "lcd.h" instead.

However I would personally just copy "lcd.h" to your project directory. Because almost certainly you have a custom "lcd.h" that is specific to your project.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding to what David said: in you "AVR GCC" files pane located on the left in your studio project, is the lcd.h visible under the 'Header Files'? If not then right click on the Headers Files folder and select Add Existing... then browse to the lcd.h and add it.

It is never IMHO good practice to use #include for a .c file.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much, I tried your solution in three projects and it works fine, the two links are great too, thank you JohanEkdahl
I feel embraced because i did the exact same thing in my projects before i ask my question and it was not working, i can't explain it...

I'm coming to gcc from codevision and things were a little easier there but i find that the gcc compiler is faster and the hex file size is smaller.
I already tried simple projects that use ^=1 to invert the output of a pin in a port or the same thing for a port (PORTB^=0xff), gcc is faster about 20% in the frequency measured in that port or pin and when this basic action is faster then almost anything that uses ports will be faster unless a library is worse than the one used in codevision.

I also tried with a spi project that sends 3 spi bytes to a 12bit a/d converter and then passes the result (the last 12 bits)to PORTC and PORTD (mega8) , the result was about 12% more convertions (2MHz spi clock in both), i have used the following spi function

unsigned char spi(unsigned char send_data)
{
	// load the data to be send
	SPDR = send_data;
   
	// Wait for transmission complete
  	while(!(SPSR & (1<<SPIF)));

	// Receive the data from MISO
   	return SPDR;
	   
} 

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another blow struck in the compiler wars!

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are my test results from PORTB^=0xff; simulated in proteus

mega8 clock 8MHz ,

frequency is measured at any PORTB pin

codevision 666666Hz 170 byte
gcc 800000Hz 124 byte

gcc optimization
O0 244byte 363636Hz
O1 128byte 571429Hz
O2 124byte 800000Hz
O3 124byte 800000Hz
Os 124byte 800000Hz (default)

cvavr optimization

speed 170byte 666666Hz
size 170byte 666666Hz (default)

----------------------------------------------

I have also tried with a mega 8 a/d converter with an interrupt and 8 bit result to PORTB, i invert the PORTC bit0 before the new conversion and measure the frequency

cv 4242Hz 248 byte (size and speed optimization have same result)
gcc 4614Hz 202 byte (Os optimization)

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown