MPLAB and PIC16F877A error

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
OK that is what I suggested. Does it compile? Looks like it did. Now add your lcd.c file to the project. Compile again.
Thanks a lot

I did the mistake I was not including lcd. file in project

Now it's working fine I can see text on LCD

code
Code:
#define _XTAL_FREQ 8000000



// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7

#include <xc.h>
#include "lcd.h";
void main(void)
{
    unsigned int a;
    TRISD = 0x00;
    Lcd_Init();
    while(1)
    {
        Lcd_Clear();
        Lcd_Set_Cursor(1,1);
        Lcd_Write_String("LCD Library for");
        Lcd_Set_Cursor(2,1);
        Lcd_Write_String("MPLAB XC8");
        __delay_ms(2000);
        Lcd_Clear();
        Lcd_Set_Cursor(1,1);
        Lcd_Write_String("Developed By");
        Lcd_Set_Cursor(2,1);
        Lcd_Write_String("electroSome");
        __delay_ms(2000);
        Lcd_Clear();
        Lcd_Set_Cursor(1,1);
        Lcd_Write_String("www.electroSome.com");

        for(a=0;a<15;a++)
        {
            __delay_ms(300);
            Lcd_Shift_Left();
        }

        for(a=0;a<15;a++)
        {
            __delay_ms(300);
            Lcd_Shift_Right();
        }

        Lcd_Clear();
        Lcd_Set_Cursor(2,1);
        Lcd_Write_Char('e');
        Lcd_Write_Char('S');
        __delay_ms(2000);
    }
   
}
 

spinnaker

Joined Oct 29, 2009
7,830
Not sure how that fixed it. You should have gotten link errors not compile errors. Must have been something else you uncovered by taking a step at a time

So you do have a C file and an H (include file) for lcd? LCD.C and LCD.H?
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
Not sure how that fixed it. You should have gotten link errors not compile errors. Must have been something else you uncovered by taking a step at a time

So you do have a C file and an H (include file) for lcd? LCD.C and LCD.H?
see here
upload_2019-3-9_21-12-39.png

I wasn't adding this file lcd.h in the project before
 

spinnaker

Joined Oct 29, 2009
7,830
You should not need to do that if you have the #include directive in your code. That is only there to make it easy to access the file.

I really think you had another issue somewhere. I have seen strange problems with editors (don't remember if happened in MPLab) but it seems like they hold on to hidden characters. Sometimes copying,deleting and pasting fixes it. Sometime you have to retype the line or paste it to another editor first.
 

Ian Rogers

Joined Dec 12, 2012
1,136
I have never, ever included source code (other than definitions that is) in a header file. Bad practice IMHO.
Totally agree.. However! He downloaded the project from the web, so someone does.. Operationally, no problem with H files having code... Inline code is normally done that way.. But as you say, I normally don't do it unless the IDE will not allow multiple C files..
 

spinnaker

Joined Oct 29, 2009
7,830
Totally agree.. However! He downloaded the project from the web, so someone does.. Operationally, no problem with H files having code... Inline code is normally done that way.. But as you say, I normally don't do it unless the IDE will not allow multiple C files..

So I take my previous statement back. I have put code in the header fine but only when the compiler had the inline keyword. Trying to recall if I have done it in C++ but it has been so long since I have touched C++ it is hard to remember for sure.
 
Top