LCD module programming

Status
Not open for further replies.

szekhoon

New Member
Hi I have problems writing from a PIC16F877 to a SANYO DM1622 LCD module to display text... the first line of the display is fully lit instead of showing "LCD testing"... pls help... below is the codes.

void initPORTS()
{
TRISA = 0x00; // 0000 0000
TRISB = 0x00; // 0000 0000
TRISC = 0x00; // 0000 0000
TRISE = 0x00; // 0000 0000
TRISD = 0x00; // 0000 0000

//Clear all ports
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
}

//write a byte to LCD in 8-bit mode (To PortD)
void lcd_write(unsigned char c)
{
char_count++;

PORTD = c;
LCD_STROBE;
DelayUs(10);
}

// separate into characters for writing to LCD
void lcd_puts(const char * s)
{
LCD_RS = 1;
while(*s)
lcd_write(*s++);
}

void lcd_init()
{
LCD_RS = 0; // write control bytes
DelayMs(100); // power on delay
LCD_STROBE;
DelayMs(100);
LCD_STROBE;
DelayUs(100);
lcd_write(0x38); //set 8 bit mode, 2 lines, 5x7 font
lcd_write(0x08); // display off
lcd_write(0x0F); // display on, cursor on
lcd_write(0x06); // cursor-shift-right entry mode
}

//clear display, home cursor
void lcd_clear()
{
char_count = 0;

LCD_RS = 0;
DelayMs(100);
lcd_write(0x01);
DelayMs(100);
}

//top row pos is 0-15, bottom row pos is 40-55
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
DelayMs(100);
lcd_write(0x80+pos);
DelayMs(100);
}

int main()
{
unsigned char enter;
initPORTS();
initUART();
initialize_timer0();
initialize_timer1();
initialize_ADC();

delay(1000);

lcd_init();
lcd_clear();
lcd_puts(MSG);
lcd_goto(0x40);
while(1);
}
 
Last edited:
Did you connect a contrast adjustment pot? Can you turn the contrast adjustment down until they go out?
 
Yes... I have done that... I am able to adjust the brightness of the display but it doesn't show the correct text that I have programmed it to show... it shows one whole block being lit up...
 
Try adding this 10µS delay -

Code:
void lcd_write(unsigned char c) 
{
char_count++;

PORTD = c;
DelayUs(10);
LCD_STROBE;
DelayUs(10);
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…