AVR and CFAG128128B

kasunt

New member
Hi Guys,

I just wanted to test my connections and the LCD itself and I started using Vanya's LC7981 code https://github.com/vsergeev/embedded-drivers/tree/master/avr-lc7981 with slight modifications for 128x128 LCD I'm using. Using an Arduino Mega 2560 board but with GCC C. The LCD lights up and I can control the contrast. The only thing that happens is some flickering. No characters shows up. What could possibly be the problem ?

The constants I changed were,

In lc7981.h,
Code:
#define F_CPU	16000000
#define LCD_CTRL_DDR DDRC
#define LCD_CTRL_PORT PORTC

#define LCD_CTRL_RS 1
#define LCD_CTRL_RW 2
#define LCD_CTRL_E 3
#define LCD_CTRL_CS 4
#define LCD_CTRL_RST 5

#define LCD_WIDTH 128
#define LCD_HEIGHT 128

#define lcd_cs_high() (LCD_CTRL_PORT |= (1<<LCD_CTRL_CS))
#define lcd_cs_low() (LCD_CTRL_PORT &= ~(1<<LCD_CTRL_CS))

#define lcd_rst_high() (LCD_CTRL_PORT |= (1<<LCD_CTRL_RST))
#define lcd_rst_low() (LCD_CTRL_PORT &= ~(1<<LCD_CTRL_RST))
In lc7981.c,
Code:
/**
* Initializes the LCD in graphics mode.
* Uses a character pitch of 8 (8 bits are plotted whenever a byte is drawn)
*/
void lcd_graphics_init(void) {
unsigned char commandData;

/* Set the data direction registers appropriately */
LCD_DATA_DDR = 0xFF;
LCD_CTRL_DDR |= (1<<LCD_CTRL_RS)|(1<<LCD_CTRL_RW)|(1<<LCD_CTRL_E)|(1<<LCD_CTRL_CS)|(1<<LCD_CTRL_RST);

/* Assert all control lines to low */
lcd_rw_low();
lcd_rs_low();
lcd_enable_low();
lcd_cs_low(); /* Active */

lcd_rst_high();
delay_ms_long(100);
lcd_rst_low();
delay_ms_long(100);

/* Send mode configuration command with
* Toggle Display On, Master, Mode Graphics bits set */
commandData = LCD_MODE_ON_OFF | LCD_MODE_MASTER_SLAVE | LCD_MODE_MODE;
lcd_write_command(LCD_CMD_MODE, commandData);

/* Send the set character pitch command with horizontal
* character pitch of 8 (so 8 pixels are painted when we draw) */	
commandData = LCD_CHAR_PITCH_HP_8;
lcd_write_command(LCD_CMD_CHAR_PITCH, commandData);

/* Send the number of characters command with the total
* number of graphics bytes that can be painted horizontally
* (width/8) */
commandData = (LCD_WIDTH/8)-1;
lcd_write_command(LCD_CMD_NUM_CHARS, commandData);

/* Set the time division */
commandData = 128-1;
lcd_write_command(LCD_CMD_TIME_DIVISION, commandData);

/* Set the display low/high start address to 0x00 (left corner) */
commandData = 0x00;
lcd_write_command(LCD_CMD_DISPLAY_START_LA, commandData);
lcd_write_command(LCD_CMD_DISPLAY_START_HA, commandData);

/* Reset the cursor to home 0x00 (left corner) */
commandData = 0x00;
lcd_write_command(LCD_CMD_CURSOR_LA, commandData);
lcd_write_command(LCD_CMD_CURSOR_HA, commandData);
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Last edited:
I'd be willing to help you with this, as I have used the CFAG128128, but I'm not willing to go to other web sites to download stuff. You should make it easy on your prospective helpers by putting everything necessary in this thread.

A suggestion: if your code stuff is approx 100 lines or less, put it in a code box (as you have done). If its a lot longer, upload the file(s) as an attachment.

As a first observation, you say:
No characters shows up.
But in your code snippet, you have:
Code:
* Initializes the LCD in graphics mode.
Which leads me to inquire which mode you are trying to use. Maybe if you supply your entire code, this would become evident.
 

kasunt

New member
Thanks dude.

I have attached the code. In a compressed format so will be easier for you to open all the files.

What I want to make sure is if the instructions are correct ? I could not find any instructions for the NT7086 controller ?
I did find a number of instructions for LC7981 controller in the datasheet. However, these instructions dont match with the instructions given in the parallel port sample code in http://www.crystalfontz.com/backlight/Demo_Code/CFAG128128A_wintest.zip

As you can see from the code I attached Im trying to get the character mode going.
 

Attachments

I could not find any instructions for the NT7086 controller ?
You can download the NT7086 datasheet: https://www.crystalfontz.com/controllers/NT7086.pdf
I did find a number of instructions for LC7981 controller in the datasheet. However, these instructions dont match with the instructions given in the parallel port sample code in CFAG128128A_wintest.zip
I wouldn't expect the instructions to match. The 128128A display uses a different controller than the 128128B display.
As you can see from the code I attached Im trying to get the character mode going.
Actually, what I see is you are not using character mode; you are initializing in graphics mode and trying to use the graphics functions to plot the bitmap font for the characters.

One thing I discovered about this display some years ago is described in this thread:
https://forum.crystalfontz.com/showthread.php?5339-CFAG128128-to-an-8051&p=23071#post23071

I don't have any graphics experience with the 128128B, although I have done a lot of graphics code for the 160160B, which uses the same controller.

To simplify testing, I recommend that you initialize your 128128B in character mode (0x30) first, and write a few characters, to see if you can get anything to show on the screen, before you switch to experimenting in graphics mode.

One other thing: your code uses a fixed delay for the "busy wait" instead of actually testing the controller, and you may or may not need a longer value of delay. In my code, I test the busy status to avoid timing problems:
Code:
static void LCDBusy(void)
{
	PEDD = 0xFF;			//set bus port to inputs

	PCOUT = RW + RS + RES;		// set for status read
	DELAY;
	PCOUT = E + RW + RS + RES;	// assert enable
	DELAY;

	while (LCD_IN & 0x80);		// wait for busy bit to go low

	PCOUT = RW + RS + RES;		// de-assert enable
	PCOUT = RES;			// set for write

	PEDD = 0;			//set bus port to outputs
}
This actually takes less time than your fixed delay.

LCD_E_RW.jpg
 

kasunt

New member
Thanks cosmicvoid.

Very good tips. I didnt realize that the older version used a different chipset.

And you are right about the timing. For now I thought of using a delay. But I will opt to use what you suggested once I get this going. Time for me to do a lot more homework :p.
 
Top