16F18877 and 4 LCD Compile error

Thread Starter

FroceMaster

Joined Jan 28, 2012
531
Hi
Have this setup, 4 LCD connected to one 16f18877
All 4 data D4+D5+D6+D7 er connected together,
All RS is together,
Each EN is on seperate PIN on MCU

First run, is to get life on the LCD.
Here is my code. for Main
Code:
#include    "lcd4.c"
#include    "lcd1.h"
#include    "lcd2.h"
#include    "lcd3.h"
#include    "lcd4.h"

#pragma config FEXTOSC=XT
#pragma config RSTOSC=EXT1X
#pragma config CLKOUTEN=OFF
#pragma config CSWEN=ON
#pragma config FCMEN=ON
#pragma config MCLRE=ON
#pragma config PWRTE=OFF
#pragma config LPBOREN=OFF
#pragma config BOREN=ON
#pragma config BORV=LO
#pragma config ZCD=OFF
#pragma config PPS1WAY=ON
#pragma config STVREN=ON
#pragma config WDTCPS=WDTCPS_31
#pragma config WDTE=ON
#pragma config WDTCWS=WDTCWS_7
#pragma config WDTCCS=SC
#pragma config WRT=OFF
#pragma config SCANE=available
#pragma config LVP=ON
#pragma config CP=OFF
#pragma config CPD=OFF

#define _XTAL_FREQ 16000000
#define FOSC 16000000L

         void setup(void)
{    
TRISA=1; //set all port in
TRISB=1; // ALLE B = IN
TRISB0=0; // port b0 = ud
TRISB3=0; // PORT B3 = UD
TRISC=1; // ALLE C = IN
TRISD=0; // ALLE D = UD
TRISE1=0; // E0 = UD
ANSELA=0; // set alle digital.
ANSELB=0;
ANSELC=0;
ANSELD=0;
ANSELE=0;
lcd4_init();
lcd4_goto(0);
}
void main (void)
{
     setup();
     lcd4_clear();
     lcd4_goto(0x00);
     lcd4_puts("Det er en test");
     while (1)
     {
     }
}
And here for lcd4.c
Code:
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 16000000
#endif


#include    <htc.h>
#include    "lcd1.h"
#include    "lcd2.h"
#include    "lcd3.h"
#include    "lcd4.h"

#define    LCD_RS RB3
#define LCD1_EN RD7
#define LCD_D4 RD0    // Data bits
#define LCD_D5 RD1    // Data bits
#define LCD_D6 RD2    // Data bits
#define LCD_D7 RD3    // Data bits

#define LCD2_EN RD6

#define LCD3_EN RD5

#define LCD4_EN RD4

#define    LCD1_STROBE()    ((LCD1_EN = 1),(LCD1_EN=0))
#define    LCD2_STROBE()    ((LCD2_EN = 1),(LCD2_EN=0))
#define    LCD3_STROBE()    ((LCD3_EN = 1),(LCD3_EN=0))
#define    LCD4_STROBE()    ((LCD4_EN = 1),(LCD4_EN=0))



/* write a byte to the LCD in 4 bit mode */

void
lcd1_write(unsigned char c)
{   static unsigned char temp;
     temp=c;
    __delay_us(320);
   
    if(c & 0x80) LCD_D7=1; else LCD_D7=0;
    if(c & 0x40) LCD_D6=1; else LCD_D6=0;
    if(c & 0x20) LCD_D5=1; else LCD_D5=0;
    if(c & 0x10) LCD_D4=1; else LCD_D4=0;
    LCD1_STROBE();
    if(c & 0x08) LCD_D7=1; else LCD_D7=0;
    if(c & 0x04) LCD_D6=1; else LCD_D6=0;
    if(c & 0x02) LCD_D5=1; else LCD_D5=0;
    if(c & 0x01) LCD_D4=1; else LCD_D4=0;

    LCD1_STROBE();
}

void
lcd2_write(unsigned char c)
{   static unsigned char temp;
     temp=c;
    __delay_us(320);
   
    if(c & 0x80) LCD_D7=1; else LCD_D7=0;
    if(c & 0x40) LCD_D6=1; else LCD_D6=0;
    if(c & 0x20) LCD_D5=1; else LCD_D5=0;
    if(c & 0x10) LCD_D4=1; else LCD_D4=0;
    LCD2_STROBE();
    if(c & 0x08) LCD_D7=1; else LCD_D7=0;
    if(c & 0x04) LCD_D6=1; else LCD_D6=0;
    if(c & 0x02) LCD_D5=1; else LCD_D5=0;
    if(c & 0x01) LCD_D4=1; else LCD_D4=0;

    LCD2_STROBE();
}

void
lcd3_write(unsigned char c)
{   static unsigned char temp;
     temp=c;
    __delay_us(320);
   
    if(c & 0x80) LCD_D7=1; else LCD_D7=0;
    if(c & 0x40) LCD_D6=1; else LCD_D6=0;
    if(c & 0x20) LCD_D5=1; else LCD_D5=0;
    if(c & 0x10) LCD_D4=1; else LCD_D4=0;
    LCD3_STROBE();
    if(c & 0x08) LCD_D7=1; else LCD_D7=0;
    if(c & 0x04) LCD_D6=1; else LCD_D6=0;
    if(c & 0x02) LCD_D5=1; else LCD_D5=0;
    if(c & 0x01) LCD_D4=1; else LCD_D4=0;

    LCD3_STROBE();
}

void
lcd4_write(unsigned char c)
{   static unsigned char temp;
     temp=c;
    __delay_us(320);
   
    if(c & 0x80) LCD_D7=1; else LCD_D7=0;
    if(c & 0x40) LCD_D6=1; else LCD_D6=0;
    if(c & 0x20) LCD_D5=1; else LCD_D5=0;
    if(c & 0x10) LCD_D4=1; else LCD_D4=0;
    LCD4_STROBE();
    if(c & 0x08) LCD_D7=1; else LCD_D7=0;
    if(c & 0x04) LCD_D6=1; else LCD_D6=0;
    if(c & 0x02) LCD_D5=1; else LCD_D5=0;
    if(c & 0x01) LCD_D4=1; else LCD_D4=0;

    LCD4_STROBE();
}

/*
*     Clear and home the LCD
*/

void
lcd1_clear(void)
{
    LCD_RS = 0;
    lcd1_write(0x1);
    __delay_ms(16);
}
void
lcd2_clear(void)
{
    LCD_RS = 0;
    lcd2_write(0x1);
    __delay_ms(16);
}
void
lcd3_clear(void)
{
    LCD_RS = 0;
    lcd3_write(0x1);
    __delay_ms(16);
}
void
lcd4_clear(void)
{
    LCD_RS = 0;
    lcd4_write(0x1);
    __delay_ms(16);
}

/* write a string of chars to the LCD */

void
lcd1_puts(const char * s)
{
    LCD_RS = 1;    // write characters
    while(*s)
        lcd1_write(*s++);
}

void
lcd2_puts(const char * s)
{
    LCD_RS = 1;    // write characters
    while(*s)
        lcd2_write(*s++);
}
void
lcd3_puts(const char * s)
{
    LCD_RS = 1;    // write characters
    while(*s)
        lcd3_write(*s++);
}
void
lcd4_puts(const char * s)
{
    LCD_RS = 1;    // write characters
    while(*s)
        lcd4_write(*s++);
}
/* write one character to the LCD */

void
lcd1_putch(char c)
{
    LCD_RS = 1;    // write characters
    lcd1_write( c );
}

void
lcd2_putch(char c)
{
    LCD_RS = 1;    // write characters
    lcd2_write( c );
}

void
lcd3_putch(char c)
{
    LCD_RS = 1;    // write characters
    lcd3_write( c );
}

void
lcd4_putch(char c)
{
    LCD_RS = 1;    // write characters
    lcd4_write( c );
}


/*
* Go to the specified position
*/

void
lcd1_goto(unsigned char pos)
{
    LCD_RS = 0;
    lcd1_write(0x80+pos);
}
    void
lcd2_goto(unsigned char pos)
{
    LCD_RS = 0;
    lcd2_write(0x80+pos);
}void
lcd3_goto(unsigned char pos)
{
    LCD_RS = 0;
    lcd3_write(0x80+pos);
}void
lcd4_goto(unsigned char pos)
{
    LCD_RS = 0;
    lcd4_write(0x80+pos);
}
/* initialise the LCD - put into 4 bit mode */
void
lcd1_init()
{
       
//NY RUTINE       
        LCD_RS = 0;    // write control bytes

__delay_ms(280);// power on delay

    LCD_D4 = 1;    // init!   
    LCD_D5 = 1; //
    LCD1_STROBE();   
    __delay_ms(40);

    LCD1_STROBE();    // init!   
    __delay_us(800);

    LCD1_STROBE();    // init!   
    __delay_us(40);

    LCD_D4 = 0;    // set 4 bit mode
    LCD1_STROBE();   
    __delay_us(320);
   
    lcd1_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
    lcd1_write(0x0C);// display on
    lcd1_write(0x06);// entry mode advance cursor
    lcd1_write(0x01);// clear display and reset cursor

}
void
lcd2_init()
{
       
//NY RUTINE       
        LCD_RS = 0;    // write control bytes

__delay_ms(280);// power on delay

    LCD_D4 = 1;    // init!   
    LCD_D5 = 1; //
    LCD2_STROBE();   
    __delay_ms(40);

    LCD2_STROBE();    // init!   
    __delay_us(800);

    LCD2_STROBE();    // init!   
    __delay_us(40);

    LCD_D4 = 0;    // set 4 bit mode
    LCD2_STROBE();   
    __delay_us(320);
   
    lcd2_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
    lcd2_write(0x0C);// display on
    lcd2_write(0x06);// entry mode advance cursor
    lcd2_write(0x01);// clear display and reset cursor

}
void
lcd3_init()
{
       
//NY RUTINE       
        LCD_RS = 0;    // write control bytes

__delay_ms(280);// power on delay

    LCD_D4 = 1;    // init!   
    LCD_D5 = 1; //
    LCD3_STROBE();   
    __delay_ms(40);

    LCD3_STROBE();    // init!   
    __delay_us(800);

    LCD3_STROBE();    // init!   
    __delay_us(40);

    LCD_D4 = 0;    // set 4 bit mode
    LCD3_STROBE();   
    __delay_us(320);
   
    lcd3_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
    lcd3_write(0x0C);// display on
    lcd3_write(0x06);// entry mode advance cursor
    lcd3_write(0x01);// clear display and reset cursor

}
void
lcd4_init()
{
       
//NY RUTINE       
        LCD_RS = 0;    // write control bytes

__delay_ms(280);// power on delay

    LCD_D4 = 1;    // init!   
    LCD_D5 = 1; //
    LCD4_STROBE();   
    __delay_ms(40);

    LCD4_STROBE();    // init!   
    __delay_us(800);

    LCD4_STROBE();    // init!   
    __delay_us(40);

    LCD_D4 = 0;    // set 4 bit mode
    LCD4_STROBE();   
    __delay_us(320);
   
    lcd4_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
    lcd4_write(0x0C);// display on
    lcd4_write(0x06);// entry mode advance cursor
    lcd4_write(0x01);// clear display and reset cursor

}
And finaly for Header file.
Code:
/*
*    LCD interface header file
*    See lcd.c for more info
*/

/* write a byte to the LCD in 4 bit mode */

extern void lcd1_write(unsigned char);

/* Clear and home the LCD */

extern void lcd1_clear(void);

/* write a string of characters to the LCD */

extern void lcd1_puts(const char * s);

/* Go to the specified position */

extern void lcd1_goto(unsigned char pos);
   
/* intialize the LCD - call before anything else */

extern void lcd1_init(void);

extern void lcd1_putch(char);

/*    Set the cursor position */

#define    lcd1_cursor(x)    lcd1_write(((x)&0x7F)|0x80)
have 3 header files more, lcd2.h ect.
All lcd1_clear ect is corrected to lcd2_clear ect in all files.
Hope this makes sence..

Here is the error on compiling.
Code:
:: warning: (1273) Omniscient Code Generation not available in Free mode
lcd4.c:38: error: (237) function "_lcd1_write" redefined
lcd4.c:57: error: (237) function "_lcd2_write" redefined
lcd4.c:76: error: (237) function "_lcd3_write" redefined
lcd4.c:95: error: (237) function "_lcd4_write" redefined
lcd4.c:118: error: (237) function "_lcd1_clear" redefined
lcd4.c:125: error: (237) function "_lcd2_clear" redefined
lcd4.c:132: error: (237) function "_lcd3_clear" redefined
lcd4.c:139: error: (237) function "_lcd4_clear" redefined
lcd4.c:149: error: (237) function "_lcd1_puts" redefined
lcd4.c:157: error: (237) function "_lcd2_puts" redefined
lcd4.c:164: advisory: (1) too many errors (11)
(908) exit status = 1
 

JohnInTX

Joined Jun 26, 2012
3,798
What Error 237 means is that there is more than one definition for the named function i.e. lcd1_write in the code. It looks like you have lots of copy/paste going to replicate the code for each of the 4 LCD modules so I'd do a search on each name to make sure it only appears in one form, including the function prototype.

Just curious, why do you declare the function type on the line before the name and param list e.g.
void
lcd2_write(unsigned char c)


instead of the conventional
void lcd2_write(unsigned char c)
 
Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
531
the code has been working for 1 lcd . before i added lcd1 lcd2 ect.
Have started first to update mplab x to newest version , due to new MCU

Have checked code over but cant find error.
have changed the void line but not the error
 

JohnInTX

Joined Jun 26, 2012
3,798
the code has been working for 1 lcd . before i added lcd1 lcd2 ect.
Have started first to update mplab x to newest version , due to new MCU

Have checked code over but cant find error.
have changed the void line but not the error
That's what might be the problem, if you replicated the code for the other LCDs, it would be easy to overlook updating the LCD number in the function name. Do a CTRL-SHIFT-F global search for one of the function prototypes listed in the error. You should get hits for only one instance of the function. Multiple instances of the prototype are OK if the declarations are all identical.
Updating MPLABX/XC8 is a good idea but it probably won't fix this.
Having 'void' on the previous line seems OK with XC8 (I tried it) but traditional C says to have it all on one line - easier to read and harder to make mistakes. Easy to read is important when debugging..

An observation: you are replicating lots of code that is identical except for the E line. Personally, I would have only one set of routines to do the data, R/S select etc. and a selector for which LCD to use. Have 2 functions setE, and clearE that inspect the selector and output to the selected E line. Then all you have to do is select the LCD then call the routines as if you only had one LCD. Easy. You can use a switch statement to select the E line:

unsigned char activeLCD;

void setE(void)
{
switch(activeLCD){
case 1: E1 = 1; break;
case 2; E2 = 1; break;
.. and so on..
}
}

Then:
active_LCD=1;
lcd_write("LCD1"); // write string to selected LCD
active_LCD=2;
lcd_write("LCD2"); // write string to selected LCD

That sort of thing... You only have to write and debug one set of routines. Nice.

Good luck!
 
Last edited:

jayanthd

Joined Jul 4, 2015
902
Here is the code which I made. You need Proteus to simulate it. If you use Proteus then replace the White On Blue Lcd models with Black On Green Lcd models of Proteus else you will get error.

Code:
/* Main.c file generated by New Project wizard
*
* Created:   Mon Dec 18 2017
* Processor: PIC16F877A
* Compiler:  MPLAB XC8
*/

#define _XTAL_FREQ 4000000
#include <xc.h>
#pragma config WDTE = OFF, LVP = OFF, CP = OFF, CPD = OFF, WRT = OFF ,DEBUG = OFF

#define _LCD_FIRST_ROW                   0x80             //Move cursor to the 1st row
#define _LCD_SECOND_ROW              0xC0         //Move cursor to the 2nd row
#define _LCD_THIRD_ROW                    0x94             //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW              0xD4         //Move cursor to the 4th row
#define _LCD_CLEAR                           0x01                 //Clear display
#define _LCD_RETURN_HOME             0x02         //Return cursor to home position, returns a
                                                                        //shifted display to its original position.
                                                                        //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF              0x0C         //Turn off cursor
#define _LCD_UNDERLINE_ON            0x0E         //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT  0x10     //Move cursor left without changing
                                                                            //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing
                                                                            //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing
                                                                //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing
                                                                    //display data RAM

#define EN_DELAY 50
#define LCD_STROBE1 {LCD_EN1 = 1; __delay_us(EN_DELAY); LCD_EN1 = 0; __delay_us(EN_DELAY);};
#define LCD_STROBE2 {LCD_EN2 = 1; __delay_us(EN_DELAY); LCD_EN2 = 0; __delay_us(EN_DELAY);};
#define LCD_STROBE3 {LCD_EN3 = 1; __delay_us(EN_DELAY); LCD_EN3 = 0; __delay_us(EN_DELAY);};
#define LCD_STROBE4 {LCD_EN4 = 1; __delay_us(EN_DELAY); LCD_EN4 = 0; __delay_us(EN_DELAY);};

#define LCD_RS   PORTBbits.RB0
#define LCD_EN1 PORTDbits.RD0
#define LCD_EN2 PORTDbits.RD1
#define LCD_EN3 PORTDbits.RD2
#define LCD_EN4 PORTDbits.RD3
#define LCD_D4   PORTBbits.RB1
#define LCD_D5   PORTBbits.RB2
#define LCD_D6   PORTBbits.RB3
#define LCD_D7   PORTBbits.RB4

#define LCD_RS_Direction   TRISBbits.TRISB0
#define LCD_EN1_Direction TRISDbits.TRISD0
#define LCD_EN2_Direction TRISDbits.TRISD1
#define LCD_EN3_Direction TRISDbits.TRISD2
#define LCD_EN4_Direction TRISDbits.TRISD3
#define LCD_D4_Direction   TRISBbits.TRISB1
#define LCD_D5_Direction   TRISBbits.TRISB2
#define LCD_D6_Direction   TRISBbits.TRISB3
#define LCD_D7_Direction   TRISBbits.TRISB4

const char msg1[] = "LCD 20X4";
const char msg2[] = "LCD1";
const char msg3[] = "LCD2";
const char msg4[] = "LCD3";
const char msg5[] = "LCD4";
const char msg6[] = "PIC16F877A";
const char msg7[] = "Working For You ?";

char msg[23];

char *CopyConst2Ram(char * dest, const char *src) {
    char *d;

    d = dest;

    for(;*dest++ = *src++;);

    return d;
}

void LCD_Cmd(char lcdNo, char out_char) {

    LCD_RS = 0;

    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };

    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };

    if(out_char == 0x01)__delay_ms(2);
}

void LCD_Chr(char lcdNo, char row, char column, char out_char) {

    switch(row){

        case 1:
        LCD_Cmd(lcdNo, 0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(lcdNo, 0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(lcdNo, 0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(lcdNo, 0xD4 + (column - 1));
        break;
    }

    LCD_RS = 1;

    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };


    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };
}

void LCD_Chr_Cp(char lcdNo, char out_char) {

    LCD_RS = 1;

    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };

    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;

    switch(lcdNo) {
        case 0:
                LCD_STROBE1
                break;
        case 1:
                LCD_STROBE2
                break;
        case 2:
                LCD_STROBE3
                break;
        case 3:
                LCD_STROBE4
                break;
    };
}

void LCD_Init() {

    __delay_ms(200);

    LCD_RS_Direction = 0;
    LCD_EN1_Direction = 0;
    LCD_EN2_Direction = 0;
    LCD_EN3_Direction = 0;
    LCD_EN4_Direction = 0;
    LCD_D4_Direction = 0;
    LCD_D5_Direction = 0;
    LCD_D6_Direction = 0;
    LCD_D7_Direction = 0;

    LCD_RS = 0;
    LCD_EN1 = 0;
    LCD_EN2 = 0;
    LCD_EN3 = 0;
    LCD_EN4 = 0;
    LCD_D4 = 0;
    LCD_D5 = 0;
    LCD_D6 = 0;
    LCD_D7 = 0;

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_STROBE1
    LCD_STROBE2
    LCD_STROBE3
    LCD_STROBE4

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_STROBE1
    LCD_STROBE2
    LCD_STROBE3
    LCD_STROBE4

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_STROBE1
    LCD_STROBE2
    LCD_STROBE3
    LCD_STROBE4

    __delay_ms(30);

    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_STROBE1
    LCD_STROBE2
    LCD_STROBE3
    LCD_STROBE4

    __delay_ms(30);

    LCD_Cmd(0, 0x28);
    LCD_Cmd(0, 0x06);

    LCD_Cmd(1, 0x28);
    LCD_Cmd(1, 0x06);

    LCD_Cmd(2, 0x28);
    LCD_Cmd(2, 0x06);

    LCD_Cmd(3, 0x28);
    LCD_Cmd(3, 0x06);
}

void LCD_Out(char lcdNo, char row, char col, char *text) {
    while(*text)
         LCD_Chr(lcdNo, row, col++, *text++);
}

void LCD_Out_Cp(char lcdNo, char *text) {
    while(*text)
         LCD_Chr_Cp(lcdNo, *text++);
}

void main() {

    CMCON = 0x07;
    ADCON1 = 0x8F;

    TRISA = 0x00;
    TRISB = 0x00;
    TRISC = 0x00;
    TRISD = 0x00;
    TRISE = 0x00;

    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;

    LCD_Init();

    LCD_Cmd(0, _LCD_CURSOR_OFF);
    LCD_Cmd(1, _LCD_CURSOR_OFF);
    LCD_Cmd(2, _LCD_CURSOR_OFF);
    LCD_Cmd(3, _LCD_CURSOR_OFF);

    LCD_Cmd(0, _LCD_CLEAR);
    LCD_Cmd(1, _LCD_CLEAR);
    LCD_Cmd(2, _LCD_CLEAR);
    LCD_Cmd(3, _LCD_CLEAR);

    LCD_Out(0,1,1,CopyConst2Ram(msg,msg1));
    LCD_Out(1,1,1,CopyConst2Ram(msg,msg1));
    LCD_Out(2,1,1,CopyConst2Ram(msg,msg1));
    LCD_Out(3,1,1,CopyConst2Ram(msg,msg1));

    LCD_Out(0,2,1,CopyConst2Ram(msg,msg2));
    LCD_Out(1,2,1,CopyConst2Ram(msg,msg3));
    LCD_Out(2,2,1,CopyConst2Ram(msg,msg4));
    LCD_Out(3,2,1,CopyConst2Ram(msg,msg5));
   
    LCD_Out(0,3,1,CopyConst2Ram(msg,msg6));
    LCD_Out(1,3,1,CopyConst2Ram(msg,msg6));
    LCD_Out(2,3,1,CopyConst2Ram(msg,msg6));
    LCD_Out(3,3,1,CopyConst2Ram(msg,msg6));
   
    LCD_Out(0,4,1,CopyConst2Ram(msg,msg7));
    LCD_Out(1,4,1,CopyConst2Ram(msg,msg7));
    LCD_Out(2,4,1,CopyConst2Ram(msg,msg7));
    LCD_Out(3,4,1,CopyConst2Ram(msg,msg7));

    while(1) {

    }
}
 

Attachments

Last edited:

spinnaker

Joined Oct 29, 2009
7,815
the code has been working for 1 lcd . before i added lcd1 lcd2 ect.
Have started first to update mplab x to newest version , due to new MCU

Have checked code over but cant find error.
have changed the void line but not the error

Why do you have 4 include files??? And 4 source files for the LCD? There should be no need for that. I would do it with one set of functions. I would use arguments in the functions to select the various displays. Makes fixing issues with the code far easier. You maintain it in one place.


#include "lcd4.c"
#include "lcd1.h"
#include "lcd2.h"
#include "lcd3.h"
#include "lcd4.h"


Why are you including a C file? That is likely one source of your problem. C files should be listed in the project and not included in the source.

Why are you defining your functions as extern??? There should be no need for that and is likely another source of your problems.


Your header files should be written in such a way that they can't be included more than once.

Something like this.

#ifndef LCD4_H
#define LCD4_H


void lcd1_puts(const char * s);


#endif /* LCD4_H */


I strongly recommend that you read a good article on C programming.
 
Top