Graphic LCD (KS0108) library now available

I wanted to get the GLCD to work with the 74HC595 to be able to save 5 pins on the arduino. To test this fast I just did a fask hack to try if it was possible to do.
The answer to that is that it is possible. The big loss with this is that it is not possible read from the GLCD and therefor if you write to the same area more then one time with different data only the last data will show.
For me that has not been a big problen because I mostly present text in the display and I use a font with fixed width. Therefor all the old characters are coverd with the new ones if the same amount of characters are used.

If someone is interested in how I did this fast hack here is the answer.
This is what I did in the ks0108.h file:

  1. I defined the pins needed for the 74HC595 to work.
#define DataPin      2
#define ClockPin      3
#define LatchPin      4
  1. I added the ShiftOut macro from MartinFick that he posted in the thread “Arduino Forum ? Software ? Bugs & Suggestions ? Higher Performance IO”.
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#define sbipin(pin) sbi((pin)<8 ? PORTD:PORTB, (pin) - ((pin)<8 ? 0:8))
#define cbipin(pin) cbi((pin)<8 ? PORTD:PORTB, (pin) - ((pin)<8 ? 0:8))

#define bitWrite(pin, val) { \
  if ((val) == LOW) cbipin(pin); \
  else              sbipin(pin); \
}

#define shiftOutBit(dataPin, clockPin, val, bit) { \
  bitWrite(dataPin, ((val) & (1 << (bit))) ? HIGH:LOW); \
  bitWrite(clockPin, HIGH); \
  bitWrite(clockPin, LOW); \
}

#define shiftOutByte(dataPin, clockPin, bitOrder, val) { \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?0:7); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?1:6); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?2:5); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?3:4); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?4:3); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?5:2); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?6:1); \
  shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?7:0); \
}
  1. In the private section I added a new function.
void lcdDataShiftOut(uint8_t data);

In the ks0108.cpp file I did these changes:

  1. All the lines that uses the ReadData() function I changed to a fake readout with 0. This is because it's no longer possible to read from the GLCD.
    e.g. “data = this->ReadData();” became
    data = 0x00; //this->ReadData();
  2. In the “Init(Boolean invert)” function I added the outputs needed for the 74HC595.
pinMode(LatchPin,OUTPUT);
pinMode(DataPin,OUTPUT);
pinMode(ClockPin,OUTPUT);
  1. A shiftout function was added to write to the GLDC using the macros in the .h file.
void ks0108::lcdDataShiftOut(uint8_t data)
{
      fastWriteLow(LatchPin);
      shiftOutByte(DataPin, ClockPin, MSBFIRST, data);
      fastWriteHigh(LatchPin);
}
  1. And finally in the “WriteData(uint8_t data)” and “WriteCommand(uint8_t cmd, uint8_t chip)” functions I commented out the use of “lcdDataOut()” macro and replaced it with the “lcdDataShiftOut(uint8_t data)”.
    e.g. “lcdDataOut(cmd);” was commented out and “lcdDataShiftOut(cmd);” was added.

I hope that someone find this usefull. It works fine with my GLCD (ATM12864D). If I test it with the testcode made by mem I got 12 FPS but it do not look that good in the display because there is not possible to read anything from the GLCD. Do not use the 74HC595 if you tend to use a lot of graphics in the GLCD.
\Frisken