View Single Post
Old 07-09-2008, 12:54 PM   #24 (permalink)
Yoshi
SuperMID designer
 
Yoshi's Avatar
 
Join Date: Mar 2008
Location: Yokohama, JAPAN
Posts: 37
Thanks: 0
Thanked 13 Times in 2 Posts
Hi,
From the "OBD MPGuino gauge" thread...
Quote:
Originally Posted by dcb View Post
Is anyone willing to fix the 4 bit library?
Following is my proposal for the LCD init() routine.
I have not tested it yet. Please let me know it works or not.
Code:
void LCD::init(){
  delay(16);                    // wait for more than 15 msec
  value=pushNibble(B00110000);  // send (B0011) to DB7-4
  cmdWriteSet();
  tickleEnable();
  delay(5);                     // wait for more than 4.1 msec
  value=pushNibble(B00110000);  // send (B0011) to DB7-4
  cmdWriteSet();
  tickleEnable();
  delay(1);                     // wait for more than 100 usec
  value=pushNibble(B00110000);  // send (B0011) to DB7-4
  cmdWriteSet();
  tickleEnable();
  delay(1);                     // wait for more than 100 usec
  value=pushNibble(B00100000);  // send (B0010) to DB7-4 for 4bit
  cmdWriteSet();
  tickleEnable();
  delay(1);                     // wait for more than 100 usec
  // ready to use normal LcdCommandWrite() function now!
  LcdCommandWrite(B00101000);   // 4-bit interface, 2 display lines, 5x8 font
  LcdCommandWrite(B00001100);   // display control:
  LcdCommandWrite(B00000110);   // entry mode set: increment automatically, no display shift

//creating the custom fonts:
  LcdCommandWrite(B01001000);  // set cgram
  static byte chars[] PROGMEM ={
    B11111,B00000,B11111,B11111,B00000,
    B11111,B00000,B11111,B11111,B00000,
    B11111,B00000,B11111,B11111,B00000,
    B00000,B00000,B00000,B11111,B00000,
    B00000,B00000,B00000,B11111,B00000,
    B00000,B11111,B11111,B11111,B01110,
    B00000,B11111,B11111,B11111,B01110,
    B00000,B11111,B11111,B11111,B01110};

    for(byte x=0;x<5;x++)
      for(byte y=0;y<8;y++)
          LcdDataWrite(pgm_read_byte(&chars[y*5+x])); //write the character data to the character generator ram

  LcdCommandWrite(B00000001);  // clear display, set cursor position to zero
  LcdCommandWrite(B10000000);  // set dram to zero

}
Regards,
Yoshi
  Reply With Quote