Problem with LCD 1602
Discussion in "8051 Discussion Forum" started by TsK Jan 8, 2009.
Thu Jan 08 2009, 12:02 am
Hi, members of this site i read the tutorial about LCD interface and the problems reported here, but i can´t solve my problem by myself.
My LCD don´t initialize just the BackLight turns ON
here is a picture of my schematic i did it in mspaint no programs in my work to do a nice job
And here is my code i'll thank if someone get my mistake.
The LCD i'm using is GDM1602 and de data sheet is here:
http://www.akkayaelektronik.com/downloads/GDM1602.pdf
Sorry for the grammar errors i'm brazillian and i'm improving my skills =)
My LCD don´t initialize just the BackLight turns ON
here is a picture of my schematic i did it in mspaint no programs in my work to do a nice job
And here is my code i'll thank if someone get my mistake.
The LCD i'm using is GDM1602 and de data sheet is here:
http://www.akkayaelektronik.com/downloads/GDM1602.pdf
#include <REGX52.H> #define LCD_data P2 #define LCD_rs P1_0 #define LCD_rw P1_1 #define LCD_en P1_2 void LCD_busy(void); void LCD_command(unsigned char var); void LCD_senddata(unsigned char var); void LCD_sendstring(unsigned char *var); void LCD_init(void); void main(void) { unsigned char msg[] ="HELLO WORLD!"; LCD_init(); LCD_command (0x40); // Set CGRAM adress,data is Avaible from uC LCD_command (0x80); // Set CGRAM adress,data is Avaible from uC LCD_sendstring(msg); } void LCD_busy() { unsigned char i,j; for(i=0;i<50;i++) for(j=0;j<255;j++); } void LCD_command(unsigned char var) { LCD_data = var; //Function set: 2 Line, 8-bit, 5x8 dots LCD_rs = 1; //Selected command register LCD_rw = 0; //We are writing in instruction register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command } // Using the above function is really simple // var will carry the command for LCD // e.g. // // LCD_command(0x01); void LCD_sendstring(unsigned char *var) { while(*var) //till string ends LCD_senddata(*var++); //send characters one by one } // Using the above function is really simple // we will pass the string directly to the function // e.g. // // LCD_sendstring("LCD Tutorial"); void LCD_senddata(unsigned char var) { P0 = var; //Function set: 2 Line, 8-bit, 5x7 dots LCD_rs = 1; //Selected data register LCD_rw = 0; //We are writing LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command } // Using the above function is really simple // we will pass the character to display as argument to function // e.g. // // LCD_senddata('A'); void LCD_init(void) { LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x8 dots LCD_rs = 1; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x0F; //Display on, Curson blinking command LCD_rs = 1; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x01; //Clear LCD LCD_rs = 1; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x06; //Entry mode, auto increment with no shift LCD_rs = 1; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_busy(); }
Sorry for the grammar errors i'm brazillian and i'm improving my skills =)
[ Edited Fri Jan 09 2009, 03:54 am ]
Thu Jan 08 2009, 04:15 am
thx ajay, still no sucess, i read people talking about black blocks showed on the initialization of the LCD i don't got this blocks at any momment.
Thu Jan 08 2009, 07:52 am
Have you adjusted the contrast ?
It may be working but just not visible.ExperimenterUK
Yes I did,I tried with 10K/5K/1K resistors and nothing.
I'll buy a new LCD and try again tomorrow i'll report when i get some fresh news
Good night fellows.
Fri Jan 09 2009, 03:53 am
Yes i used as a voltage divider, i solve the problem it wasn´t about the contrast
sashijoseph pointed the major error, and i found others.... like i was selecting the wrong register in the command routine, and in LCD_senddata i seted the wrong port.
I also added to the code a 15ms delay before the inicialization
Well its working now. Thanks for the precious help, the code below is the correct, maybe it will be helpfull for other people.
sashijoseph pointed the major error, and i found others.... like i was selecting the wrong register in the command routine, and in LCD_senddata i seted the wrong port.
I also added to the code a 15ms delay before the inicialization
Well its working now. Thanks for the precious help, the code below is the correct, maybe it will be helpfull for other people.
#include <REGX52.H> #define LCD_data P2 #define LCD_rs P1_0 #define LCD_rw P1_1 #define LCD_en P1_2 void LCD_busy(void); void LCD_poweron(void); void LCD_command(unsigned char var); void LCD_senddata(unsigned char var); void LCD_sendstring(unsigned char *var); void LCD_init(void); void main(void) { unsigned char msg[] ="Learning"; LCD_poweron(); // 15ms delay LCD_init(); LCD_command (0x80); // Set CGRAM adress,data is Avaible from uC LCD_sendstring(msg); while(1); } void LCD_busy() { unsigned char i,j; for(i=0;i<50;i++) for(j=0;j<255;j++); } void LCD_poweron() { unsigned int i; for (i=0;i<22500; i++); } void LCD_command(unsigned char var) { LCD_data = var; //Function set: 2 Line, 8-bit, 5x8 dots LCD_rs = 0; //Selected command register LCD_rw = 0; //We are writing in instruction register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command } void LCD_sendstring(unsigned char *var) { while(*var) //till string ends LCD_senddata(*var++); //send characters one by one } void LCD_senddata(unsigned char var) { P2 = var; //Function set: 2 Line, 8-bit, 5x7 dots LCD_rs = 1; //Selected data register LCD_rw = 0; //We are writing LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command } void LCD_init(void) { LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x8 dots LCD_rs = 0; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x0F; //Display on, Curson blinking command LCD_rs = 0; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x01; //Clear LCD LCD_rs = 0; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command LCD_data = 0x06; //Entry mode, auto increment with no shift LCD_rs = 0; //Selected command register LCD_rw = 0; //We are writing in data register LCD_en = 1; //Enable H-> L LCD_en = 0; //Enable H-> L LCD_busy(); }
[ Edited Fri Jan 09 2009, 04:03 am ]
Powered by e107 Forum System