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();
}
Crystalfontz LCD Help
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Crystalfontz LCD Help
Hello Ondra
The LCD should work fine with our LCD component in Flowcode, you should not need to add any of your own C code. As long as the clock speed is defined correctly in Flowcode and you are assigning the correct config details then the LCD should be working correctly. Also note that you should connect the upper data nibble when in 4 bit data mode so the first data pin in Flowcode should connect to the fourth data pin on the LCD etc.
When you call the start macro the top bar of characters should go blank like the bottom line. This indicates a correct initialization.
The LCD should work fine with our LCD component in Flowcode, you should not need to add any of your own C code. As long as the clock speed is defined correctly in Flowcode and you are assigning the correct config details then the LCD should be working correctly. Also note that you should connect the upper data nibble when in 4 bit data mode so the first data pin in Flowcode should connect to the fourth data pin on the LCD etc.
When you call the start macro the top bar of characters should go blank like the bottom line. This indicates a correct initialization.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Crystalfontz LCD Help
Thanks Benj for the quick response. I'm hoping to have this up and running by the weekend.
When you say clock speed are you talking about the PIC clock speed? I am using a part number ECS-200-20-4XDN, a 20MHz, that 20000000 in flow code.
When You say config detail, are you talking about the LCD pin connections and the LCD size?
When laying out my PCB board with the intent of using the LCD some time in the future, for convenience I did not connect the pins sequentially Do the pin have to be in order? Will the device not work if I have it connected the way I have it below.
Data1 Port B bit 1 connects to pin 11 on the LCD
Data2 Port B bit 0 connects to pin 12 on the LCD
Data3 Port B bit 3 connects to pin 13 on the LCD
Data4 Port B bit 2 connects to pin 14 on the LCD
When you say clock speed are you talking about the PIC clock speed? I am using a part number ECS-200-20-4XDN, a 20MHz, that 20000000 in flow code.
When You say config detail, are you talking about the LCD pin connections and the LCD size?
When laying out my PCB board with the intent of using the LCD some time in the future, for convenience I did not connect the pins sequentially Do the pin have to be in order? Will the device not work if I have it connected the way I have it below.
Data1 Port B bit 1 connects to pin 11 on the LCD
Data2 Port B bit 0 connects to pin 12 on the LCD
Data3 Port B bit 3 connects to pin 13 on the LCD
Data4 Port B bit 2 connects to pin 14 on the LCD
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Crystalfontz LCD Help
Hello Ondra
One further thing to check is the chip's configuration and that it is setup to work correctly with the crystal. You should be able to do this using an LED and a 1 second flasher program.
I am and ok that looks great.When you say clock speed are you talking about the PIC clock speed? I am using a part number ECS-200-20-4XDN, a 20MHz, that 20000000 in flow code.
Again yes and all your connections look fine. The non sequential connections for the data pins should not make any difference as long as they are connected and assigned correctly in Flowcode.When You say config detail, are you talking about the LCD pin connections and the LCD size?
One further thing to check is the chip's configuration and that it is setup to work correctly with the crystal. You should be able to do this using an LED and a 1 second flasher program.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Crystalfontz LCD Help
Thanks Benj. One of the data pins on the screen connector was not soldered.
Ondra
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Crystalfontz LCD Help
Hi Ondra
Great glad you got it all working correctly now. I hate it when things like that crop up its always quite a journey finding the cause of the problem.
Great glad you got it all working correctly now. I hate it when things like that crop up its always quite a journey finding the cause of the problem.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel