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.

[SOLVED] what is the procedure for creating a header file in Mplab8xc

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,382
I want to make My-own some header file .what is the procedure to do that ?


Trying to make the following code in .h file ,But saying the the __delay(); function some error .ie unable to resolve identify the .
Code:
#define _XTAL_FREQ 8000000
#define LCDPORT PORTB
#define RS RB2
#define E RB3
//#define LIINE2 lcd_cmd(0xc0)


void latch(void)
{
    E = 1;
    __delay_ms(1);
    E = 0;


}
void lcd_cmd(unsigned char c)   // used to send the command / Instruction to the lcd port
{
RS = 0;    // send a '0' value to select to send command
__delay_ms(1);
LCDPORT = c & 0xf0;  //  send  the command c only 4 bit by masking the lower bit
latch();
__delay_ms(1);
LCDPORT =  (c << 4); // giving the lowerbit  by shifting the 4 bit to left
latch();
}
 void lcd_data(unsigned char c)
 {
 RS =1;    // send 1 to send data
 __delay_ms(1);
LCDPORT = c & 0xf0 | 0x4; //send  the data  only  4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
__delay_ms(1);
latch();


LCDPORT = (c << 4)| 0x4; ; // giving the lower bit  by shifting the 4 bit to left
latch();
}


 void lcd_init()
{
 __delay_ms(20);
    lcd_cmd(0x30);  //as per data sheet
  __delay_ms(20);
    lcd_cmd(0x30);    //as per data sheet
  __delay_ms(4);
    lcd_cmd(0x32);    //as per data sheet
 __delay_ms(4);
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x0c);            // Make cursorinvisible
    lcd_cmd(0x6);            // Set entry Mode(auto increment of cursor)
}


 void string(const char *q)    // used to send single charcter to display the lcd
{
    while (*q) {
        lcd_data(*q++);
    }
}

I triedout include xc.h file but nothing happend ?
 

You can create file, from file->New (of course) and save with .h extension.
Normally .h file don't contain function bodies (although it is not forbidden), but structures and other type definitions, #define statements, function references and variable references.

If you want to move code to other file, move it to a .c file and add it to your project. Linker will do the rest.

In your case, you tried to use a function that the compiler was not aware of. You could #include the necessary headers in your header if you want to write code inside.
 

where can i write the body of the function ?
 

Code:
//main.c

#include "mine.h"
void main(){
       foo();
}
Code:
//foo.c
#include "mine.h"
void foo(void){
 printf("hello world\n");
}
Code:
//mine.h
#include <stdio.h>
void foo(void);
 
But I cant acces the __delay_ms() function foo.c ?:oops:
 

The __delay_ms() is it a function of yours, or a library function?
If it's yours, you should place the declaration in the header .h file:
Code:
void __delay_ms(int n);
or something like that

If it's a library function, you should #include the library .h file in the .c required.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top