[Icc-avr] 4-line LCD display

Albert vanVeen Albert.vanVeen at pertronic.co.nz
Mon Jan 28 17:18:12 PST 2008


Thanks, especially for hw suggestions; we're looking at it.
Meanwhile here is my init code for your perusal.


void LCD1_busy_check() {
unsigned char temp;
	if (E1_fault)
		return;
	CLRBIT(PORTC,LCD_RS);
	set_LCD_read();
	TCNT0= 0;	   	   // start timer0
	SETBIT(TIFR,TOV0);   // clear flag
	do {
		busy_bit= false;
		SETBIT(PORTC,LCD_E1);
		NOP(); NOP();
		temp= LCD_DATA_IN;
		CLRBIT(PORTC,LCD_E1);
		if (temp & LCD_DB7) 
		   busy_bit= true;
		if (TIFR&BIT(TOV0)) break;
	} while (busy_bit);
	if (busy_bit)
		E1_fault= true;
}

void LCD2_busy_check() {
unsigned char temp;
	if (E2_fault)
		return;
	CLRBIT(PORTC,LCD_RS);
	set_LCD_read();
	TCNT0= 0;	   	   // start timer0
	SETBIT(TIFR,TOV0);   // clear flag
	do {
		busy_bit= false;
		SETBIT(PORTC,LCD_E2);
		NOP(); NOP();
		temp= LCD_DATA_IN;
		CLRBIT(PORTC,LCD_E2);
		if (temp & LCD_DB7) 
		   busy_bit= true;
		if (TIFR&BIT(TOV0)) break;
	} while (busy_bit);
	if (busy_bit)
		E2_fault= true;
}

void LCD_control_E1(char control_data) {

	LCD1_busy_check();
	if (E1_fault)
		return;
	set_LCD_write();
	LCD_DATA= control_data;
	SETBIT(PORTC,LCD_E1);
	CLRBIT(PORTC,LCD_E1);
}

void LCD_control_E2(char control_data) {
	LCD2_busy_check();
	if (E2_fault)
		return;
	set_LCD_write();
	LCD_DATA= control_data;
	SETBIT(PORTC,LCD_E2);
	CLRBIT(PORTC,LCD_E2);
}

void initialise_LCD() {
	DelayMs(15);			// for 15ms
	LCD_status.byte= 0;		// clear flags
	CLRBIT(PORTC,LCD_RS);
	set_LCD_write();
	LCD_DATA= 0b00111000;	// 8-bit, 2 rows
	SETBIT(PORTC,LCD_E1);
	SETBIT(PORTC,LCD_E2);
	CLRBIT(PORTC,LCD_E1);
	CLRBIT(PORTC,LCD_E2);
	DelayMs(5);			// for 5ms
	SETBIT(PORTC,LCD_E1);
	SETBIT(PORTC,LCD_E2);
	CLRBIT(PORTC,LCD_E1);
	CLRBIT(PORTC,LCD_E2);
	DelayUs(11);

	LCD_control_E1(0b00111100);	// 8-bit, 2 rows, 10 font
	LCD_control_E1(0b00001100);	// turn display on
	LCD_control_E2(0b00111100);	// 8-bit, 2 rows, 10 font
	LCD_control_E2(0b00001100);	// turn display on
	ClrScr();
	LCD_control_E1(0b00000110);	// cursor incr, no shift
	LCD_control_E2(0b00000110);	// cursor incr, no shift
}

BTW: the timeout in busy_check has never happened, i.e. not that I've
seen.

Albert.
 

-----Original Message-----
From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of John Baraclough
Sent: Tuesday, January 29, 2008 12:45 AM
To: Discussion list for ICCAVR and ICCtiny Users. You do NOT need
tosubscribe to icc-announce if you are a member of this.
Subject: Re: [Icc-avr] 4-line LCD display

Hi Albert,

I second Owen's suggestion of a decoupling capacitor on the contrast
pin. If that doesn't fix it then post us your intialisation code as you
might have a problem there.

One thing I have found; it is advisable to increase the delays between
initialisation steps to about double of that recommended in the data
sheet.

All the best for now,
John


Albert vanVeen wrote:
> Occasionally, but too often to ignore we have problems with 4x40 lcd
> displays: the borrom 2 lines display 'garbage'. No amount of debugging

> and timing experiments have shown up anything so far, and the 
> conclusion "it must be a hardware problem" is tempting, but why then 
> would always the bottom half fail, as these 2 halfs are completely 
> identical?
>  
> Any ideas?
>  
> Albert.
>  
>
> ----------------------------------------------------------------------
> --
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>   

_______________________________________________
Icc-avr mailing list
Icc-avr at imagecraft.com
http://dragonsgate.net/mailman/listinfo/icc-avr

Scanned by Bizo Email Filter




More information about the Icc-avr mailing list