Page 1 of 1

Initialization Problems

Posted: Wed Jul 11, 2007 10:34 pm
by kaseldl
Hello, I have been struggling with coding a MOP-AL204A LCD I recently bought. I have read through the HD44780 datasheet, and I believe I have followed the initialization routine specified there, but am not yet getting anything to show up on my screen. I will paste my "main.c" code here:

void main(void)
{

Sys_Init();

while(1)
{

while(!SW1)
{

LED1 = 1;

P1 = 0x30;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(12);

P1 = 0x30;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

P1 = 0x38;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

P1 = 0x08;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

P1 = 0x01;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

P1 = 0x0C;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

P1 = 0x06;
Delay(1);
E = 1;
Delay(6);
E = 0;
Delay(6);

}

while(!SW2)
{

LED2 = 1;

RS = 1;
RW = 0;
Delay(1);

P0 = 0x41;
Delay(1);
E = 1;
Delay(6);
E = 0;

}

LED1 = 0;
LED2 = 0;

P0 = 0x00;

}

}

Note: Delay() corresponds to multiples of 5ms, so Delay(2) is a 10ms delay.

E - Enable chip
RS - Data/Instruction
RW - Read/Write
P0 - DB0 - DB7

Can you see any errors here? I can check lines with an o-scope if it will help, but the checks I have done haven't resulted in anything. Thanks in advance!

Posted: Wed Jul 18, 2007 11:48 am
by Raquel
Dustin had been help via direct technical support.

Posted: Wed May 21, 2008 5:29 pm
by bdony
I am also having initialization problems with an AL204A model LCD, specifically the MOP-AL204A-BGFW-25E-3IN. My initialization code is similar to the OPs, but not exactly the same. Mine consists of fewer instructions, and I can post it if this is the appropriate place.

I am also unclear about the requirement described on page 18 of the data sheet regarding the timing of VDD versus V0. It says that there is a typical delay of 50ms, but I am not sure what exactly the "requirement" is.

Posted: Thu May 22, 2008 10:12 am
by Clark
Hi Brian,

Please feel free to post up that code here, and we'll take a look at it. The VDD versus V0 is probably a pretty good place to start. As I mentioned earlier, the back light with solid blocks of text is something we notice on our serial units when the uC doesn't boot the system quite right.

I will be in contact with Raquel, and see if she can remember what helped last time in the hope that it will provide a little insight for you. Unfortunately, she will be away for some time, so correspondence may be slow, but I'm sure we'll work something out.

~Troy

Posted: Sat May 24, 2008 1:39 pm
by bdony
I'm currently addressing the VDD vs V0 rise time issue - I have the same full blocks of text with a backlight even though my V0 voltage is 0, so does that mean the spec applies to the current flow also? And about how much error is allowed from the typical 50ms delay (IE how low can that number be)?

Here is my init (pseudo)code:

//INIT LCD
delay 40ms
WrPortI( PBDR, NULL, 0x3C ); //function set (0011NFxx)
set RS = 0, R/W~ = 0, E = 1;
set E = 0;
delay 40us;
WrPortI( PBDR, NULL, 0x3C ); //function set (0011NFxx)
set RS = 0, R/W~ = 0, E = 1;
set E = 0;
delay 40us;
WrPortI( PBDR, NULL, 0x0C ); // (00001DCB)
set RS = 0, R/W~ = 0, E = 1;
set E = 0;
delay 40us;
WrPortI( PBDR, NULL, 0x01 ); //clear display
set RS = 0, R/W~ = 0, E = 1;
set E = 0;
delay 2ms;
WrPortI( PBDR, NULL, 0x06 ); //entry mode set (000001 I/D SH)
set RS = 0, R/W~ = 0, E = 1;
set E = 0;


I have observed the 3 control (RS, RW, E) and 8 data signals on a logic analyzer, and the signals behave as described above. All instructions meet the required timing constraints described by the data sheet.

Posted: Mon May 26, 2008 12:38 pm
by Clark
Hi Brian,

I took a look at your code, and all seems well here. Although, looking at your post, something just clicked in my head. I apologize that I didn't see it before, but V0 is rather low.

While pins 1 and 2 are primary power for the logic of the screen, pin 3 controls contrast, which is why you see the a potentiometer in the circuitry diagrams. I scoped out a 20x4 white on blue unit out here, connected to our daughter board, and the middle of the road for contrast was about 0.5 volts. Setting it to the lowest level resulted in an output of about 2.2 volts, and high resulted in 0 volts, and those darkened boxes.

At this point in time, I would worry more about the level of the V0 voltage rather than the timing, although if you can do both, great. From what I remember about doing a project with one of these in college, drawing voltage from a potentiometer, 10k ohms might be a good starting value, connected between pins 1 and 2 should do the trick. You may have to play with it a bit, but you should see a nice contrast somewhere around that 0.5 volt mark.

Let me know how that goes, and if you've got any further questions as you continue development.

Thanks,
Troy

Posted: Mon May 26, 2008 1:15 pm
by bdony
For pins 1, 2, and 3 I am actually using the pot circuit described in the datasheet on page 8 for a single supply. My 10k-20k pot gives me a voltage range of ~0 - 5 volts, where 0 gives me dark blocks and up around 5 I cannot see any blocks (too bright). I should have no problem hitting 0.5 volts. I'm going to try it out today, I'll let you know how it goes. As far as telling signs go for successful init, I expect the blocks will be cleared by the clear display instruction, or should I be looking for something else like a cursor?

Thanks for all your help.
-Bryan

Posted: Mon May 26, 2008 2:30 pm
by Ray
Once you initalize the display correctly the black bars will disappear. The best thing usually to do is

1) Verify the wiring
2) Verify the wiring again
3) Verify the wiring again
4) Timings can be too low, but they never be too high, thow a couple of ms between all commands just to see if it improves things especially in between putting E to 1 and back to 0 you probably want a small delay there.

Posted: Mon May 26, 2008 8:31 pm
by bdony
So I tried powering up with varying delays between the VDD and V0 rise, and it all yields the same result: two rows of solid blocks (faded by adjusting the contrast pot). I have verified all of the signals and voltage levels to the LCD (all the wiring I could think of), and now I am going to insert delays to more than double all of the instruction cycles. I'll keep you updated.

-Bryan

EDIT: Reviewing the OP's initialization sequence, I notice 3 function sets in a row (I only use 2), and 2 display on/off instructions (I only use 1 and set display=1). Is his sequence/values correct?

Posted: Tue May 27, 2008 10:03 am
by Clark
Hi Bryan,

It looks like Ray has given you a few ideas, the last of which is probably the most helpful in there :wink: . He's more of a software guy, so he's going to doubt the hardware, and I'm more hardware, so I'll be doubting the code; between us I think we can get this screen up and running :lol:.

The delay to allow E to set up high before dropping it low is a good idea, give it a shot. Also, I am wondering if you've tried writing any text to the screen; keep in mind RS should be high for data and throw something simple like 0x41 (A) at the screen.

At this point, it looks like your display is behaving as it should as far as hardware is concerned. You seem to have good control over contrast, and the screen is blank on start up, which is a great start.

As always, let me know how the tinkering is going, and I'll try to point you in the right direction.

~Troy

Posted: Tue May 27, 2008 2:44 pm
by Ray
Hey,

Ran a quick test today and while i'm not too sure about my timings (too lazy to do the math or grab a scope) the following code will initalize the controller and write HI.

Code: Select all

#define LCD_COMMAND 0
#define LCD_DATA    1

void smallNap()
{
	for(int i=0; i<1600; i++)
		__asm volatile (" nop");  
}

void LongNap()
{
	for(int i=0; i<16000; i++)
		__asm volatile (" nop");  
}

void writeLcd(unsigned char command,int data)
{
	GPIO_SET(RS,command==LCD_DATA);
	GPIO_LO(RW);
	GPIO_SET_RANGE(D0,data,8);
	GPIO_HI(E);
	smallNap();  
	GPIO_LO(E);
	smallNap();
}

void Init()
{
	//Init
    writeLcd(LCD_COMMAND, 0x30);
    LongNap();
    writeLcd(LCD_COMMAND, 0x30);
    LongNap();
    writeLcd(LCD_COMMAND, 0x30);
    LongNap();

    //function set <-- Black bars get removed after this command.
    writeLcd(LCD_COMMAND, 0x38);
    LongNap();

    //display off
    writeLcd(LCD_COMMAND, 0x08);
    LongNap();

    //display clear
    writeLcd(LCD_COMMAND, 0x01);
    LongNap();  
      
    //display control set
    writeLcd(LCD_COMMAND, 0x06);
    LongNap();

    //display control set
    writeLcd(LCD_COMMAND, 0x0c);
    LongNap();

    //cursor home
     writeLcd(LCD_COMMAND, 0x02);
	  LongNap();

	 writeLcd(LCD_DATA, 'H');
    LongNap(); 
    writeLcd(LCD_DATA, 'I');
    LongNap(); 
}


Posted: Thu May 29, 2008 4:23 pm
by bdony
Thanks a lot for that sample code Ray. I edited my initialization to look more like yours, and it worked like a charm. I think the step I was skipping was setting the display OFF, configuring the settings, then turning the display ON after that. Both your and Troy's help are much appreciated by me (and my team).

I have been running some test programs, adjusting settings and getting used to writing to any location on the screen via DDRAM addresses, and have been successful for the most part. My final issue is being able to write to all 4 lines. I seem to be able to only write to 2 lines, and unless I misunderstood the specs, this LCD has 4 character display lines. I believe I am currently in 5x8 character mode; if I turn the contrast way down I can clearly see 4 lines of 20 solid blocks, but I cannot seem to write to lines 2 or 4. The function set instruction allows 2 line or 1 line mode, which I don't quite understand.

Posted: Thu May 29, 2008 10:23 pm
by Ray
The HD44780 internally actually only knows of a 1x40 and a 2x40, so your 4x20 display set it up as a 2 line display. you can then address all characters at the following memory addresses.

0x00 -> 0x13 Line1
0x40 -> 0x53 Line2
0x14 -> 0x27 Line3
0x54 -> 0x67 Line4