Can't Initialize CFAG240128L-YYH-TZ

Edge

New member
I recently purchased a CFAG240128L-YYH-TZ. I am connecting it to a PIC18F4550 micro controller.

And i am having major issues with Initializing it. I have searched through Forums and data sheets with no luck.

I am sure the contrast is set since when reset is held low, then i can see a line at random locations on the screen.

Attached is my Code so far. Any suggestions would be great!

Code:
//------------------------
//
// LCD Pins
// 1  - GND
// 2  - GND
// 3  - Vcc
// 4  - Wiper of Pot
// 5  - RE2
// 6  - RE1
// 7  - RC1
// 8  - RE0
// 9  - End of Pot (other end connected to Ground)
// 10 - RC0
// 11 - RD0
// 12 - RD1
// 13 - RD2
// 14 - RD3
// 15 - RD4
// 16 - RD5
// 17 - RD6
// 18 - RD7
// 19 - GND
// 20 - GND
// 


#include <p18cxxx.h>
#include <delays.h>

#define	LCD_CMD_DATA	PORTEbits.RE0
#define LCD_READ		PORTEbits.RE1
#define LCD_WRITE		PORTEbits.RE2
#define LCD_RESET		PORTCbits.RC0
#define LCD_CHIP_ENABLE	PORTCbits.RC1
#define LCD_DATA		PORTD

void LCD_Debug(char tmp);
void LCD_Status_Check(void);
void LCD_Write_Cmd(char cmd_val);
void LCD_Write_Byte(char byte_val);
void LCD_Init(void);


//-------------------------------
//Required for Bootloader
extern void _startup (void);		

#pragma code _RESET_INTERRUPT_VECTOR = 0x000800

void _reset (void) {
    _asm
		goto _startup
	_endasm
}

#pragma code
//-------------------------------

void main(void)
{
	char i;	

	ADCON1 = 0b00001111;	

	//Sets all control i/o pins
	TRISC = 0b11111100;
	TRISE = 0b11111000;

	//Sets all Data i/o pins
	TRISD = 0b00000000;
	TRISA = 0b11011111;

TRISA = 0x00;
TRISC = 0x00;
TRISE = 0x00;
TRISD = 0x00;

	LCD_CHIP_ENABLE = 1;

	LCD_RESET = 0;

	LCD_Debug(10);

	LCD_RESET = 1;

	LCD_Debug(4);

	LCD_Init();


	// Flashing LED to Tell when Above Code has been Completed
	while(1)
	{
		PORTAbits.RA5=1;
		Delay10KTCYx(800);
		PORTAbits.RA5=0;
		Delay10KTCYx(800);
	}

}

void LCD_Debug(char tmp)
{	
	char i;

	Delay10KTCYx(200);

	for(i=0; i < tmp; i++)
	{
		PORTAbits.RA5=1;
		Delay10KTCYx(200);
		PORTAbits.RA5=0;
		Delay10KTCYx(200);
	}

}

void LCD_Status_Check(void)
{
	char lcd_status;

	LCD_CMD_DATA = 1;

	TRISD = 0xff;

	LCD_READ = 0;
	LCD_CHIP_ENABLE = 0;

	do
	{

		//Short Delay	
		_asm
			NOP
			NOP
			NOP
			NOP
		_endasm
	
		lcd_status = LCD_DATA;
	}
	while( ( PORTDbits.RD0 == 0 ) || ( PORTDbits.RD1 == 0 ) );

	LCD_CHIP_ENABLE = 1;

	TRISD = 0x00;

	LCD_READ = 1;
}


void LCD_Write_Cmd(char cmd_val)
{
	LCD_Status_Check();
	
	LCD_CMD_DATA = 1;

	LCD_DATA = cmd_val;
	
	LCD_WRITE = 0;
	LCD_CHIP_ENABLE = 0;
LCD_Debug(1);

	
	//Short Delay	
	_asm
		NOP
		NOP
	_endasm
	LCD_CHIP_ENABLE = 1;
	
	LCD_WRITE = 1;

}

void LCD_Write_Byte(char byte_val)
{
	LCD_Status_Check();

	LCD_CMD_DATA = 0;

	LCD_DATA = byte_val;

	LCD_WRITE = 0;
	LCD_CHIP_ENABLE = 0;
LCD_Debug(1);

	
	//Short Delay	
	_asm
		NOP
		NOP
	_endasm
	LCD_CHIP_ENABLE = 1;
	
	LCD_WRITE = 1;
}

void LCD_Init(void)
{	


// Initialization

	LCD_Write_Cmd(0x80); 	//CMD

	LCD_Write_Byte(0x00);	//LSB
	LCD_Write_Byte(0x0C);	//MSB
	LCD_Write_Cmd(0x42); 	//CMD

	LCD_Write_Byte(0x28);	//LSB
	LCD_Write_Byte(0x00);	//MSB
	LCD_Write_Cmd(0x43); 	//CMD

	LCD_Write_Byte(0x00);	//LSB
	LCD_Write_Byte(0x00);	//MSB
	LCD_Write_Cmd(0x40); 	//CMD

	LCD_Write_Byte(0x28);	//LSB
	LCD_Write_Byte(0x00);	//MSB
	LCD_Write_Cmd(0x41); 	//CMD

// init over

	LCD_Write_Byte(0x00);	//LSB
	LCD_Write_Byte(0x00);	//MSB
	LCD_Write_Cmd(0x24); 	//CMD

	LCD_Write_Byte(0x24);	//MSB
	LCD_Write_Cmd(0xC0); 	//CMD

	LCD_Write_Byte(0x25);	//MSB
	LCD_Write_Cmd(0xC0); 	//CMD

	LCD_Write_Cmd(0x9C); 	//CMD



}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Top