Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Header file creating in Keil

Status
Not open for further replies.

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
first create a file header file. these usually do not need any other header file to be added in it, but if you declare any variables that is dependent of any other , then you have to include that header file in the header file you are creating. example

i have pins.h in this header file i use reg51.h as i use variables defined by other header file...
Code:
/*  Header file declaration  */
#include<reg51.h>

/*  SFR declaration          */
sfr lcd=0x90;

/*single bit declaration */
sbit RS=0x90;
sbit EN=0x91;
sbit relay=P3^7;
i have 2nd header file lcd.h here i dont use any header file in my header file...
Code:
void lcd_cmdwrt(unsigned char cmd);
void lcd_datawrt(unsigned char *);
void dat(unsigned char);
void lcd_init();
void delay(unsigned int );
then i write my C file as main.c

Code:
/*  Header file declaration  */
#include<lcd.h>
#include<pins.h>
#include<string.h>

void main()
{
	lcd_init();		   //To initalise the lcd
	while(1) //infinity loop
	{									
			lcd_cmdwrt(0x01);			//clear on lcd
			delay(10);
			
	}	
}
 

thannara123

Advanced Member level 4
Joined
Jan 7, 2010
Messages
1,452
Helped
119
Reputation
238
Reaction score
110
Trophy points
1,353
Location
God's Own country India, India
Activity points
9,388
Sir i didnt get well ,that is .
where do i make it (note pad or in keil or anything ?)
Where it put ?(keils directory )
I want to call my own functions which are written in header file (my own)?
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
write it in keil by opening new file, or type it in notepad but save it as .h file and add it to keil project where all files are added.. and compile it with other files in the project window.......

store all these header files in the same folder where your .C files are stored...
 
  • Like
Reactions: ramina

    ramina

    points: 2
    Helpful Answer Positive Rating

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,455
Helped
14,040
Reputation
28,333
Reaction score
12,691
Trophy points
1,393
Location
Bochum, Germany
Activity points
275,990
Generally, header files are holding the data definitions and function prototypes that shall be shared by multiple source files. As other source files they can be created in any text editor or the Keil IDE's file editor. For simple "flat" projects, they are stored in the project directory. For complex projects with subdirectories, it's your choice.

Why don't you study some example projects?
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,020
Reputation
4,156
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
The header file is just a text file with a .h extension, use any text editor to create it.
You can place it to your project folder or in the include path of your compiler, if you place it in the project folder then you can include it using #include "headername.h" or if it is in the include path #include <headername.h>

Alex
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
delay.h


Code:
void delay(unsigned int );

delay.c
you can write it as delay.c or write the delay.c code in the main program

Code:
#include<delay.h>

void delay(unsigned int sec)
{
 unsigned int i,j;
 
 for(i=0;i<sec;i++)
   for(j=0;j<1500;j++);
}

main.c

Code:
#include<delay.h>
#include<reg51.h>

main()
{
     delay(100);

}
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,020
Reputation
4,156
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
ckshivaram I will use your code to give an example of what I do


delay.h

Code C - [expand]
1
2
3
4
5
6
7
// the #ifndef prevents the file from being included more than once
#ifndef __DELAY_H__   
#define __DELAY_H__
 
void delay(unsigned int );
 
#endif /* __DELAY_H__



delay.c

Code C - [expand]
1
2
3
4
5
6
7
8
9
#include <delay.h>
 
void delay(unsigned int sec)
{
 unsigned int i,j;
 
 for(i=0;i<sec;i++)
   for(j=0;j<1500;j++);
}



then in the main you have to include the delay.h in the main code and add the delay.c to the project files

Code C - [expand]
1
2
3
4
5
6
7
8
#include<delay.h>
#include<reg51.h>
 
main()
{
     delay(100);
 
}



Alex
 

rajivpatnaik

Newbie level 2
Joined
Dec 18, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
10
write it in keil by opening new file, or type it in notepad but save it as .h file and add it to keil project where all files are added.. and compile it with other files in the project window.......

store all these header files in the same folder where your .C files are stored...

The best thing is to simply open a "New" file in keil, Enter the required data(for header file) in the "New" file as advised by as ckshivram. Save as "delay.h" in the same directory. Compile. You will see the delay.h integrated in the Project directory as a file called "delay" without an extension but type as H. Avoid using another editor like notepad and add to keil.....ckshivaram ROCKS!!!!!!!
 

embpic

Advanced Member level 3
Joined
May 29, 2013
Messages
742
Helped
80
Reputation
160
Reaction score
77
Trophy points
1,308
Location
india
Activity points
5,213
in header file you should give all variable declaration, file inclusion, preprocessor, function declaration. and file named as header.h
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top