Where to place .h and .c files ?

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

Hello,

i'm simulating a glcd (ks0108 controller) in proteus and programming via AvrStudio 4, everything is working fine but i have one question that i couldn't figure out(googled it without sucess).
Where should I place the ks0108.h and ks0108.c files so that i don't need to declare all the functions I use? I want my code to be just like this one below:

Example Code:

#include 
#include 
#include 

#include "ks0108.h"
#include "arial_bold_14.h"
#include "SC.h"
#include "Bitmap.h"


int main(void) {
	
	// Wait a little while the display starts up
	for(volatile uint16_t i=0; i<15000; i++);
	
	// Initialize the LCD
	ks0108Init(0);
	
	// Select a font
	//ks0108SelectFont(Arial_Bold_14, ks0108ReadFontData, BLACK);
	// Set a position
	//ks0108GotoXY(15,10);
	// Print some text
	//ks0108Puts_P(PSTR("test"));
	// a nice little round rect
	//ks0108DrawRoundRect(5, 5, 117, 20, 8, BLACK);

	// Once again :)
	// Select a font
	//ks0108SelectFont(SC, ks0108ReadFontData, BLACK);
	// Set a position
	//ks0108GotoXY(5,30);
	// Print some text
	//ks0108Puts("test");
   // ks0108DrawLine(0, 0, 100, 50, BLACK);
	//ks0108DrawCircle(50, 40, 20, BLACK);
	ks0108ClearScreen();
	/*LoadBitmap(IMAGE);*/
	while(1);
}

Here is part of my code:


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

...

void ks0108DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color) {
	ks0108DrawHoriLine(x, y, width, color);				// top
	ks0108DrawHoriLine(x, y+height, width, color);		// bottom
	ks0108DrawVertLine(x, y, height, color);			// left
	ks0108DrawVertLine(x+width, y, height, color);		// right
}

void ks0108DrawRoundRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t radius, uint8_t color) {
  	int16_t tSwitch, x1 = 0, y1 = radius;
  	tSwitch = 3 - 2 * radius;
	
	while (x1 <= y1) {
	    ks0108SetDot(x+radius - x1, y+radius - y1, color);
	    ks0108SetDot(x+radius - y1, y+radius - x1, color);

	    ks0108SetDot(x+width-radius + x1, y+radius - y1, color);
	    ks0108SetDot(x+width-radius + y1, y+radius - x1, color);
	    
	    ks0108SetDot(x+width-radius + x1, y+height-radius + y1, color);
	    ks0108SetDot(x+width-radius + y1, y+height-radius + x1, color);

	    ks0108SetDot(x+radius - x1, y+height-radius + y1, color);
	    ks0108SetDot(x+radius - y1, y+height-radius + x1, color);

	    if (tSwitch < 0) {
	    	tSwitch += (4 * x1 + 6);
	    } else {
	    	tSwitch += (4 * (x1 - y1) + 10);
	    	y1--;
	    }
	    x1++;
	}
	  	
	ks0108DrawHoriLine(x+radius, y, width-(2*radius), color);			// top
	ks0108DrawHoriLine(x+radius, y+height, width-(2*radius), color);	// bottom
	ks0108DrawVertLine(x, y+radius, height-(2*radius), color);			// left
	ks0108DrawVertLine(x+width, y+radius, height-(2*radius), color);	// right
}

...

I placed the files in C:\WinAVR-20090313\avr\include\avr, but the compilator refuses to work if i only wirte the function name and don't declare the operations that occur in the function(like in the code above). For example, if i write:

ks0108DrawRect(10, 10, 90, 50, BLACK);

I get an error message saying that ks0108DrawRect wasn't declared.

Please, what i'm doing wrong ? The code i wrote works, but it's giant and messy. I would like to clean it up.

Thanks.

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

you place your own .h and .c files in your projects directory, or in a subdirectory thereof. When you #include, using double quotes tell the compiler to find the file in the current directory (it will then traverse up a search tree of include directories if the files is not found) Using angle brackets, the compiler will search for the file in the system include directories.

For more understanding, try reading Deans excellent tutorial on the subject

https://www.avrfreaks.net/index.p...

Writing code is like having sex.... make one little mistake, and you're supporting it for life.