CFAG128128B only flickers


New member
Hi all,

Im trying to drive the CFAG128128B using AVR but all I'm seeing is flickering. Its the CFAG128128B-TMI-VZ lcd and even without powering the AVR board (Arduino mega 2560 coded in GCC C) the result is a bunch of white lines running in a blue background. You can see this in the video,

I'm happy to upload a link to the code but not sure how useful that would be.

In terms of connections I have mapped the following LCD->AVR pins,

Pins 1-8PORT A
CSPIN C4 (Set to low during initialisation)
RESETPIN C5 (Set to high during initialisation)
VoOne end of 10k pot
VEEOther end of 10k pot
LED+One end of 18.8Ohm resistor
LED-The other end of 18.8Ohm resistor

The third leg of the 10k pot is connected to 5V. And unless mentioned the logic levels of the control signals RS, R/W and E are controlled appropriately.

Can anyone shed some light as to why all I'm getting is flickering ? Hopefully it isnt anything to do with my connections.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
Without seeing your code and init values, I can only make two comments.

1. The video looks like a display that has not been initialized correctly.

2. The connections for the contrast pot should be: one end to Vee, one end to Vdd, middle to Vo.


New member

That's how I have connected the pot. middle leg to Vo and the ends to 5V and Vee.
As I mentioned earlier even without any mcu connections Im seeing flickering. This is what I'm most worried about.
Ofcourse when mcu is initialized there is no change either.

I have attached the source for your reference...


Last edited:
I took a look at your latest code, and I see what seems to be some serious errors. My comments are in red.
void lcd_init(uint8_t mode)
    LCD_DATA_DDR = 0xFF;[COLOR="#FF0000"]    // data bus port set to output[/COLOR]
    LCD_DATA = 0;
[COLOR="#FF0000"]// control port bit direction settings[/COLOR]
    LCD_CTRL_DDR |= (1 << LCD_CTRL_RS) | (1 << LCD_CTRL_RW) | (1 << LCD_CTRL_EN) | (1 << LCD_CTRL_RST);
[COLOR="#FF0000"]// RS, RW, E, RST are all set as outputs (normal)[/COLOR]
    LCD_CTRL_DDR &= ~(1 << LCD_CTRL_CS);
[COLOR="#FF0000"]// CS is set as input (abnormal)!!![/COLOR]
    LCD_CTRL = 0;
[COLOR="#FF0000"]// RST is now set low (active)[/COLOR]


    if (mode == LCD_TEXT)
        lcd_mode = LCD_TEXT;

        lcd_write_command(0x00, 0x3C);
        lcd_write_command(0x01, 0x75);
        lcd_write_command(0x02, LCD_TEXT_COLUMNS - 1);
        lcd_write_command(0x03, 0x4F);
        lcd_write_command(0x04, 0x07);
        lcd_write_command(0x08, 0x00);
        lcd_write_command(0x09, 0x00);
        lcd_write_command(0x0A, 0x00);
        lcd_write_command(0x0B, 0x00);
Your control port can never assert CS to low because the pin is set as an input (i.e. either floating or pulled up; your MCU init is unknown). Also, the /RST signal is set active, and never released in later code. So the upshot is that you are never writing anything to the display controller.

As a secondary observation, your LCD init values seem to treat the display as "128x128", but I pointed you to another thread which tell about treating the display as a "160x160" to make it work correctly. Here is a list of init values from my troubleshooting code.
#define GR_MODE		0		// mode register
#define GR_PITCH	1		// character H & V pitch register
#define GR_HORIZ	2		// horiz chars or bytes register
#define GR_DUTY		3		// duty cycle register
#define GR_CURP		4		// cursor posn register
#define GR_STRTL	8		// display start addr L register
#define GR_STRTH	9		// display start addr H register
#define GR_CURAL	0xA		// cursor addr L register
#define GR_CURAH	0xB		// cursor addr H register
#define GR_WRITE	0xC		// write instruction

static const BYTE LCDIni[GR_INILEN][2] = {
		GR_MODE, 0x10,
		GR_PITCH, 0x95,
		GR_HORIZ, 27,
		GR_DUTY, 159,
		GR_CURP, 6,
		GR_STRTL, 0,
		GR_STRTH, 0,
		GR_CURAL, 0,
		GR_CURAH, 0,
//		GR_MODE, 0x32,	// graphic mode normally
		GR_MODE, 0x30,	// character mode test
		GR_WRITE, 0x44, // test data
		GR_WRITE, 0x55  // test data
By the way, when you are writing a long string of data to the screen (like when clearing it), you only need to send the command "0x0C" (GR_WRITE) once, and then as many data bytes as needed. No need to use GR_WRITE with each data byte.

Also, by declaring "lcd_write_command()" as "inline" in lc7981.h, you are duplicating that code many many times (big time bloat). Better you should make it a called function, and only have one instance of that code in your program.

P.S. Ignore the behavior of an un-initialized display, it doesn't mean anything. So if you just apply power and no MCU activity, may or may not flicker.