Crystalfontz LCD Help
Posted: Fri Oct 16, 2009 3:06 am
Good day all.
I have a working project to which I want to connect a LCD I purchased from Crystalfontzs. According to the spec sheet the device uses an Industry-standard HD44780 compatible controller. A link to the pdf is: -
http://www.crystalfontz.com/products/20 ... ATMIJP.pdf.
I have the device connected to the B port as follows: -
Data1 Port B bit 1
Data2 Port B bit 0
Data3 Port B bit 3
Data4 Port B bit 2
Rs Port B bit 6
Enable Port B bit 7
Rw is connected to ground
As I said this is an existing program and yes, the program works fine with out the device: The system I am trying to connect it to uses a Pic 18f2680 running a 20mhz.I placed a "start LCD" component macro at the beginning of my program and from what it seems the device is not being initialized. Yes the program runs as normal. The LCD screen does power up. When I increase the contrast Just one line of the 2X20 LCD unit changes. I talked to the tech support at crystal fonts and they told me that when that happens that the device is not being initialized. He sent me the code for initializing the device see below. But since I work in Flowcode I thought I would put this forward to the the experts who, I'm sure, can help me get this device working. Thanks in advance.
Ondra
Initialization code for the CrystalFontz LCD
void CCFAH_WinTestDlg::OnInit4Bit()
{
int
display_type;
display_type=
m_display_type.GetCurSel();
ubyte
i;
ubyte
j;
ubyte
controller;
for(controller=0;
controller<display_codes[display_type].controllers;
controller++)
{
Init_LCD_4(controller);
for(j=0;j<display_codes[display_type].rows;j++)
{
Sleep(2);
Write_LCD_Control_4(display_codes[display_type].line_address[j],controller);
//Get the string
CString
input_string;
char
string[120];
switch(j+(controller*display_codes[display_type].rows))
{
case 0:
m_line_0.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
case 1:
if(display_type==DISPLAY_TYPE_16x1)
{
m_line_0.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
strcpy(string,&string[8]);
}
else
{
m_line_1.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
}
break;
case 2:
m_line_2.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
case 3:
m_line_3.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
}
char
send_string[120];
for(i=0;i<=119;i++)
send_string=' ';
//Copy the data, handling \123 and \\ and counting the characters
int
count;
for(i=0,count=0;string&&(count<display_codes[display_type].cols);i++,count++)
{
if((string=='\\')&&(string[i+1]=='\\'))
{
send_string[count]='\\';
i++;
}
else
{
if((string=='\\')&&(isdigit(string[i+1]))
&&(isdigit(string[i+2]))
&&(isdigit(string[i+3]))
&&(((string[i+1]-'0')*100
+(string[i+2]-'0')*10
+(string[i+3]-'0'))<=255))
{
send_string[count]=
((string[i+1]-'0')*100+(string[i+2]-'0')*10+(string[i+3]-'0'));
i+=3;
}
else
send_string[count]=string;
}
}
for(i=0;i<display_codes[display_type].cols;i++)
{
Sleep(2);
Write_LCD_Data_4(send_string,controller);
}
}
//Initialize the 8 custom characters.Turn the cursor off.
Sleep(2);
Write_LCD_Control_4(0x0C,controller);
//Address the data area for the custom character 0.
Sleep(2);
Write_LCD_Control_4(0x40,controller);
for(j=0;j<=7;j++)
for(i=0;i<=7;i++)
{
Sleep(2);
Write_LCD_Data_4(default_special_characters[j],controller);
}
}
//Idle things.
data_register=0;
Update_Buttons_From_Data_Register();
control_register=0;
Update_Buttons_From_Control_Register();
}
I have a working project to which I want to connect a LCD I purchased from Crystalfontzs. According to the spec sheet the device uses an Industry-standard HD44780 compatible controller. A link to the pdf is: -
http://www.crystalfontz.com/products/20 ... ATMIJP.pdf.
I have the device connected to the B port as follows: -
Data1 Port B bit 1
Data2 Port B bit 0
Data3 Port B bit 3
Data4 Port B bit 2
Rs Port B bit 6
Enable Port B bit 7
Rw is connected to ground
As I said this is an existing program and yes, the program works fine with out the device: The system I am trying to connect it to uses a Pic 18f2680 running a 20mhz.I placed a "start LCD" component macro at the beginning of my program and from what it seems the device is not being initialized. Yes the program runs as normal. The LCD screen does power up. When I increase the contrast Just one line of the 2X20 LCD unit changes. I talked to the tech support at crystal fonts and they told me that when that happens that the device is not being initialized. He sent me the code for initializing the device see below. But since I work in Flowcode I thought I would put this forward to the the experts who, I'm sure, can help me get this device working. Thanks in advance.
Ondra
Initialization code for the CrystalFontz LCD
void CCFAH_WinTestDlg::OnInit4Bit()
{
int
display_type;
display_type=
m_display_type.GetCurSel();
ubyte
i;
ubyte
j;
ubyte
controller;
for(controller=0;
controller<display_codes[display_type].controllers;
controller++)
{
Init_LCD_4(controller);
for(j=0;j<display_codes[display_type].rows;j++)
{
Sleep(2);
Write_LCD_Control_4(display_codes[display_type].line_address[j],controller);
//Get the string
CString
input_string;
char
string[120];
switch(j+(controller*display_codes[display_type].rows))
{
case 0:
m_line_0.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
case 1:
if(display_type==DISPLAY_TYPE_16x1)
{
m_line_0.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
strcpy(string,&string[8]);
}
else
{
m_line_1.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
}
break;
case 2:
m_line_2.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
case 3:
m_line_3.GetWindowText(input_string);
strcpy(string,(LPSTR)(const char *)input_string);
break;
}
char
send_string[120];
for(i=0;i<=119;i++)
send_string=' ';
//Copy the data, handling \123 and \\ and counting the characters
int
count;
for(i=0,count=0;string&&(count<display_codes[display_type].cols);i++,count++)
{
if((string=='\\')&&(string[i+1]=='\\'))
{
send_string[count]='\\';
i++;
}
else
{
if((string=='\\')&&(isdigit(string[i+1]))
&&(isdigit(string[i+2]))
&&(isdigit(string[i+3]))
&&(((string[i+1]-'0')*100
+(string[i+2]-'0')*10
+(string[i+3]-'0'))<=255))
{
send_string[count]=
((string[i+1]-'0')*100+(string[i+2]-'0')*10+(string[i+3]-'0'));
i+=3;
}
else
send_string[count]=string;
}
}
for(i=0;i<display_codes[display_type].cols;i++)
{
Sleep(2);
Write_LCD_Data_4(send_string,controller);
}
}
//Initialize the 8 custom characters.Turn the cursor off.
Sleep(2);
Write_LCD_Control_4(0x0C,controller);
//Address the data area for the custom character 0.
Sleep(2);
Write_LCD_Control_4(0x40,controller);
for(j=0;j<=7;j++)
for(i=0;i<=7;i++)
{
Sleep(2);
Write_LCD_Data_4(default_special_characters[j],controller);
}
}
//Idle things.
data_register=0;
Update_Buttons_From_Data_Register();
control_register=0;
Update_Buttons_From_Control_Register();
}