# 16x4 LCD not displaying anything

I am trying to interface a 16x4 LCD with an atmega32 chip. I wrote the following code which used to work for 16x2 LCD

#include<avr/io.h>
#include<util/delay.h>

#define dataport PORTC // LCD data port
#define commport PORTD
#define en PD6 // enable signal
#define wr PD5 // read/write signal
#define rs PD4 // register select signal

int wrcomm(unsigned int data)
{
dataport=data;
_delay_ms(10);
commport &= ~(1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(10);
return 1;
}

int wrdata(unsigned int data)
{
dataport=data;
_delay_ms(10);
commport |= (1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(10);

return 1;
}

int lcd_putchar(unsigned char x)
{
wrdata(x);
return 1;
}

void lcd_init(void)
{
DDRC=0xff;
DDRD=0x70;
wrcomm(0x38);
wrcomm(0x01); //turn on display and cursor
wrcomm(0x0E);//cursor line 1 postn 1
wrcomm(0x80);
}

int main(void)
{
lcd_init();
lcd_putchar('a');
return 0;
}


I am guessing that it should work for 16x4 LCD too. But it doesn't. The LCD is a JHD539 164b.

The one thing I have made progress with is that if I do not send any command the 2nd and 4th line remain all black but if I send any command they are all off. The pot is not helping at all.

• I can't find a datasheet for your specific display -- do you have a link? Sometimes a display manufacturer uses an "odd" mapping from memory locations to screen locations. You might try writing a different data value to each location in the controller's memory to see if anything shows up on the screen, and figure out the mapping from that. – Dave Tweed Jan 21 '13 at 14:04
• Why do you bother with the return values? For stuff like this it's mainly waste as there's not way you can detect an error. – Trygve Laugstøl Jan 22 '13 at 18:41