Maker Pro
Maker Pro

Four line Alphanumeric Display

Hi everyone,
I've been working on a project using a a four line display using a HD44780 compatible display.
I've tried two different models but only been able to get lines 1 and 3 to work because when I try to put the display into two line mode the screen goes blank.
Here's the code I'm using to control it. ( A modified version of the code included in the hi-tech C compiler. I'm using a PIC 16f628 to do the control work.

Has anyone had any similar problems in the past - I tried searching but couldn't find anything about it.
Code:
#ifndef _XTAL_FREQ
 #define _XTAL_FREQ 4000000
#endif

unsigned char screenBuffer[64] = {48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,
					48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,
					48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,
					48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48
	}; // These are all zeros

#define D7 RB0
#define	LCD_RS RB2
#define	LCD_RW RB4
#define LCD_EN RB5
#define LCD_DATA	PORTA

#define	LCD_STROBE()	((LCD_EN = 1),(LCD_EN=0))

void lcd_write(unsigned char c){
	LCD_EN = 1;
	LCD_DATA = ((c & 0x1F) | ((c << 1) &0xC0));
	D7 = (c >> 7);
	LCD_EN = 0;
	__delay_us(50);
}

void lcd_clear(){
	LCD_RS = 0;
	lcd_write(0x1);
	__delay_ms(2);
}

void lcd_goto(unsigned char pos){
	LCD_RS = 0;
	lcd_write(0x80+pos);
}

void lcd_update(){
	lcd_clear();
	unsigned char i;
	lcd_goto(0);
	for(i=0;i<64;i++){
		switch(i){ 
			case 16: lcd_goto(0x40); break;
			case 32: lcd_goto(0x10); break;
			case 48: lcd_goto(0x50); break;
		}
		LCD_RS = 1;
		lcd_write(screenBuffer[i]);
	}
	LCD_RS = 0;
}

void lcd_init() {
	LCD_RS = 0;
	LCD_EN = 0;
	LCD_RW = 0;
	__delay_ms(50);	// wait 30mSec after power applied,
	lcd_write(0x30);
	__delay_ms(5);
	LCD_STROBE();
	__delay_us(100);
	LCD_STROBE();
	__delay_us(100);
	lcd_write(0x30); 	
	lcd_write(0x08); 
	lcd_write(0x01); 
	//lcd_clear();
	lcd_write(0x06); 
	__delay_ms(15);
	
}

This works for one line mode (wrapped around) if I change the 0x38 to 0x30

-- The 8 bit data bus is attatched to PORTA but bit 5 is attatched to RA6, 6 to RA7 and bit7 to RB0 (RA5 is input only).
Thanks
 
Last edited:
Solved

After lots of hours, I solved it.
In case anyone else is having problems the contrast resistor required seems to vary between one line mode and two line mode. I'd just put a static resistor in when it was working in one line mode and assumed it'd be fine for two. Such a simple solution!
 
Top