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
And here for lcd4.c
And finaly for Header file.
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.
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)
{
}
}
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
}
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)
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