NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Hyundai # HG25504. 5.8" x 4.58" graphic display

May 12, 2011
by kle8309
kle8309's Avatar

allelectronics.com

I bought this GLCD a while ago and finally have time this summer to figure out how to drive this nice GLCD. I have been doing a lot of research on this device and found a number of source codes to help me get started. However, most people use other MCU like Atmega644 or PIC. I'm trying to interface with the Atmega328P. So far the two reliable source codes are from these websites:

cornell's project

sed1335 universal driver

There are basically two PORT setting: DATA/COMMAND and CONTROL For the DAT/CMD I used the whole PORTD 7..0 For the CTR I used PORTC 3..0

May 12, 2011
by kle8309
kle8309's Avatar
// hyundaiHG25504.c
// for NerdKits with ATmega328P
// Kelvin Le

#define F_CPU 14745600

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

#include <stdio.h>

// PORTC 3:0 (/RES,A0,/WR,/RD)
#define LCDRESET 0x07 // RES low
#define CMDSETUP 0x0f // A0 high
#define CMDWRITE 0x0d // A0 high,WR low
#define DATASETUP 0x0b // A0 low
#define DATAWRITE 0x09 // A0 low,WR low

// PORTD 7:0 (D7:D0)
#define SYSTEMSET   0x40 // initialization
#define DISPON 0x59 // display on
#define SCROLL 0x44 // set partitions
#define CSRFORM 0x5D // set cursor type
#define CSRRIGHT 0x4C // right cursor dir
#define HSCROLL 0x5A // horizontal scrolling
#define OVERLAY 0x5B // merging layers
#define CSRW 0x46 // set cursor addr
#define MWRITE 0x42 // write to LCD

unsigned int i_clear = 0;
unsigned char i_clear_row = 0;
unsigned char i_string = 0;
unsigned int row = 0;
unsigned char row_low = 0,row_high = 0;
unsigned char column = 0;
unsigned int scroll_index = 0;

char input[32];
unsigned char accept_input = 0;
unsigned char i_input = 0, column_start = 0;

void init(void);
void clear_lcd(void);
void write_cmd(unsigned char cmd);
void write_data(unsigned char data);
void write_string(char * string);

void init(void){

  DDRC = 0x0f;
  DDRD = 0xff;
  // reset LCD
  PORTC = CMDSETUP;
  _delay_ms(3);
  PORTC = LCDRESET;
  _delay_ms(2);
  PORTC = CMDSETUP;
  _delay_ms(3);

  write_cmd(SYSTEMSET);
  write_data(0x30); // use internal 8px char w/ no top line correction
  write_data(0x87); // 8px width char
  write_data(0x07); // 8px height char
  write_data(0x1f); // 32 char per line
  write_data(0x23); // previous value + 4
  write_data(0x7f); // 128 pixel screen height
  write_data(0x20); // 32 char per line
  write_data(0x00);

  write_cmd(OVERLAY); // text mode,OR layers
  write_data(0x00);

  write_cmd(SCROLL); // screen views 128 rows of mem starting at 0
  write_data(0x00);
  write_data(0x00);
  write_data(0x7f);

  write_cmd(CSRFORM); // 5x7 cursor size
  write_data(0x04);
  write_data(0x86);

  write_cmd(CSRRIGHT); // cursor moves to the right

  write_cmd(HSCROLL); // no horizontal scrolling
  write_data(0x00);

  write_cmd(DISPON); // turn on layer 1,no flashing
  write_data(0x06);

  clear_lcd();

  write_string("Starting...\n");
  sei();
}

void clear_lcd(void){
  write_cmd(CSRRIGHT);
  write_cmd(CSRW); // set the cursor addr
  write_data(0x00);
  write_data(0x00);
  write_cmd(MWRITE);

  for (i_clear=0; i_clear<1024; i_clear++){
    write_data(0x20); // write blank spaces
  }

  write_cmd(CSRW);
  write_data(0x00);
  write_data(0x00);
}

void write_cmd(unsigned char cmd){
  PORTD = cmd;
  PORTC = CMDSETUP; // A0=1,WR=1
  PORTC = CMDSETUP;
  PORTC = CMDWRITE; // WR=0
  PORTC = CMDWRITE;
  PORTC = CMDSETUP; // A0=1,WR=1
  PORTC = CMDSETUP;
}

void write_data(unsigned char data){
  PORTD = data;
  PORTC = DATASETUP; // A0=0,WR=1
  PORTC = DATASETUP;
  PORTC = DATAWRITE; // WR=0
  PORTC = DATAWRITE;
  PORTC = DATASETUP; // A0=0,WR=1
  PORTC = DATASETUP;
}

void write_string(char * string){

  i_string = 0;
  while(string[i_string] != 0){
    if (string[i_string] == '\n'){
      accept_input = 0;
      row += 32; // advance row by 1
      column = 0;
      row_low = row; // low and high bytes of row
      row_high = row >> 8;

      // blank the new row
      write_cmd(CSRW);
      write_data(row_low);
      write_data(row_high);
      for (i_clear_row=0;i_clear_row<32;i_clear_row++){
        write_cmd(MWRITE);
        write_data(0x20);
      }

      // receive \n on last row
      if (row > 992){ // 992=31*32
        write_cmd(CSRW);
        write_data(row_low);
        write_data(row_high-2);
        for (i_clear_row=0;i_clear_row<32;i_clear_row++){
          write_cmd(MWRITE);
          write_data(0x20);
        }

        row = 512; // 512=16*32
        row_low = 0;
        row_high = 2;
        scroll_index = 32;
        write_cmd(SCROLL);
        write_data(0x20);
        write_data(0x00);
      // transition to second 512KB block of memory
      // advance scroll view of mem by one row
      }else if (row > 480){ // 480=15*32
        scroll_index += 32;
        write_cmd(SCROLL);
        write_data(scroll_index);
        write_data((scroll_index >> 8)&0xff);

        // write to 1st 512KB block of mem
        write_cmd(CSRW);
        write_data(row_low);
        write_data(row_high-2);
        for (i_clear_row=0;i_clear_row<32;i_clear_row++){
          write_cmd(MWRITE);
          write_data(0x20);
        }

      }
      write_cmd(CSRW);
      write_data(row_low);
      write_data(row_high);

    }else{
      // printable character
      if (column < 31){
        write_cmd(MWRITE);
        write_data(string[i_string]);

        // write to both 512KB blocks of memory when the LCD
        // displays the second 512KB block of memory
        if (row > 480){
          write_cmd(CSRW);
          write_data(row+column);
          write_data(((row+column) >> 8)-2);

          write_cmd(MWRITE);
          write_data(string[i_string]);

          // advance cursor to next position
          write_cmd(CSRW);
          write_data(row+column+1);
          write_data((row+column+1) >> 8);
        }

        column++;
      }
    }
    i_string++;
  }
}

int main() {

  // init lcd
  init();
  int i=0;
  // testing write_string function
  for(i=0;i<10;i++){
  write_string("\n Hello World !! \n");
   _delay_ms(1000);
   }

while(1)
{
//
}

  return 0;
}
May 12, 2011
by kle8309
kle8309's Avatar

My questions:

  1. Has anyone ever tried to interface with this GLCD using atmega328P b4

  2. Does the clock freq matter (14.7MHZ)

  3. Has anyone ever tried using the universal glcd lib for sed1335

ps. I have tried using the universal glcd lib for sed1335 also but still no luck

ps. the contrast is set at -10v

May 12, 2011
by kle8309
kle8309's Avatar

May 12, 2011
by kle8309
kle8309's Avatar

Here are some pictures of my setup

pic1

pic2

pic3

May 12, 2011
by kle8309
kle8309's Avatar

Sorry for the large pictures

Note:

the yellow wires are the data bus PORTD 7:0 (D7..D0)

the orange wires are the control bus PORTC 3:0 (/RES,A0,/WR,/RD)

Post a Reply

Please log in to post a reply.

Did you know that sound travels via pressure waves in the air, and you can make these with a piezoelectric buzzer? Learn more...