MPLAB and PIC16F877A error

Thread Starter

Fanfire174

Joined Mar 13, 2018
209
I am trying to interface lcd 16*2 and I have MPLABx IDE V4.15 (xc8 compiler ) and I have PIC16F877A

I am following link here
https://electrosome.com/lcd-pic-mplab-xc8/
C:
#define _XTAL_FREQ=20000000

#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
// 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)

#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);
    }
}
output
Code:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'E:/3. Embedded System/2. PIC/6. Sample Project/LCD.X'
make  -f nbproject/Makefile-default.mk dist/default/production/LCD.X.production.hex
make[2]: Entering directory 'E:/3. Embedded System/2. PIC/6. Sample Project/LCD.X'
"C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe" --pass1  --chip=16F877A -Q -G  --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/lcd.p1  lcd.c
lcd.h:32: error: (195) expression syntax
lcd.h:32: error: (187) too few function arguments
lcd.h:32: error: (194) ")" expected
lcd.h:32: error: (195) expression syntax
lcd.h:37: warning: (371) missing basic type; int assumed
lcd.h:66: error: (195) expression syntax
lcd.h:66: error: (187) too few function arguments
lcd.h:66: error: (194) ")" expected
lcd.h:66: error: (195) expression syntax
lcd.h:68: error: (195) expression syntax
lcd.h:68: error: (187) too few function arguments
lcd.h:68: error: (194) ")" expected
lcd.h:68: error: (195) expression syntax
lcd.h:70: error: (195) expression syntax
lcd.h:70: error: (187) too few function arguments
lcd.h:70: error: (194) ")" expected
lcd.h:70: error: (195) expression syntax
lcd.h:90: error: (195) expression syntax
lcd.h:90: error: (187) too few function arguments
lcd.h:90: error: (194) ")" expected
lcd.h:90: error: (195) expression syntax
lcd.h:94: error: (195) expression syntax
lcd.h:94: advisory: (1) too many errors (21)
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/lcd.p1' failed
make[2]: Leaving directory 'E:/3. Embedded System/2. PIC/6. Sample Project/LCD.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'E:/3. Embedded System/2. PIC/6. Sample Project/LCD.X'
(908) exit status = 1
make[2]: *** [build/default/production/lcd.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 24s)
How to resoloved problem ?
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
209
Loose the ";" (semi colon...) Then see if it compiles..

You will also need the LCD library... Have you got the LCD.H file??
perhaps missing LCD.H file but I have downloaded full program and I think it should be work
C:
//LCD Functions Developed by electroSome


void Lcd_Port(char a)
{
    if(a & 1)
        D4 = 1;
    else
        D4 = 0;

    if(a & 2)
        D5 = 1;
    else
        D5 = 0;

    if(a & 4)
        D6 = 1;
    else
        D6 = 0;

    if(a & 8)
        D7 = 1;
    else
        D7 = 0;
}
void Lcd_Cmd(char a)
{
    RS = 0;             // => RS = 0
    Lcd_Port(a);
    EN  = 1;             // => E = 1
        __delay_ms(4);
        EN  = 0;             // => E = 0
}

Lcd_Clear()
{
    Lcd_Cmd(0);
    Lcd_Cmd(1);
}

void Lcd_Set_Cursor(char a, char b)
{
    char temp,z,y;
    if(a == 1)
    {
      temp = 0x80 + b - 1;
        z = temp>>4;
        y = temp & 0x0F;
        Lcd_Cmd(z);
        Lcd_Cmd(y);
    }
    else if(a == 2)
    {
        temp = 0xC0 + b - 1;
        z = temp>>4;
        y = temp & 0x0F;
        Lcd_Cmd(z);
        Lcd_Cmd(y);
    }
}

void Lcd_Init()
{
  Lcd_Port(0x00);
   __delay_ms(20);
  Lcd_Cmd(0x03);
    __delay_ms(5);
  Lcd_Cmd(0x03);
    __delay_ms(11);
  Lcd_Cmd(0x03);
  /////////////////////////////////////////////////////
  Lcd_Cmd(0x02);
  Lcd_Cmd(0x02);
  Lcd_Cmd(0x08);
  Lcd_Cmd(0x00);
  Lcd_Cmd(0x0C);
  Lcd_Cmd(0x00);
  Lcd_Cmd(0x06);
}

void Lcd_Write_Char(char a)
{
   char temp,y;
   temp = a&0x0F;
   y = a&0xF0;
   RS = 1;             // => RS = 1
   Lcd_Port(y>>4);             //Data transfer
   EN = 1;
   __delay_us(40);
   EN = 0;
   Lcd_Port(temp);
   EN = 1;
   __delay_us(40);
   EN = 0;
}

void Lcd_Write_String(char *a)
{
    int i;
    for(i=0;a[i]!='\0';i++)
       Lcd_Write_Char(a[i]);
}

void Lcd_Shift_Right()
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x0C);
}

void Lcd_Shift_Left()
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x08);
}
Do you have code without header file lcd.h ?
 

Ian Rogers

Joined Dec 12, 2012
662
It would appear it's not liking the __delay_ms() and __delay_us() in the LCD.H you may need to put #include< XC.h>" in that file as well..
 

spinnaker

Joined Oct 29, 2009
7,815
I am trying it but haven't succeeded yet

Can you help to get sample code without lcd.h file ?
No of course not. You need lcd.h for it to compile properly. What is not working now? what error are you getting? On what line is it occurring?Make sure you post that source code if not already done so.


Edit: You may have misunderstood Ian. When he said "Loose the ";" (semi colon...)" he meant remove it.

Instead of #include "lcd.h"; it should be #include "lcd.h"


But before you try to tackle a project with LCD, I HIGHLY recommend you learn C first.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
209
What is not working now? what error are you getting? On what line is it occurring?Make sure you post that source code if not already done so..
I have posted source code with output error

see the post #1

Edit: You may have misunderstood Ian. When he said "Loose the ";" (semi colon...)" he meant remove it.

Instead of #include "lcd.h"; it should be #include "lcd.h"
already done it but getting the same error


But before you try to tackle a project with LCD, I HIGHLY recommend you learn C first.
I am not an expert in c language but I can manage it
 

spinnaker

Joined Oct 29, 2009
7,815
I have posted source code with output error

see the post #1



already done it but getting the same error




I am not an expert in c language but I can manage it
Obviously you can't manage it or you could figure this out. ;)

Where is the LCD.H file? I am not seeing it. That is where the error is occurring or at least seems to be occurring.

Create a new C project. Create a new C file with nothing in it but your void main() function. Add in the #linclude "lcd.h ". Try compiling and see if you get the same error. Make sure you copy lcd.h to the new directory. If it compiles start adding other files and code a bit at a time.


C can be tricky at times. A mistake in one part of the file or another include file can cause an error in a different location. You need to narrow it down to where the error is actually occurring. One trick is to start eliminating things then adding them back in until you find the error. That is how you "manage" C.
 

spinnaker

Joined Oct 29, 2009
7,815
It would appear it's not liking the __delay_ms() and __delay_us() in the LCD.H you may need to put #include< XC.h>" in that file as well..

No lcd.h file, unless you were brave enough to click on the link and get it.

BTW do what you want but IMHO this is the wrong answer. TS needs to figure out how to solve this on his own (with our help of course).
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
209
Obviously you can't manage it or you could figure this out. ;)

Where is the LCD.H file? I am not seeing it. That is where the error is occurring or at least seems to be occurring.

Create a new C project. Create a new C file with nothing in it but your void main() function. Add in the #linclude "lcd.h ". Try compiling and see if you get the same error. Make sure you copy lcd.h to the new directory. If it compiles start adding other files and code a bit at a time.
.
Look at this screenshot

upload_2019-3-9_16-42-39.png
 

spinnaker

Joined Oct 29, 2009
7,815
If you get an error, stat eliminating things from lcd.c until the error goes away.


I might be out of touch for a while Did not sleep well last night. Need to grab some breakfast and maybe try to get more sleep. ;)
 

spinnaker

Joined Oct 29, 2009
7,815
If you get an error, stat eliminating things from lcd.c until the error goes away.


I might be out of touch for a while Did not sleep well last night. Need to grab some breakfast and maybe try to get more sleep. ;)

If you don't have a lcd.c file and all of the code is indeed in lcd.h (which it should not be in my opinion but might be OK to do it that way.)

then start pasting code into the new project a function at a time until the error occurs.
 

AlbertHall

Joined Jun 4, 2014
8,379
The original files, as downloaded from the link in post #1, do compile for me albeit with two warnings - one for the additional semicolon described earlier and the other for the function in lcd.h, lcd_clear which has no type specifier.
I have attached the complete project files here with the warnings corrected.

I am using MPLAB-X V5.10 and XC8 V2.05.
 

Attachments

Top