Place the function's prototype (needs a ';' at the end of the line) inside lcd.h and the body inside lcd.c. File lcd.c must include lcd.h. All files that desire to call Lcd_Init(), must include lcd.h.arunsharma0731 said:Can anyone tell me how to do this...
Are you saying that each time you call Lcd_Init(), function's code size is added to the whole project? What is this size? What exactly did you tested to come to such a conclusion?arunsharma0731 said:When i call my function Lcd_Init()
The Code size for the whole code is equal to, if have included all the function..
// header file
#ifdef _INCLUDE_F1
void function1(void);
#endif
#ifdef _INCLUDE_F2
void function2(void);
#endif
#ifdef _INCLUDE_F3
void function3(void);
#endif
//and in the c file
#ifdef _INCLUDE_F1
void function1(void) {
};
#endif
#ifdef _INCLUDE_F2
void function2(void){
};
#endif
#ifdef _INCLUDE_F3
void function3(void){
};
#endif
to include any of the functions in your main code you have to define (any of then or all)
#define _INCLUDE_F1
#define _INCLUDE_F2
#define _INCLUDE_F3
and then include the header
Code C - [expand] 1 2 3 4 5 6 7 8 // USE THIS IN THE HEADER #ifndef _SOME_UNIQUE_LIB_IDENTIFIER_ #define _SOME_UNIQUE_LIB_IDENTIFIER_ //write header content here #endif
Modern compilers should normally optimize this even for no optimization level. Even in this way, you could comment out all not used functions inside lcd.h file. If this does not work, comment out their bodies as well, inside lcd.c. That should work for sure.arunsharma0731 said:Then The Code is Suppose 2K
and Obviously it must be less than 2K When i am including only one Functions...
i.e
Lcd_Init(); //Only this functions is included....
Then my Code size must be less than 2K
But in my case it is equal to 2k
Even in this way, you could comment out all not used functions inside lcd.h file. If this does not work, comment out their bodies as well, inside lcd.c. That should work for sure.
#ifndef _SOME_UNIQUE_LIB_IDENTIFIER_ // this means if _SOME_UNIQUE_LIB_IDENTIFIER_ is not defined, the following code will only be executed if this condition is true.
#define _SOME_UNIQUE_LIB_IDENTIFIER_ // then define it
//write header content here
#endif // end condition
Final step - header file protection
The last thing to do before our conversion is complete, is to protect our header files from multiple inclusion. Take the following example. Say that Main and ADC both refer to each other:
Main.h
Code:#include "ADC.h"
ADC.h
Code:#include "Main.h"
What happens when this is compiled? The preprocessor will look at Main.h, then include ADC.h. However, ADC.h includes Main.h, which again includes ADC.h, etc...
To guard against this problem, we can use preprocessor defines. The following code snippet is the basic protection setup:
#ifndef MAIN_H
#define MAIN_H
// Header file contents
#endif
This construct, when applied to each of your header files, will protect against multiple inclusions. As each C file is compiled, the associated header file is included, as well as any other referenced header files (via includes in the C file's header file). As each header is included, a check is performed to see if the header's unique token is already defined, and if so the inclusion halts to prevent recursion. If the token is not already defined, the preprocessor defines it and looks at the remainder of the header file's contents. By giving each header file a different token (typically the header's filename in ALL CAPS, and the period replaced by an underscore), this system will prevent any preprocessor troubles.
arunsharma0731 said:I don;t understand this line....
void Lcd_Init (void);
[B]//[/B]void Lcd_Clear (void);
[B]//[/B]void Lcd_Data (unsigned char x);
[B]//[/B]void Lcd_String (unsigned char string[]);
void Lcd_Init (void)
{
...............
}
[B]/*[/B]
void Lcd_Clear (void);
{
...............
}
void Lcd_Data (unsigned char x);
{
...............
}
void Lcd_String (unsigned char string[]);
{
...............
}
[B]*/[/B]
//This is LCD Header File
#define _XTAL_FREQ 20000000
#define LCD_DATA PORTB
#define RS PORTCbits.RC0
#define RW PORTCbits.RC1
#define EN PORTCbits.RC2
#ifndef __LCD_H
#define __LCD_H
void lcd_data(unsigned char value);
void lcd_data(unsigned char value);
#ifdef _LCD_INIT
void lcd_init(void);
#endif
#ifdef _LCD_CLEAR
void lcd_clear(void);
#endif
#ifdef _LCD_DATA_STRING
void lcd_data_string(unsigned char msg[]);
#endif
#ifdef _LCD_FIRST_ROW
void lcd_first_row(void);
#endif
#ifdef _LCD_SECOND_ROW
void lcd_second_row(void);
#endif
#endif
/*All LCD Functions Definitions*/
#include<htc.h>
#include<string.h>
#include"lcd.h"
void lcd_cmd(unsigned char value)
{
LCD_DATA = value;
RS = 0;
RW = 0;
EN = 1;
__delay_ms(1);
EN = 0;
}
void lcd_data(unsigned char value)
{
LCD_DATA = value;
RS = 1;
RW = 0;
EN = 1;
__delay_ms(1);
EN = 0;
}
#ifdef _LCD_INIT
void lcd_init(unsigned char value)
{
lcd_cmd(0x38);
lcd_cmd(0x0E);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
#endif
#ifdef _LCD_CLEAR
void lcd_clear(void)
{
lcd_cmd(0x01); //Clears The LCD
}
#endif
#ifdef _LCD_DATA_STRING
void lcd_data_string(unsigned char msg[])
{
unsigned int j,len;
len = strlen(msg);
for(j=0;j<len;j++)
{
lcd_data(msg[j]);
}
}
#endif
#ifdef _LCD_FIRST_ROW
void lcd_first_row(void)
{
lcd_cmd(0x80);
}
#endif
#ifdef _LCD_SECOND_ROW
void lcd_second_row(void)
{
lcd_cmd(0xC0);
}
#endif
#include<htc.h>
#include"lcd.h"
#define _LCD_INIT
#define _LCD_CLEAR
#define _LCD_DATA_STRING
#define _LCD_FIRST_ROW
#define _LCD_SECOND_ROW
void main()
{
lcd_init();
__delay_ms(100);
lcd_clear();
while(1);
// lcd_data_string("Arun Sharma");
}
#define _LCD_INIT
#define _LCD_CLEAR
#define _LCD_DATA_STRING
#define _LCD_FIRST_ROW
#define _LCD_SECOND_ROW
//This is LCD Header File
#define _XTAL_FREQ 20000000
[COLOR="#FF0000"]
#define _LCD_INIT
#define _LCD_CLEAR
#define _LCD_DATA_STRING
#define _LCD_FIRST_ROW
#define _LCD_SECOND_ROW
[/COLOR]
#define LCD_DATA PORTB
#define RS PORTCbits.RC0
#define RW PORTCbits.RC1
#define EN PORTCbits.RC2
#ifndef __LCD_H
#define __LCD_H
void lcd_data(unsigned char value);
void lcd_data(unsigned char value);
#ifdef _LCD_INIT
void lcd_init(void);
#endif
#ifdef _LCD_CLEAR
void lcd_clear(void);
#endif
#ifdef _LCD_DATA_STRING
void lcd_data_string(unsigned char msg[]);
#endif
#ifdef _LCD_FIRST_ROW
void lcd_first_row(void);
#endif
#ifdef _LCD_SECOND_ROW
void lcd_second_row(void);
#endif
#endif
#define _LCD_INIT
#define _LCD_CLEAR
#define _LCD_DATA_STRING
#define _LCD_FIRST_ROW
#define _LCD_SECOND_ROW
#include"lcd.h"
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\lcd.p1".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\main_prog.p1".
Clean Warning: File "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.cof" doesn't exist.
Clean Warning: File "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.hex" doesn't exist.
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.sym".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.map".
Clean Warning: File "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.hxl" doesn't exist.
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\startup.lst".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\startup.rlf".
Clean Warning: File "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\doprnt.p1" doesn't exist.
Clean Warning: File "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\doprnt.pre" doesn't exist.
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.obj".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.lst".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.rlf".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.sdb".
Clean: Deleted file "C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd.mcs".
Clean: Done.
Build C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\test_program_lcd for device 16F877A
Using driver C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\lcd.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\main_prog.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Warning [361] C:\Users\SHARMA\Documents\MPLAB_Projects\LCD_Header_File_Test\main_prog.c; 12.1 function declared implicit int
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" -otest_program_lcd.cof -mtest_program_lcd.map --summary=default --output=default lcd.p1 main_prog.p1 --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.81
Copyright (C) 2010 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error [500] ; 0. undefined symbols:
_lcd_init(test_program_lcd.obj) _lcd_clear(test_program_lcd.obj) ___delay_ms(test_program_lcd.obj)
********** Build failed! **********
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?