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.

Header file creating in Keil

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,576
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,330
Hi experts ,i want to know that how can i create Header file in keil please post step by step. thanks for all replays
 

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);
			
	}	
}
 
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)?
 

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
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?
 
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
 
Sir can you give me an another example
Having delay function
delay()
 
Last edited:

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);

}
 
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
 
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!!!!!!!
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top