CFAH2004 usage questions


New member
I just bought a CFAH2004A-TMI-JP. I want to use it as part of the final project for my microcontroller interfacing class. I don't have much experience with hardware thats more complicated than simple combinatorial/sequential logic chips, but I learn pretty quickly. I have no trouble writing code for my microcontroller (motorola/freescale 9s12c32), and I can easily interface with pushbuttons and LEDs - I don't need any help putting the circuit together, or getting my microcontroller to send data to the LCD module. What I do want is a little help understanding the basics of the LCD instructions and such. I'm pretty sure I could figure it out on my own for the most part, but I want to make sure I don't do anything stupid and break it.

Looking at the data sheet, it seems pretty simple. I turn everything on and follow the initialization sequence, setting N, F, I/D, and S in the process. From the instruction table, those signals do the following:
N=0 - 1 display line; N=1 - 2 display lines
F=0 - 5x8 dots; F=1 - 5x11 dots
I/D - cursor moving direction
SH - shift of display
I understand generally what these are all supposed to do, but I don't understand exactly how theyre implemented. I have the following problems:
- I assume the display can use either 4 or 2 lines, which value of N corresponds to which of those?
- I thought each character was 5x8 dots, with 1 dot in between each character, how does "5x11" work?
- What exactly gets shifted? does this signal toggle between using lines 1,3 and 2,4?

As far as I can tell, a character is written as follows: set DDRAM address to the desired screen position, then write data to RAM, using falling edge of E to trigger the instructions. Both of these operations take a while, so I'll have to make sure to wait an appropriate amount of time between these two operations. Is any of this right, or near the mark at all?

Why exactly is the DDRAM mapped like it is? 0-13, 40-43, 14-27, 54-67. Why does the second line get skipped, and why is there a jump in the memory between 27 and 40?

Finally, I have a couple questions about the LCD and LED. I see that the LCD should probably take 4-4.5V, should I worry about the current as well? How is the contrast controlled? I assume the LED needs a resistor, probably 10K-20K, is that right?

I guess I wrote a lot more than I meant to. Please have patience, its been a while since I've dealt with some of this stuff, and I've never worked with an LCD before. I'm completely new to this, and I am trying to figure out as much as I can on my own from the data sheet, I just want to be sure not to screw it up. Thanks for any help.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.

CF Tech

For the LED backlight, this is the thread:

A 10K pot between 5v and ground connected to Vo works fine.

The best way to understand the instructions is probably to look at CFAH_WinTest:

A lot of the odd stuff like the character maps comes from history. I think maybe the controller was originally designed for a 40x2, and some clever glass layout guy wrapped it into a 20x4 :) . . . well, maybe not but that is basically the way the addresses work.

I have found the best way is to just reserve 4 20 character strings in your micro's RAM. Put all your data there (for easy positioning, fast access, & et c.). Then make an "update" routine that copies that data to the physical display.

You will need delays or you will need to poll the busy bit.

Look for a "44780" LCD library for your processor, there is probably one out there.


New member
Thanks for the reply. Should I just connect V0, the LCD operating voltage, between two resistors from ground to 5v? Also, since the busy flag is on DB7, doesn't that mean its possible to short out the circuit if I send an instruction when BF is asserted? Is BF only asserted when the read intruction is sent?

CF Tech

BF is only asserted during a read operation. You should make your data lines high impedance at your processor as part of the read sequence.

Typically a 10K pot between +5v and ground, with the wiper connected to Vo works fine for contrast adjustment.


New member
I'm starting to understand whats going on, but I'm still having a few problems, hopefully you can help me out with these last few things.

1. I hooked up RS, R/W, E, and D to some dip switches, and I managed to initialize the module and display a few characters. This means I understand how to send instructions and data. However, when I try to do the same thing using my micro, I don't really get any response. Are there any common mistakes I might be making? I checked the timing diagram and all of the other timing parameters scattered throughout the data sheet, and as far as I can tell, my code is following those values correctly.

2. When I was using the dip switches, I got through the initialization with no problem, and I could display characters, but I wasn't getting the characters I was trying to. Is there something out of the ordinary about the order of the 8 data bits?

3. Finally, the first time I turned on the backlight and the LCD display, the first line was fully 'lit up' (or active, I'm not sure of the correct term), the second and fourth lines were blank, and the third line was about half lit - the bottom five pixels of every character were on, and the top three were off. I know lines two and four are controlled in the initialization sequence and all that, what concerns me is the third line, why is it only half lit?
I was very careful not to connect anything directly until I was confident it was correct. I started with 10k resistors between basically every connection, and removed them one by one until I reached my current setup, where the backlight is on just enough so that I can see it, and V0 is something pretty low, not quite enough to light up an LED.
I don't believe I sent out any weird data on RS,R/W,E,D, because I spent a couple hours writing the code and at least another hour double checking it. I was specifically worried about accidentally sending bad instructions/data to the LCD, so I rechecked every line of code a couple times to make sure it was doing exactly what it was supposed to
So, I don't think I did anything dumb, but is there another reason why one of my lines would evidently be broken? Or did I screw up and fry something?

Thanks for any help, and thanks for your patience.

CF Tech

Generally if you do not reverse polarity, and keep everything between 0v and +5v, you should not have killed the display. You can whack them with ESD.

Using the DIP switches, you would need to "debounce" E to get reliable results. The switch's contact bounce would look like multiple clock cycles to the LCD.

Usually there is a wiring or code issue. Do this test:

1) Make a very slow square wave that is about 1 second high, and 3 seconds low. You can do this with a bunch of delays in a loop. Put this square wave to output on E. Set all the other LCD pins to low. Use your meter to verify that all the pins are low (at the LCD connector), and that E (at the LCD connector) comes high for 1 second, and goes low for 3 seconds.

2) Repeat this test for R/W, RS, and D0 - D7

This tests "all the way through" your software to the pin on the LCD connector. Once you get that going (and hopefully it will point out some errors), try making those changes back into the initialization code.

3) Set Vo (pin 3) to about 1v

4) Put long delays between EVERY step of the initialization. They will not hurt and you can take them out later.

You also may want to check for a Freescale application note that shows how to drive a "HD77480" LCD.


New member
After putting it off for a while, I sat down for a few hours and wrote all the code for the display tonight, and got it done. It works exactly as I want it to. Thank you for all your help, I now completely understand how to interface with the LCD. However, I still have the problem of what appears to be some dead pixels.

As I mentioned earlier, on the third line of my display, the top three rows of pixels for each character completely refuse to turn on. I have no idea what might have caused this. I do not believe that I caused this, because a) I have been extremely careful with the module since I got it, b) the display has had this problem since the first time I turned it on, and c) only a certain strange set of pixels is dead, I do not see how this could have been caused by ESD (though I am clearly not an expert on this).

Is it possible that I might have received a damaged display? If so, how might I go about getting it replaced?

Thank you.

CF Tech

Please write, and reference this thread. We will issue an RMA.

A line going bad like that is typically caused by the LCD glass being disassembled from the PCB, and not being reassembled correctly. There can be other causes, sometimes there truly is ESD damage, sometimes the glass has a crack at the edge, hidden by the bezel.