MPLab Compiling error

Thread Starter

enciklinux

Joined Dec 8, 2021
13
I've been backtracking all the header files and include it all in the mplab so I can successfully build the code

1640163671857.png
This is the error that I got
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/BEU/2. BEU30063 MICROPROCESSOR AND MICROCONTROLLER/LAB SHEET/Mini Project/Proteus project/LCD SIGN BOARD/MPLAB Source File/LCD SIGN BOARD.X'
make -f nbproject/Makefile-default.mk dist/default/production/LCD_SIGN_BOARD.X.production.hex
make[2]: Entering directory 'D:/BEU/2. BEU30063 MICROPROCESSOR AND MICROCONTROLLER/LAB SHEET/Mini Project/Proteus project/LCD SIGN BOARD/MPLAB Source File/LCD SIGN BOARD.X'
"C:\Program Files\Microchip\xc8\v2.32\bin\xc8-cc.exe" -mcpu=16F887 -Wl,-Map=dist/default/production/LCD_SIGN_BOARD.X.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="C:/Program Files/Microchip/MPLABX/v5.50/packs/Microchip/PIC16Fxxx_DFP/1.2.33/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/LCD_SIGN_BOARD.X.production.elf "build/default/production/lcd signboard.p1" LCD_Lib.c
::: advisory: (2049) C99 compliant libraries are currently not available for baseline or mid-range devices, or for enhanced mid-range devices using a reentrant stack; using C90 libraries
LCD_Lib.c:45:3: error: use of undeclared identifier 'LCD_RS'
LCD_RS = RS;
^
LCD_Lib.c:46:3: error: use of undeclared identifier 'LCD_D4'
LCD_D4 = n & 0x01;
^
LCD_Lib.c:47:3: error: use of undeclared identifier 'LCD_D5'
LCD_D5 = (n >> 1) & 0x01;
^
LCD_Lib.c:48:3: error: use of undeclared identifier 'LCD_D6'
LCD_D6 = (n >> 2) & 0x01;
^
LCD_Lib.c:49:3: error: use of undeclared identifier 'LCD_D7'
LCD_D7 = (n >> 3) & 0x01;
^
LCD_Lib.c:52:3: error: use of undeclared identifier 'LCD_EN'
LCD_EN = 0;
^
LCD_Lib.c:53:3: warning: implicit declaration of function '__delay_us' is invalid in C99 [-Wimplicit-function-declaration]
__delay_us(1);
^
LCD_Lib.c:54:3: error: use of undeclared identifier 'LCD_EN'
LCD_EN = 1;
^
LCD_Lib.c:56:3: error: use of undeclared identifier 'LCD_EN'
LCD_EN = 0;
^
LCD_Lib.c:66:5: warning: implicit declaration of function '__delay_ms' is invalid in C99 [-Wimplicit-function-declaration]
__delay_ms(2);
^
LCD_Lib.c:110:3: error: use of undeclared identifier 'LCD_RS'
LCD_RS = 0;
^
LCD_Lib.c:111:3: error: use of undeclared identifier 'LCD_EN'
LCD_EN = 0;
^
LCD_Lib.c:112:3: error: use of undeclared identifier 'LCD_D4'
LCD_D4 = 0;
^
LCD_Lib.c:113:3: error: use of undeclared identifier 'LCD_D5'
LCD_D5 = 0;
^
LCD_Lib.c:114:3: error: use of undeclared identifier 'LCD_D6'
LCD_D6 = 0;
^
LCD_Lib.c:115:3: error: use of undeclared identifier 'LCD_D7'
LCD_D7 = 0;
^
LCD_Lib.c:116:3: error: use of undeclared identifier 'LCD_RS_DIR'
LCD_RS_DIR = 0;
^
LCD_Lib.c:117:3: error: use of undeclared identifier 'LCD_EN_DIR'
LCD_EN_DIR = 0;
^
LCD_Lib.c:118:3: error: use of undeclared identifier 'LCD_D4_DIR'
LCD_D4_DIR = 0;
^
LCD_Lib.c:119:3: error: use of undeclared identifier 'LCD_D5_DIR'
LCD_D5_DIR = 0;
^
LCD_Lib.c:120:3: error: use of undeclared identifier 'LCD_D6_DIR'
LCD_D6_DIR = 0;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:138: recipe for target 'dist/default/production/LCD_SIGN_BOARD.X.production.hex' failed
make[2]: Leaving directory 'D:/BEU/2. BEU30063 MICROPROCESSOR AND MICROCONTROLLER/LAB SHEET/Mini Project/Proteus project/LCD SIGN BOARD/MPLAB Source File/LCD SIGN BOARD.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/BEU/2. BEU30063 MICROPROCESSOR AND MICROCONTROLLER/LAB SHEET/Mini Project/Proteus project/LCD SIGN BOARD/MPLAB Source File/LCD SIGN BOARD.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/LCD_SIGN_BOARD.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)
Its in LCD_Lib.c
 

JohnInTX

Joined Jun 26, 2012
4,671
I suspect that the LCD library needs the various IO lines defined to specify what the connections to the LCD module are. For example
#define LCD_E LATBbits.RB0
or whatever the actual pin is.

The delay function appears to be missing its prototype. Check the manual’s library section for the header file and syntax. C99 is more strict than the C90 standard used in earlier versions.

I’m not at the computer to check in more detail.
Good luck.
 
Last edited:

Thread Starter

enciklinux

Joined Dec 8, 2021
13
I suspect that the LCD library needs the various IO lines defined to specify what the connections to the LCD module are. For example
#define LCD_E LATBbits.RB0
or whatever the actual pin is.

The delay function appears to be missing its prototype. Check the manual’s library section for the header file and syntax. C99 is more strict than the C90 standard used in earlier versions.

I’m not at the computer to check in more detail.
Good luck.
LCD_Lib.c:
/*******************************************************************************
 * LCD_Lib.c                                                                   *
 * MPLAB XC8 compiler LCD driver for LCDs with HD44780 compliant controllers.  *
 * https://simple-circuit.com/                                                 *
 *                                                                             *
 ******************************************************************************/


#pragma warning disable 520

#include <stdint.h>

#define LCD_FIRST_ROW          0x80
#define LCD_SECOND_ROW         0xC0
#define LCD_THIRD_ROW          0x94
#define LCD_FOURTH_ROW         0xD4
#define LCD_CLEAR              0x01
#define LCD_RETURN_HOME        0x02
#define LCD_ENTRY_MODE_SET     0x04
#define LCD_CURSOR_OFF         0x0C
#define LCD_UNDERLINE_ON       0x0E
#define LCD_BLINK_CURSOR_ON    0x0F
#define LCD_MOVE_CURSOR_LEFT   0x10
#define LCD_MOVE_CURSOR_RIGHT  0x14
#define LCD_TURN_ON            0x0C
#define LCD_TURN_OFF           0x08
#define LCD_SHIFT_LEFT         0x18
#define LCD_SHIFT_RIGHT        0x1E

#ifndef LCD_TYPE
   #define LCD_TYPE 2           // 0=5x7, 1=5x10, 2=2 lines
#endif

__bit RS;

void LCD_Write_Nibble(uint8_t n);
void LCD_Cmd(uint8_t Command);
void LCD_Goto(uint8_t col, uint8_t row);
void LCD_PutC(char LCD_Char);
void LCD_Print(char* LCD_Str);
void LCD_Begin();

void LCD_Write_Nibble(uint8_t n)
{
  LCD_RS = RS;
  LCD_D4 = n & 0x01;
  LCD_D5 = (n >> 1) & 0x01;
  LCD_D6 = (n >> 2) & 0x01;
  LCD_D7 = (n >> 3) & 0x01;

  // send enable pulse
  LCD_EN = 0;
  __delay_us(1);
  LCD_EN = 1;
  __delay_us(1);
  LCD_EN = 0;
  __delay_us(100);
}

void LCD_Cmd(uint8_t Command)
{
  RS = 0;
  LCD_Write_Nibble(Command >> 4);
  LCD_Write_Nibble(Command);
  if((Command == LCD_CLEAR) || (Command == LCD_RETURN_HOME))
    __delay_ms(2);
}

void LCD_Goto(uint8_t col, uint8_t row)
{
  switch(row)
  {
    case 2:
      LCD_Cmd(LCD_SECOND_ROW + col - 1);
      break;
    case 3:
      LCD_Cmd(LCD_THIRD_ROW  + col - 1);
      break;
    case 4:
      LCD_Cmd(LCD_FOURTH_ROW + col - 1);
    break;
    default:      // case 1:
      LCD_Cmd(LCD_FIRST_ROW  + col - 1);
  }

}

void LCD_PutC(char LCD_Char)
{
  RS = 1;
  LCD_Write_Nibble(LCD_Char >> 4);
  LCD_Write_Nibble(LCD_Char );
}

void LCD_Print(char* LCD_Str)
{
  uint8_t i = 0;
  RS = 1;
  while(LCD_Str[i] != '\0')
  {
    LCD_Write_Nibble(LCD_Str[i] >> 4);
    LCD_Write_Nibble(LCD_Str[i++] );
  }
}

void LCD_Begin()
{
  RS = 0;

  LCD_RS     = 0;
  LCD_EN     = 0;
  LCD_D4     = 0;
  LCD_D5     = 0;
  LCD_D6     = 0;
  LCD_D7     = 0;
  LCD_RS_DIR = 0;
  LCD_EN_DIR = 0;
  LCD_D4_DIR = 0;
  LCD_D5_DIR = 0;
  LCD_D6_DIR = 0;
  LCD_D7_DIR = 0;

  __delay_ms(40);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(LCD_RETURN_HOME);
  __delay_ms(5);
  LCD_Cmd(0x20 | (LCD_TYPE << 2));
  __delay_ms(50);
  LCD_Cmd(LCD_TURN_ON);
  __delay_ms(50);
  LCD_Cmd(LCD_CLEAR);
  __delay_ms(50);
  LCD_Cmd(LCD_ENTRY_MODE_SET | LCD_RETURN_HOME);
  __delay_ms(50);
}
I copied the LCD_Lib.c from the internet. Assuming all the LCD_Lib.c is the same one for most cases :/
 

Thread Starter

enciklinux

Joined Dec 8, 2021
13
This is the main program
lcd signboard.c:
/*
 * Interfacing PIC16F887 microcontroller with LCD screen
 * C Code for MPLAB XC8 compiler
 * Internal oscillator used @ 8MHz
 * This is a free software with NO WARRANTY
 * https://simple-circuit.com/
*/
 
#pragma config CONFIG1 = 0x2CD4
#pragma config CONFIG2 = 0x0700
 
//LCD module connections
#define LCD_RS       RD0
#define LCD_EN       RD1
#define LCD_D4       RD2
#define LCD_D5       RD3
#define LCD_D6       RD4
#define LCD_D7       RD5
#define LCD_RS_DIR   TRISD0
#define LCD_EN_DIR   TRISD1
#define LCD_D4_DIR   TRISD2
#define LCD_D5_DIR   TRISD3
#define LCD_D6_DIR   TRISD4
#define LCD_D7_DIR   TRISD5
//End LCD module connections
 
 
#include <xc.h>
#define _XTAL_FREQ 8000000
#include <stdio.h>            // for sprintf
#include "LCD_Lib.c"          // include LCD driver source file
 
char i = 0, text[4];
 
void main(void)
{
    OSCCON =  0X70;    // set internal oscillator to 8MHz
 
    LCD_Begin();       // initialize LCD module
 
    LCD_Goto(4, 1);           // go to column 4, row 1
    LCD_Print("MPLAB XC8");
    LCD_Goto(3, 2);           // go to column 3, row 2
    LCD_Print("LCD Example");
 
    __delay_ms(5000);         // wait 5 seconds
 
    LCD_Cmd(LCD_CLEAR);       // clear the whole screen
    LCD_Goto(3, 1);           // go to column 3, row 1
    LCD_Print("Hello world!");
 
    while (1)
    {
      sprintf(text, "%03u", i);
 
      LCD_Goto(7, 2);      // go to column 7, row 2
      LCD_Print(text);
 
      i++;                 // increment i
      __delay_ms(500);     // wait 1/2 second
    }
}
// End of code.
 

JohnInTX

Joined Jun 26, 2012
4,671
Still not at a computer but I am guessing that the LCD code is being compiled as a library before the main code and at that point it has no information about the IO definitions. Try deleting the LCD library from the ’Library’ folder in the Project (Don’t delete the source). Rebuild. You have included the LCD code on main so it should fix the IO errors.

If that works you can put the LCD code in the source folder and add a suitable header file with the IO definitions.
 

djsfantasi

Joined Apr 11, 2010
8,443
I once ran into a somewhat similar issue in the Arduino IDE, where some definitions were being “clobbered” (technical term) by being defined in two libraries. I solved my problem by making a copy of one library and commenting out the conflicting definitions. I then included the modified library in my code in place of the original library.

May not apply. May give you an idea.
 

Thread Starter

enciklinux

Joined Dec 8, 2021
13
Still not at a computer but I am guessing that the LCD code is being compiled as a library before the main code and at that point it has no information about the IO definitions. Try deleting the LCD library from the ’Library’ folder in the Project (Don’t delete the source). Rebuild. You have included the LCD code on main so it should fix the IO errors.

If that works you can put the LCD code in the source folder and add a suitable header file with the IO definitions.
It work for some reason, maybe MPLAB already have the library installed itself. Thank you very much :D
 
Top