CFAH1202A, wrong characters are displayed to the screen

Dee Newcum

New member
I'm trying to write to DDRAM, but the characters aren't what I want to be displayed.

  • When I write to position 0, it always comes out as character 0xF0, regardless of what character I write
  • When I write to position 1, it always comes out as character 0xF1
  • When I write to position 2, it always comes out as character 0xF2
  • When I write to position 3, it always comes out as character 0xF3
  • ...
  • When I write to position 0x40, it always comes out as character 0xF0
  • When I write to position 0x41, it always comes out as character 0xF1
  • When I write to position 0x42, it always comes out as character 0xF2
  • ...

I'm using 4bit mode, and I'm using a NXP KL82 microcontroller.

Attached is my code,
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

Attachments

When I see stuff like this, and there is no indication of the speed of the MCU's I/O cycle, I get suspicious of timing errors. This LCD controller is not particularly fast, and you may be violating the 'E' setup or hold times. In my code I typically set the bus data before toggling the 'E' signal, adding delays for fast MCUs.

Try this change in your code (wherever you do writes) to see whether it has any effect on your problem:

Code:
...
	GPIO_DRV_WritePinOutput(LCD_DB4, ((val >> 0) & 0x1));
	GPIO_DRV_WritePinOutput(LCD_DB5, ((val >> 1) & 0x1));
	GPIO_DRV_WritePinOutput(LCD_DB6, ((val >> 2) & 0x1));
	GPIO_DRV_WritePinOutput(LCD_DB7, ((val >> 3) & 0x1));
	delay40uS();
	GPIO_DRV_SetPinOutput(LCD_E);
	delay40uS();
	GPIO_DRV_ClearPinOutput(LCD_E);
...
If this makes a difference, then you can reduce the delays to 1 or 2 uS. If no joy, then I'll need more details.

Afterthought:
Looking at your LCD_set_4bit_mode() function, it seems like that might be a problem, too. I was looking for some of my old LCD 4-bit code but couldn't find any quickly, but I found another piece of code which illustrates the 4-bit init procedure.
Code:
void lcd_init ()
{
/*
 * I don't understand the reason for the same command three
 * times with different delays but that's what the data
 * sheet says.
 */
        delay (60);             /* >= 15 mS. */
        lcd_put4 (3);
        delay (16);             /* >= 4.1 mS. */
        lcd_put4 (3);
        delay (1);              /* >= 0.1 mS. */
        lcd_put4 (3);
        delay (16);             /* >= 4.1 mS. */
        lcd_put4 (2);           /* Enter 4 bit data mode. */
        delay (1);

/*
 * We are now in 4 bit mode and must do writes in pairs.
 */
        lcd_put4 (2);           /* 4 bit mode again. */
        lcd_put4 (8);           /* 2 line display, 5x7 characters. */
        delay (1);

        lcd_put4 (0);           /* Display off. */
        lcd_put4 (8);
        delay (1);

        lcd_put4 (0);           /* Display on, Cursor and blinking off. */
        lcd_put4 (12);
        delay (3);              /* >= 1.64 mS. */

        lcd_put4 (0);           /* Cursor right automatically. */
        lcd_put4 (6);
        delay (1);
}

void lcd_put4 (byte_t x)
{
        PORTB = x << 4;
        NOP;
        LCD_e = 1;             
        NOP;
        LCD_e = 0;              
}
 
Top