Hello everyone,
I've got a big problem ( I guess ?) with my LCD 4x20 :
Here's the datasheet :
**broken link removed**
When i send to him my initilisation code , I've got nothing but only two lines of dark squares (line 1 and 3)
My code is actually working on little LCD's displays (16x2) and also on a pic development board.
So I guess there is something wrong with the init routine , but i don't understand a thing about the datasheet, someone told me that with my code I was supposed to make it work , but it seems not.
I'm working with Mplabx 2.10 and my Pic is a 18f4580.
I've checked all my connections and nothing is wrong , my contrast pot is also working well and I want to work on 4bits mode.
So the only problem is and must be the program.
Here's the lcd routine :
Code:
#include <xc.h>
#define LCD_RW LATCbits.LATC5
#define LCD_RS LATCbits.LATC7
#define LCD_E LATCbits.LATC6
#define LCD_D4 LATDbits.LATD3
#define LCD_D5 LATDbits.LATD2
#define LCD_D6 LATDbits.LATD1
#define LCD_D7 LATDbits.LATD0
#define _XTAL_FREQ 8000000
#define LCD_STROBE LCD_E=1; __delay_ms(5); LCD_E=0; __delay_ms(5);
// Ecrire un caract?re au LCD
void lcd_write(unsigned char c)
{
LCD_D7 = (c & 0x80) ? 1 : 0;
LCD_D6 = (c & 0x40) ? 1 : 0;
LCD_D5 = (c & 0x20) ? 1 : 0;
LCD_D4 = (c & 0x10) ? 1 : 0;
LCD_STROBE;
LCD_D7 = (c & 0x08) ? 1 : 0;
LCD_D6 = (c & 0x04) ? 1 : 0;
LCD_D5 = (c & 0x02) ? 1 : 0;
LCD_D4 = (c & 0x01) ? 1 : 0;
LCD_STROBE;
__delay_ms(5);
}
// Initialiser le LCD en mode 4 bits
void lcd_4bits_init(void)
{
LCD_RW = 0;
LCD_RS = 0;
LCD_E = 1;
// __delay_ms(15);
LCD_D4 = 1;
LCD_D5 = 1;
LCD_STROBE;
__delay_ms(1);
LCD_STROBE;
__delay_ms(1);
LCD_STROBE;
__delay_ms(5);
LCD_D4 = 0;
LCD_STROBE;
__delay_ms(1);
lcd_write(0x28); // Mode 4 bits, 2 lignes
lcd_write(0x0C); // Display on, cursor off
lcd_write(0x06); //
lcd_write(0x01); // Clear display
LCD_RS = 1;
}
// Ecrire une cha?ne au LCD
void lcd_puts(const char *s)
{
LCD_RS = 1;
while (*s != '\0')
{
lcd_write(*s++);
}
}
// Positionner le curseur
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write (0x80 + pos);
LCD_RS = 1;
}
// Effacer le display
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write (0x01);
LCD_RS = 1;
}
// Afficher un char en ASCII (d?cimal)
void lcd_ctoa(unsigned char data)
{
unsigned char digit;
digit = 0;
while(data >= 100)
{
data = data - 100;
digit++;
}
LCD_RS = 1;
lcd_write(digit + 0x30);
digit = 0;
while(data >= 10)
{
data = data - 10;
digit++;
}
lcd_write(digit + 0x30);
lcd_write(data + 0x30);
}
// Afficher un int en ASCII (d?cimal)
void lcd_itoa(unsigned int data)
{
unsigned char digit;
digit = 0;
while(data >= 10000)
{
data = data - 10000;
digit++;
}
LCD_RS = 1;
lcd_write(digit + 0x30);
digit = 0;
while(data >= 1000)
{
data = data - 1000;
digit++;
}
LCD_RS = 1;
lcd_write(digit + 0x30);
digit = 0;
while(data >= 100)
{
data = data - 100;
digit++;
}
LCD_RS = 1;
lcd_write(digit + 0x30);
digit = 0;
while(data >= 10)
{
data = data - 10;
digit++;
}
lcd_write(digit + 0x30);
lcd_write(data + 0x30);
}
So if someone need another informations about what i'm using or something else i'll be pleased to help.
Hope you'll find what's wrong because i'm starting to be completely mad.
PS: Sorry for the bad english , i'm not used to write in english
Edit 1 : I also use XC8. Tried to find on other posts or else , some new leads to find a solution , but still no idea working :s