Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

lcd interfacing with pic18f4520

Status
Not open for further replies.
Have you added a delay in between each write cycle? I normally add 10ms. You might not be familiar with C, but this is the code I use:

Code:
// -------------------------------------------------------
void lcd_initialise(void)				/* Initialise LCD */
{
	/* tie the R/W pin low permanently and ignore the DEM16217 d/sheet */
	/* refer to the HD44780 d/sheet */
	unsigned char data, n;

	setbit(global, 1);					/* indicate 1x 4 bit transfer*/
	for(n=0; n<10; n++)
	{
		delay_10ms();					/* wait for power to stabilise*/
	}
	for (n=0; n<3; n++)
	{
		data = 0b00110000;
		lcd_write(data);
	}	
	
	/* function set */
	data = 0b00100000;
	lcd_write(data);
	
	clearbit(global, 1);				/* indicate 2x 4 bit transfer */

	data = 0b00101000;					/* N= 1; F=0 */
	lcd_write(data);
	/* display off */
	data = 0b00001000;
	lcd_write(data);
	/* display clear */
	data = 0b00000001;
	lcd_write(data);
	/* entry mode set */
	data = 0b00000110;					/* I/D = 1 S = 1 */
	lcd_write(data);
	/* display on */
	data = 0b00001100;
	lcd_write(data);
}

and my LCD write code looks like:

Code:
/* -------------------------------------------------------------*/
void lcd_write(unsigned char data)		/* 4 bit LCD transfer */
{
	load_lcd(data & 0xF0);				/* load top 4 MSBs */
	if ((global & 0b00000010)==0)		/* 2 nibble transfer if bit clear */
	{
		data <<= 4;						/* shift LSBs to MSBs */
		load_lcd(data & 0xF0);			/* load bottom 4 MSB */
	}
	delay_10ms();
}
/* -------------------------------------------------------------*/
void load_lcd(unsigned char lcd_data)	/* load data into LCD */	
{
	setbit(PORTA, E);

	PORTB &= 0x0F;						/* clear top 4 bits */
	PORTB |= lcd_data;					/* toggle only DB7:DB4 */
	asm("nop");
	asm("nop");
	asm("nop");
	asm("nop");
	clearbit(PORTA, E);					/* clock in data */
}

Inside the lcd_write code is a 10ms delay. this is normally the bit that trips me up
 
hi dakshata,

what is the code that you have used and as said you said it showing nothing it could be the problem with hardware connection also...
 
Last edited:
Most alphanumeric LCDs just show 1 line of black blocks if they are not initialised properly. is yours showing this, or is it completely blank? If completely blank, check the power supply connections, but also check the contrast voltage. You might have the contrast down so low that any characters you are displaying are not visible. If you just have a row of blocks, it is 99% a software problem (or a bus wiring problem)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top