sparkfun / ColorLCDShield

This is an Arduino library for SparkFun's Color LCD Shield
http://www.sparkfun.com/products/9363
40 stars 66 forks source link

1.0 updated to work with my philips LCD shield #5

Closed eagle00789 closed 11 years ago

eagle00789 commented 12 years ago

The 1.0 version posted here doesn't work my lcd shield.

Below is the code to make it work: colorlcdshield.h

/*
  ColorLCDShield.h - Arduino Library to control a Nokia 6100 LCD, 
  specifically that found on SparkFun's Color LCD Shield.
  This code should work for both Epson and Phillips display drivers 
  normally found on the Color LCD Shield.

  License: CC BY-SA 3.0: Creative Commons Share-alike 3.0. Feel free 
  to use and abuse this code however you'd like. If you find it useful
  please attribute, and SHARE-ALIKE!

  This is based on code by Mark Sproul, and Peter Davenport.
*/

#ifndef ColorLCDShield_H
#define ColorLCDShield_H

#define PHILLIPS    0
#define EPSON       1

#include <inttypes.h>

//*******************************************************
//                      Macros
//*******************************************************
#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

//********************************************************************
//
//                  LCD Dimension Definitions
//
//********************************************************************
#define ROW_LENGTH  132
#define COL_HEIGHT  132
#define ENDPAGE     132
#define ENDCOL      130

//********************************************************************
//
//                  EPSON Controller Definitions
//
//********************************************************************
#define DISON       0xAF    // Display on
#define DISOFF      0xAE    // Display off
#define DISNOR      0xA6    // Normal display
#define DISINV      0xA7    // Inverse display
#define SLPIN       0x95    // Sleep in
#define SLPOUT      0x94    // Sleep out
#define COMSCN      0xBB    // Common scan direction
#define DISCTL      0xCA    // Display control
#define PASET       0x75    // Page address set
#define CASET       0x15    // Column address set
#define DATCTL      0xBC    // Data scan direction, etc.
#define RGBSET8     0xCE    // 256-color position set
#define RAMWR       0x5C    // Writing to memory
#define RAMRD       0x5D    // Reading from memory
#define PTLIN       0xA8    // Partial display in
#define PTLOUT      0xA9    // Partial display out
#define RMWIN       0xE0    // Read and modify write
#define RMWOUT      0xEE    // End
#define ASCSET      0xAA    // Area scroll set
#define SCSTART     0xAB    // Scroll start set
#define OSCON       0xD1    // Internal oscillation on
#define OSCOFF      0xD2    // Internal osciallation off
#define PWRCTR      0x20    // Power control
#define VOLCTR      0x81    // Electronic volume control
#define VOLUP       0xD6    // Increment electronic control by 1
#define VOLDOWN     0xD7    // Decrement electronic control by 1
#define TMPGRD      0x82    // Temperature gradient set
#define EPCTIN      0xCD    // Control EEPROM
#define EPCOUT      0xCC    // Cancel EEPROM control
#define EPMWR       0xFC    // Write into EEPROM
#define EPMRD       0xFD    // Read from EEPROM
#define EPSRRD1     0x7C    // Read register 1
#define EPSRRD2     0x7D    // Read register 2
#define NOP         0x25    // No op

//********************************************************************
//
//          PHILLIPS Controller Definitions
//
//********************************************************************
//LCD Commands
#define NOPP        0x00    // No operation
#define BSTRON      0x03    // Booster voltage on
#define SLEEPIN     0x10    // Sleep in
#define SLEEPOUT    0x11    // Sleep out
#define NORON       0x13    // Normal display mode on
#define INVOFF      0x20    // Display inversion off
#define INVON       0x21    // Display inversion on
#define SETCON      0x25    // Set contrast
#define DISPOFF     0x28    // Display off
#define DISPON      0x29    // Display on
#define CASETP      0x2A    // Column address set
#define PASETP      0x2B    // Page address set
#define RAMWRP      0x2C    // Memory write
#define RGBSET      0x2D    // Color set
#define MADCTL      0x36    // Memory data access control
#define COLMOD      0x3A    // Interface pixel format
#define DISCTR      0xB9    // Super frame inversion
#define EC          0xC0    // Internal or external oscillator

//*************************************************************************************
//  LCD Include File for Philips PCF8833 STN RGB- 132x132x3 Driver 
// 
//      Taken from Philips data sheet Feb 14, 2003 
//*************************************************************************************
//* I changed them to P_ for Philips
//* many of these commands are not used but I wanted them all listed in case
//* anyone wants to write more features
//  Philips PCF8833 LCD controller command codes 
#define P_NOP           0x00    // nop 
#define P_SWRESET       0x01    // software reset 
#define P_BSTROFF       0x02    // booster voltage OFF 
#define P_BSTRON        0x03    // booster voltage ON 
#define P_RDDIDIF       0x04    // read display identification 
#define P_RDDST         0x09    // read display status 
#define P_SLEEPIN       0x10    // sleep in 
#define P_SLEEPOUT      0x11    // sleep out 
#define P_PTLON         0x12    // partial display mode 
#define P_NORON         0x13    // display normal mode 
#define P_INVOFF        0x20    // inversion OFF 
#define P_INVON         0x21    // inversion ON 
#define P_DALO          0x22    // all pixel OFF 
#define P_DAL           0x23    // all pixel ON 
#define P_SETCON        0x25    // write contrast 
#define P_DISPOFF       0x28    // display OFF 
#define P_DISPON        0x29    // display ON 
#define P_CASET         0x2A    // column address set 
#define P_PASET         0x2B    // page address set 
#define P_RAMWR         0x2C    // memory write 
#define P_RGBSET        0x2D    // colour set 
#define P_PTLAR         0x30    // partial area 
#define P_VSCRDEF       0x33    // vertical scrolling definition 
#define P_TEOFF         0x34    // test mode 
#define P_TEON          0x35    // test mode 
#define P_MADCTL        0x36    // memory access control 
#define P_SEP           0x37    // vertical scrolling start address 
#define P_IDMOFF        0x38    // idle mode OFF 
#define P_IDMON         0x39    // idle mode ON 
#define P_COLMOD        0x3A    // interface pixel format 
#define P_SETVOP        0xB0    // set Vop
#define P_BRS           0xB4    // bottom row swap 
#define P_TRS           0xB6    // top row swap 
#define P_DISCTR        0xB9    // display control 
#define P_DOR           0xBA    // data order 
#define P_TCDFE         0xBD    // enable/disable DF temperature compensation 
#define P_TCVOPE        0xBF    // enable/disable Vop temp comp 
#define P_EC            0xC0    // internal or external oscillator 
#define P_SETMUL        0xC2    // set multiplication factor 
#define P_TCVOPAB       0xC3    // set TCVOP slopes A and B 
#define P_TCVOPCD       0xC4    // set TCVOP slopes c and d 
#define P_TCDF          0xC5    // set divider frequency 
#define P_DF8COLOR      0xC6    // set divider frequency 8-color mode 
#define P_SETBS         0xC7    // set bias system 
#define P_RDTEMP        0xC8    // temperature read back 
#define P_NLI           0xC9    // n-line inversion 
#define P_RDID1         0xDA    // read ID1 
#define P_RDID2         0xDB    // read ID2 
#define P_RDID3         0xDC    // read ID3 

//*************************************************************************************
//  LCD Include File for Philips PCF8833 STN RGB- 132x132x3 Driver 
// 
//      Taken from Philips data sheet Feb 14, 2003 
//*************************************************************************************
//* I changed them to P_ for Philips
//* many of these commands are not used but I wanted them all listed in case
//* anyone wants to write more features
//  Philips PCF8833 LCD controller command codes 
#define P_NOP           0x00    // nop 
#define P_SWRESET       0x01    // software reset 
#define P_BSTROFF       0x02    // booster voltage OFF 
#define P_BSTRON        0x03    // booster voltage ON 
#define P_RDDIDIF       0x04    // read display identification 
#define P_RDDST         0x09    // read display status 
#define P_SLEEPIN       0x10    // sleep in 
#define P_SLEEPOUT      0x11    // sleep out 
#define P_PTLON         0x12    // partial display mode 
#define P_NORON         0x13    // display normal mode 
#define P_INVOFF        0x20    // inversion OFF 
#define P_INVON         0x21    // inversion ON 
#define P_DALO          0x22    // all pixel OFF 
#define P_DAL           0x23    // all pixel ON 
#define P_SETCON        0x25    // write contrast 
#define P_DISPOFF       0x28    // display OFF 
#define P_DISPON        0x29    // display ON 
#define P_CASET         0x2A    // column address set 
#define P_PASET         0x2B    // page address set 
#define P_RAMWR         0x2C    // memory write 
#define P_RGBSET        0x2D    // colour set 
#define P_PTLAR         0x30    // partial area 
#define P_VSCRDEF       0x33    // vertical scrolling definition 
#define P_TEOFF         0x34    // test mode 
#define P_TEON          0x35    // test mode 
#define P_MADCTL        0x36    // memory access control 
#define P_SEP           0x37    // vertical scrolling start address 
#define P_IDMOFF        0x38    // idle mode OFF 
#define P_IDMON         0x39    // idle mode ON 
#define P_COLMOD        0x3A    // interface pixel format 
#define P_SETVOP        0xB0    // set Vop
#define P_BRS           0xB4    // bottom row swap 
#define P_TRS           0xB6    // top row swap 
#define P_DISCTR        0xB9    // display control 
#define P_DOR           0xBA    // data order 
#define P_TCDFE         0xBD    // enable/disable DF temperature compensation 
#define P_TCVOPE        0xBF    // enable/disable Vop temp comp 
#define P_EC            0xC0    // internal or external oscillator 
#define P_SETMUL        0xC2    // set multiplication factor 
#define P_TCVOPAB       0xC3    // set TCVOP slopes A and B 
#define P_TCVOPCD       0xC4    // set TCVOP slopes c and d 
#define P_TCDF          0xC5    // set divider frequency 
#define P_DF8COLOR      0xC6    // set divider frequency 8-color mode 
#define P_SETBS         0xC7    // set bias system 
#define P_RDTEMP        0xC8    // temperature read back 
#define P_NLI           0xC9    // n-line inversion 
#define P_RDID1         0xDA    // read ID1 
#define P_RDID2         0xDB    // read ID2 
#define P_RDID3         0xDC    // read ID3 

//*******************************************************
//              12-Bit Color Definitions
//*******************************************************
#define BLACK       0x000
#define NAVY        0x008
#define BLUE        0x00F
#define TEAL        0x088
#define EMERALD     0x0C5
#define GREEN       0x0F0
#define CYAN        0x0FF
#define SLATE       0x244
#define INDIGO      0x408
#define TURQUOISE   0x4ED
#define OLIVE       0x682
#define MAROON      0x800
#define PURPLE      0x808
#define GRAY        0x888
#define SKYBLUE     0x8CE
#define BROWN       0xB22
#define CRIMSON     0xD13
#define ORCHID      0xD7D
#define RED     0xF00
#define MAGENTA     0xF0F
#define ORANGE      0xF40
#define PINK        0xF6A
#define CORAL       0xF75
#define SALMON      0xF87
#define ORANGE2     0xFA0
#define GOLD        0xFD0
#define YELLOW      0xFF0
#define WHITE       0xFFF

//*******************************************************
//              Button Pin Definitions
//*******************************************************
#define kSwitch1_PIN    3
#define kSwitch2_PIN    4
#define kSwitch3_PIN    5

//*******************************************************
//                              Circle Definitions
//*******************************************************
#define FULLCIRCLE 1
#define OPENSOUTH  2
#define OPENNORTH  3
#define OPENEAST   4
#define OPENWEST   5
#define OPENNORTHEAST 6
#define OPENNORTHWEST 7
#define OPENSOUTHEAST 8
#define OPENSOUTHWEST 9

//* these define the PORT and BIT number for each control pin
#define _USE_ARDUINO_FOR_NOKIEA_

//* Arduino pin number defs
#define LCD_RES_PIN 8
#define CS_PIN      9
#define DIO_PIN     11
#define SCK_PIN     13

#ifdef __AVR_ATmega2560__
    //* Arduino Mega bit numbers
    #define LCD_RES     5       // D8
    #define LCD_CS          6       // D9
    #define LCD_DIO         5       // D11
    #define LCD_SCK         7       // D13

    //* Arduino Mega ports
    #define LCD_PORT_CS     PORTH
    #define LCD_PORT_SCK    PORTB
    #define LCD_PORT_RES    PORTH
    #define LCD_PORT_DIO    PORTB
#else
    //* Arduino Duemilanove bit numbers
    #define LCD_RES     0       // D8
    #define LCD_CS          1       // D9
    #define LCD_DIO         3       // D11
    #define LCD_SCK         5       // D13
    //#define LCD_PORT  PORTB

    //* Arduino Duemilanove ports
    #define LCD_PORT_CS     PORTB
    #define LCD_PORT_SCK    PORTB
    #define LCD_PORT_RES    PORTB
    #define LCD_PORT_DIO    PORTB
#endif

static char x_offset = 0;
static char y_offset = 0;

const unsigned char FONT8x16[97][16] = {
0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    // columns, rows, bytes, ...
0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    // columns, rows, bytes, ...
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    // ' '
0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,    // '!'
0x00,0x63,0x63,0x63,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    // '"'
0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00,    // '#'
0x0C,0x0C,0x3E,0x63,0x61,0x60,0x3E,0x03,0x03,0x43,0x63,0x3E,0x0C,0x0C,0x00,0x00,    // '$'
0x00,0x00,0x00,0x00,0x00,0x61,0x63,0x06,0x0C,0x18,0x33,0x63,0x00,0x00,0x00,0x00,    // '%'
0x00,0x00,0x00,0x1C,0x36,0x36,0x1C,0x3B,0x6E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,
0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x42,0x66,0x3C,0xFF,0x3C,0x66,0x42,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x18,0xFF,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x63,0x6B,0x6B,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,    // '0'
0x00,0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x03,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x03,0x03,0x1E,0x03,0x03,0x03,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x0E,0x1E,0x36,0x66,0x66,0x7F,0x06,0x06,0x0F,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x60,0x60,0x60,0x7E,0x03,0x03,0x63,0x73,0x3E,0x00,0x00,0x00,0x00,    // '5'
0x00,0x00,0x1C,0x30,0x60,0x60,0x7E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x63,0x03,0x06,0x06,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x63,0x3E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x3F,0x03,0x03,0x06,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,    // ':'
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00,
0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x06,0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x6F,0x6B,0x6B,0x6E,0x60,0x60,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x1C,0x36,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x00,0x00,0x00,0x00,    // 'A'
0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x33,0x33,0x33,0x33,0x7E,0x00,0x00,0x00,0x00,
0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x60,0x60,0x61,0x33,0x1E,0x00,0x00,0x00,0x00,    // 'C'
0x00,0x00,0x7C,0x36,0x33,0x33,0x33,0x33,0x33,0x33,0x36,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x6F,0x63,0x63,0x37,0x1D,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00,    // 'H'
0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x73,0x33,0x36,0x36,0x3C,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00,
0x00,0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x63,0x73,0x7B,0x7F,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x63,0x6B,0x6F,0x3E,0x06,0x07,0x00,0x00,
0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00,
0x00,0x00,0x3E,0x63,0x63,0x30,0x1C,0x06,0x03,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xDB,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x36,0x00,0x00,0x00,0x00,
0x00,0x00,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x00,0x00,0x00,0x00,
0x00,0x00,0xC3,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x63,0x43,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00,    // 'Z'
0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00,    // '\'
0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00,
0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,    // '^'
0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3C,0x46,0x06,0x3E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,    // '_'
0x00,0x00,0x70,0x30,0x30,0x3C,0x36,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,0x00,0x00,    // '`'
0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x60,0x60,0x60,0x63,0x3E,0x00,0x00,0x00,0x00,    // 'a'
0x00,0x00,0x0E,0x06,0x06,0x1E,0x36,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x7E,0x60,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x36,0x32,0x30,0x7C,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x66,0x3C,0x00,0x00,
0x00,0x00,0x70,0x30,0x30,0x36,0x3B,0x33,0x33,0x33,0x33,0x73,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,
0x00,0x00,0x70,0x30,0x30,0x33,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6E,0x7F,0x6B,0x6B,0x6B,0x6B,0x6B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6E,0x3B,0x33,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x38,0x0E,0x03,0x63,0x3E,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x18,0x18,0x7E,0x18,0x18,0x18,0x18,0x1B,0x0E,0x00,0x00,0x00,0x00,    // 't'
0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x36,0x36,0x1C,0x1C,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x3F,0x03,0x06,0x3C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x66,0x0C,0x18,0x30,0x63,0x7F,0x00,0x00,0x00,0x00,    // 'z'
0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00,    // '{'
0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,    // '|'
0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00,    // '}'
0x00,0x00,0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    // '~'
};

static char logo_spark[1120] =  {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfb,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x3f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x3f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x7f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x20,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0f,0xe0,0x9f,0x01,0xfc,0x09,0x9e,0x1e,0x7f,0x70,0x73,0x9f,0x00,0x00,0x00,0x00,
0x3f,0xf1,0xff,0x87,0xfe,0x3f,0xde,0x3d,0xff,0x78,0xf3,0xff,0x80,0x00,0x00,0x00,
0x3c,0xf9,0xff,0xc7,0xdf,0x3f,0xde,0x79,0xff,0x78,0xf3,0xff,0xc0,0x00,0x00,0x00,
0x78,0x79,0xc3,0xcf,0x0f,0x3f,0x1c,0xf0,0x3c,0x78,0xf3,0xe3,0xc0,0x00,0x00,0x00,
0x7c,0x01,0xc1,0xe0,0x0f,0x3e,0x1f,0xe0,0x3c,0x78,0xf3,0xc3,0xc0,0x00,0x00,0x00,
0x3f,0xc1,0x81,0xe0,0x3f,0x3c,0x1f,0xe0,0x3c,0x78,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x1f,0xf1,0x81,0xe3,0xff,0x3c,0x1f,0xe0,0x3c,0x78,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x07,0xf9,0x81,0xe7,0xef,0x3c,0x1f,0xf0,0x3c,0x78,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x00,0xf9,0x81,0xef,0x07,0x3c,0x1e,0xf8,0x3c,0x78,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x78,0x79,0xc1,0xef,0x0f,0x3c,0x1e,0x78,0x3c,0x78,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x78,0x79,0xe3,0xcf,0x0f,0x3c,0x1e,0x3c,0x3c,0x7c,0xf3,0xc1,0xc0,0x00,0x00,0x00,
0x3f,0xf9,0xff,0xcf,0xff,0x3c,0x1e,0x3e,0x3c,0x7f,0xf3,0xc1,0xcf,0x00,0x00,0x00,
0x1f,0xf1,0xff,0x87,0xff,0x3c,0x1e,0x1e,0x3c,0x3f,0xf3,0xc1,0xc7,0x00,0x00,0x00,
0x07,0xc1,0x9e,0x03,0xe0,0x00,0x00,0x02,0x00,0x0e,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x00,0x00,0x00,0xc0,0x00,0x00,0x18,0x00,0x00,0x08,0x08,0x00,0x00,
0x00,0x01,0x87,0xc3,0x03,0xe0,0xe1,0xf0,0xf8,0x3e,0x33,0x08,0x3e,0x1e,0x00,0x00,
0x00,0x01,0x86,0x03,0x03,0x01,0xb0,0xe0,0xdc,0x66,0x3b,0x08,0x66,0x32,0x00,0x00,
0x00,0x00,0x87,0xc3,0x03,0xe1,0x80,0x40,0xd8,0x63,0x3b,0x08,0x60,0x3c,0x00,0x00,
0x00,0x00,0x87,0x83,0x03,0xc1,0x80,0x40,0xf8,0x63,0x3f,0x08,0x60,0x0e,0x00,0x00,
0x00,0x00,0x06,0x03,0x03,0x01,0xb0,0x40,0xd8,0x66,0x37,0x08,0x66,0x32,0x00,0x00,
0x00,0x00,0x07,0xc3,0xe3,0xe0,0xe0,0x40,0xc8,0x3e,0x33,0x08,0x3e,0x3e,0x00,0x00,
0x00,0x00,0x07,0xc3,0xe3,0xe0,0xe0,0x40,0x88,0x3c,0x33,0x08,0x3c,0x1e,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};

class LCDShield
{
private:
    void LCDCommand(unsigned char data);
    void LCDData(unsigned char data);
    uint8_t driver;

public:
    LCDShield();
    void init(int type);
    void clear(int color);
    void contrast(char setting);
    void setPixel(int color, unsigned char x, unsigned char y);
    void setCircle (int x0, int y0, int radius, int color);
    void setChar(char c, int x, int y, int fColor, int bColor);
    void setStr(char *pString, int x, int y, int fColor, int bColor);
    void setLine(int x0, int y0, int x1, int y1, int color);
    void setRect(int x0, int y0, int x1, int y1, unsigned char fill, int color);
    void printLogo(void);
    void on(void);
    void off(void);
};

#endif  // ColorLCDShield_H

colorLCDshield.cpp

      /*
        LCDShield.cpp - Arduino Library to control a Nokia 6100 LCD, 
        specifically that found on SparkFun's Color LCD Shield.
        This code should work for both Epson and Phillips display drivers 
        normally found on the Color LCD Shield.

        License: CC BY-SA 3.0: Creative Commons Share-alike 3.0. Feel free 
        to use and abuse this code however you'd like. If you find it useful
        please attribute, and SHARE-ALIKE!

        This is based on code by Mark Sproul, and Peter Davenport.
        Thanks to Coleman Sellers and Harold Timmis for help getting it to work with the Phillips Driver 7-31-2011
      */

      #include "Arduino.h"
      #include "ColorLCDShield.h"

      LCDShield::LCDShield()
      {
        DDRB = ((1<<LCD_CS)|(1<<LCD_DIO)|(1<<LCD_SCK)|(1<<LCD_RES));    //Set the control pins as outputs

        DDRD    =   0x00;
        PORTD   =   0xFF;
      }

      void LCDShield::LCDCommand(unsigned char data)
      {
        char jj;

        cbi(LCD_PORT_CS, LCD_CS);       // enable chip
        cbi(LCD_PORT_DIO, LCD_DIO);     // output low on data out (9th bit low = command)

        cbi(LCD_PORT_SCK, LCD_SCK);     // send clock pulse
        delayMicroseconds(1);
        sbi(LCD_PORT_SCK, LCD_SCK);

        for (jj = 0; jj < 8; jj++)
        {
            if ((data & 0x80) == 0x80)
                sbi(LCD_PORT_DIO, LCD_DIO);
            else
                cbi(LCD_PORT_DIO, LCD_DIO);

            cbi(LCD_PORT_SCK, LCD_SCK);     // send clock pulse
            delayMicroseconds(1);
            sbi(LCD_PORT_SCK, LCD_SCK);

            data <<= 1;
        }

        sbi(LCD_PORT_CS, LCD_CS);           // disable
      }

      void LCDShield::LCDData(unsigned char data)
      {
        char j;

        cbi(LCD_PORT_CS, LCD_CS);           // enable chip
        sbi(LCD_PORT_DIO, LCD_DIO);         // output high on data out (9th bit high = data)

        cbi(LCD_PORT_SCK, LCD_SCK);         // send clock pulse
        delayMicroseconds(1);
        sbi(LCD_PORT_SCK, LCD_SCK);         // send clock pulse

        for (j = 0; j < 8; j++)
        {
            if ((data & 0x80) == 0x80)
                sbi(LCD_PORT_DIO, LCD_DIO);
            else
                cbi(LCD_PORT_DIO, LCD_DIO);

            cbi(LCD_PORT_SCK, LCD_SCK);     // send clock pulse
            delayMicroseconds(1);
            sbi(LCD_PORT_SCK, LCD_SCK);

            data <<= 1;
        }

        LCD_PORT_CS |=  (1<<LCD_CS);        // disable
      }

      void LCDShield::init(int type)
      {
            //* setup the switches for input
        pinMode(kSwitch1_PIN, INPUT);
        pinMode(kSwitch2_PIN, INPUT);
        pinMode(kSwitch3_PIN, INPUT);

        //* set the pull up resisters
        digitalWrite(kSwitch1_PIN, HIGH);
        digitalWrite(kSwitch2_PIN, HIGH);
        digitalWrite(kSwitch3_PIN, HIGH);

      #ifdef _USE_ARDUINO_FOR_NOKIEA_

        //* do the LCD control lines
        pinMode(CS_PIN,         OUTPUT);
        pinMode(DIO_PIN,        OUTPUT);
        pinMode(SCK_PIN,        OUTPUT);
        pinMode(LCD_RES_PIN,    OUTPUT);

      #else
        DDRB    =   ((1<<CS)|(1<<DIO)|(1<<SCK)|(1<<LCD_RES));   //Set the control pins as outputs

        // USART Baud rate: 115200 (With 16 MHz Clock)
        UBRR0H  =   (MYUBRR >> 8) & 0x7F;   //Make sure highest bit(URSEL) is 0 indicating we are writing to UBRRH
        UBRR0L  =   MYUBRR;
        UCSR0A  =   (1<<U2X0);                  //Double the UART Speed
        UCSR0B  =   (1<<RXEN0)|(1<<TXEN0);      //Enable Rx and Tx in UART
        UCSR0C  =   (1<<UCSZ00)|(1<<UCSZ01);        //8-Bit Characters
      //    stdout  =   &mystdout; //Required for printf init
        cli();

        // Arduino D3-5 are button pins
        // This is PD3-5
        DDRD    =   0x00;
        PORTD   =   0xFF;

        // Init timer 2
        //Set Prescaler to 8. (Timer Frequency set to 16Mhz)
        //Used for delay routines
        TCCR2B  =   (1<<CS20);  //Divde clock by 1 for 16 Mhz Timer 2 Frequency 
      #endif

        driver = type;

        delay(200);

        cbi(LCD_PORT_SCK, LCD_SCK); //CLK = LOW
        cbi(LCD_PORT_DIO, LCD_DIO); //DIO = LOW
        delayMicroseconds(10);
        sbi(LCD_PORT_CS, LCD_CS);   //CS = HIGH
          delayMicroseconds(10);    
          cbi(LCD_PORT_RES, LCD_RES);   //RESET = LOW
        delay(200);
          sbi(LCD_PORT_RES, LCD_RES);   //RESET = HIGH
        delay(200);
        sbi(LCD_PORT_SCK, LCD_SCK); // SCK = HIGH
        sbi(LCD_PORT_DIO, LCD_DIO); // DIO = HIGH
        delayMicroseconds(10);

          LCDCommand(DISCTL);   // display control(EPSON)
          LCDData(0x0C);        // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
        LCDData(0x20);
        LCDData(0x00);
        LCDData(0x01);

          LCDCommand(COMSCN);   // common scanning direction(EPSON)
          LCDData(0x01);

          LCDCommand(OSCON);    // internal oscialltor ON(EPSON)

          LCDCommand(SLPOUT);   // sleep out(EPSON)
        LCDCommand(P_SLEEPOUT); //sleep out(PHILLIPS)

          LCDCommand(PWRCTR);   // power ctrl(EPSON)
          LCDData(0x0F);            //everything on, no external reference resistors
          LCDCommand(P_BSTRON);     //Booset On(PHILLIPS)

        LCDCommand(DISINV);     // invert display mode(EPSON)
        //LCDCommand(P_INVON);      // invert display mode(PHILLIPS)

          LCDCommand(DATCTL);   // data control(EPSON)
          LCDData(0x03);            //correct for normal sin7
        LCDData(0x00);          // normal RGB arrangement
        //LCDData(0x01);        // 8-bit Grayscale
        LCDData(0x05);          // 16-bit Grayscale Type A

        LCDCommand(P_MADCTL);       //Set Color Mode(PHILLIPS)
        LCDData(0x00);  

        LCDCommand(P_COLMOD);       //Memory Access Control(PHILLIPS)
        LCDData(0x03);

          LCDCommand(VOLCTR);   // electronic volume, this is the contrast/brightness(EPSON)
          //LCDData(0x18);          // volume (contrast) setting - fine tuning, original
        LCDData(0x24);          // volume (contrast) setting - fine tuning, original
          LCDData(0x03);        // internal resistor ratio - coarse adjustment
        LCDCommand(P_SETCON);       //Set Contrast(PHILLIPS)
        LCDData(0x30);  

          LCDCommand(NOP);      // nop(EPSON)
        LCDCommand(P_NOP);      // nop(PHILLIPS)

        delayMicroseconds(200);

          LCDCommand(DISON);    // display on(EPSON)
        LCDCommand(P_DISPON);   // display on(PHILLIPS)
      }

      void LCDShield::clear(int color)
      {
        if (driver) // if it's an Epson
        {
            LCDCommand(PASET);
            LCDData(0);
            LCDData(131);

            LCDCommand(CASET);
            LCDData(0);
            LCDData(131);

            LCDCommand(RAMWR);
        }
        else    // otherwise it's a phillips
        {
            LCDCommand(P_PASET);
            LCDData(0);
            LCDData(131);

            LCDCommand(P_CASET);
            LCDData(0);
            LCDData(131);

            LCDCommand(P_RAMWR);
            LCDData((unsigned char)((color>>4)&0x00FF));
            LCDData((unsigned char)(((color&0x0F)<<4)|0x00));

        }

        for(unsigned int i=0; i < (131*131)/2; i++)
        {
            LCDData((color>>4)&0x00FF);
            LCDData(((color&0x0F)<<4)|(color>>8));
            LCDData(color&0x0FF);   // nop(EPSON)
        }

        x_offset = 0;
        y_offset = 0;
      }

      void LCDShield::contrast(char setting)
      {
           LCDCommand(VOLCTR);        // electronic volume, this is the contrast/brightness(EPSON)
           LCDData(setting);        // volume (contrast) setting - course adjustment,  -- original was 24

           LCDCommand(NOP);        // nop(EPSON)
      }

      void LCDShield::setPixel(int color, unsigned char x, unsigned char y)
      {
        y   =   (COL_HEIGHT - 1) - y;
              x       =       (ROW_LENGTH - 1) - x;

        if (driver) // if it's an epson
        {
            LCDCommand(PASET);  // page start/end ram
            LCDData(x);
            LCDData(ENDPAGE);

            LCDCommand(CASET);  // column start/end ram
            LCDData(y);
            LCDData(ENDCOL);

            LCDCommand(RAMWR);  // write
            LCDData((color>>4)&0x00FF);
            LCDData(((color&0x0F)<<4)|(color>>8));
            LCDData(color&0x0FF);       // nop(EPSON)       
            //LCDData(color);
            //LCDData(NOP);
            //LCDData(NOP);
        }
        else    // otherwise it's a phillips
        {
            LCDCommand(PASETP); // page start/end ram
            LCDData(x);
            LCDData(x);
            //LCDData(ENDPAGE);

            LCDCommand(CASETP); // column start/end ram
            LCDData(y);
            LCDData(y);
            //LCDData(ENDCOL);

            LCDCommand(RAMWRP); // write

            LCDData((unsigned char)((color>>4)&0x00FF));
            LCDData((unsigned char)(((color&0x0F)<<4)|0x00));
            //LCDData(NOP);
        }
      }

      void LCDShield::setCircle (int x0, int y0, int radius, int color)
      {
        int f = 1 - radius;
        int ddF_x = 0;
        int ddF_y = -2 * radius;
        int x = 0;
        int y = radius;

        setPixel(color, x0, y0 + radius);
        setPixel(color, x0, y0 - radius);
        setPixel(color, x0 + radius, y0);
        setPixel(color, x0 - radius, y0);

        while(x < y)
        {
            if(f >= 0)
            {
                y--;
                ddF_y += 2;
                f += ddF_y;
            }
            x++;
            ddF_x += 2;
            f += ddF_x + 1;

            setPixel(color, x0 + x, y0 + y);
            setPixel(color, x0 - x, y0 + y);
            setPixel(color, x0 + x, y0 - y);
            setPixel(color, x0 - x, y0 - y);
            setPixel(color, x0 + y, y0 + x);
            setPixel(color, x0 - y, y0 + x);
            setPixel(color, x0 + y, y0 - x);
            setPixel(color, x0 - y, y0 - x);
        }
      }

      void LCDShield::setChar(char c, int x, int y, int fColor, int bColor)
      {
        y   =   (COL_HEIGHT - 1) - y; // make display "right" side up
        x   =   (ROW_LENGTH - 2) - x;

        int             i,j;
        unsigned int    nCols;
        unsigned int    nRows;
        unsigned int    nBytes;
        unsigned char   PixelRow;
        unsigned char   Mask;
        unsigned int    Word0;
        unsigned int    Word1;
        unsigned char   *pFont;
        unsigned char   *pChar;

        // get pointer to the beginning of the selected font table
        pFont = (unsigned char *)FONT8x16;              
        // get the nColumns, nRows and nBytes
        nCols = *pFont;
        nRows = *(pFont + 1);
        nBytes = *(pFont + 2);
        // get pointer to the last byte of the desired character
        pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;

        if (driver) // if it's an epson
        {                   
            // Row address set (command 0x2B)
            LCDCommand(PASET);
            LCDData(x);
            LCDData(x + nRows - 1);
            // Column address set (command 0x2A)
            LCDCommand(CASET);
            LCDData(y);
            LCDData(y + nCols - 1);

            // WRITE MEMORY
            LCDCommand(RAMWR);
            // loop on each row, working backwards from the bottom to the top
            for (i = nRows - 1; i >= 0; i--) {
                // copy pixel row from font table and then decrement row
                PixelRow = *pChar++;
                // loop on each pixel in the row (left to right)
                // Note: we do two pixels each loop
                Mask = 0x80;
                for (j = 0; j < nCols; j += 2) 
                {
                    // if pixel bit set, use foreground color; else use the background color
                    // now get the pixel color for two successive pixels
                    if ((PixelRow & Mask) == 0)
                        Word0 = bColor;
                    else
                        Word0 = fColor;
                    Mask = Mask >> 1;
                    if ((PixelRow & Mask) == 0)
                        Word1 = bColor;
                    else
                        Word1 = fColor;
                    Mask = Mask >> 1;
                    // use this information to output three data bytes
                    LCDData((Word0 >> 4) & 0xFF);
                    LCDData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
                    LCDData(Word1 & 0xFF);
                }
            }
        }
        else
        {
            // Row address set (command 0x2B)
            LCDCommand(PASETP);
            LCDData(x);
            LCDData(x + nRows - 1);
            // Column address set (command 0x2A)
            LCDCommand(CASETP);
            LCDData(y);
            LCDData(y + nCols - 1);

            // WRITE MEMORY
            LCDCommand(RAMWRP);
            // loop on each row, working backwards from the bottom to the top
            pChar+=nBytes-1;    // stick pChar at the end of the row - gonna reverse print on phillips
            for (i = nRows - 1; i >= 0; i--) {
                // copy pixel row from font table and then decrement row
                PixelRow = *pChar--;
                // loop on each pixel in the row (left to right)
                // Note: we do two pixels each loop
                Mask = 0x01;    // <- opposite of epson
                for (j = 0; j < nCols; j += 2) 
                {
                    // if pixel bit set, use foreground color; else use the background color
                    // now get the pixel color for two successive pixels
                    if ((PixelRow & Mask) == 0)
                        Word0 = bColor;
                    else
                        Word0 = fColor;
                    Mask = Mask << 1;   // <- opposite of epson
                    if ((PixelRow & Mask) == 0)
                        Word1 = bColor;
                    else
                        Word1 = fColor;
                    Mask = Mask << 1;   // <- opposite of epson
                    // use this information to output three data bytes
                    LCDData((Word0 >> 4) & 0xFF);
                    LCDData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
                    LCDData(Word1 & 0xFF);
                }
            }
        }
      }

      void LCDShield::setStr(char *pString, int x, int y, int fColor, int bColor)
      {
        x = x + 16;
        y = y + 8;
        // loop until null-terminator is seen
        while (*pString != 0x00) {
          // draw the character
          setChar(*pString++, x, y, fColor, bColor);
          // advance the y position
          y = y + 8;
          // bail out if y exceeds 131
          if (y > 131) break;
        }
      }

      void LCDShield::setLine(int x0, int y0, int x1, int y1, int color)
      {
        int dy = y1 - y0;// Difference between y0 and y1
        int dx = x1 - x0;// Difference between x0 and x1
        int stepx, stepy;

        if (dy < 0)
        {
            dy = -dy; 
            stepy = -1;
        }
        else
            stepy = 1;

        if (dx < 0)
        {
            dx = -dx;
            stepx = -1;
        }
        else
            stepx = 1;

        dy <<= 1;// dy is now 2*dy
        dx <<= 1;// dx is now 2*dx
        setPixel(color, x0, y0);

        if (dx > dy) 
        {
            int fraction = dy - (dx >> 1);
            while (x0 != x1) 
            {
                if (fraction >= 0) 
                {
                    y0 += stepy;
                    fraction -= dx;
                }
                x0 += stepx;
                fraction += dy;
                setPixel(color, x0, y0);
            }
        } 
        else 
        {
            int fraction = dx - (dy >> 1);
            while (y0 != y1) 
            {
                if (fraction >= 0) 
                {
                    x0 += stepx;
                    fraction -= dy;
                }
            y0 += stepy;
            fraction += dx;
            setPixel(color, x0, y0);
            }
        }
      }

      void LCDShield::setRect(int x0, int y0, int x1, int y1, unsigned char fill, int color)
      {
        // check if the rectangle is to be filled
        if (fill == 1) 
        {
            int xDiff;

            if(x0 > x1)
              xDiff = x0 - x1; //Find the difference between the x vars
            else
              xDiff = x1 - x0;

            while(xDiff > 0)
            {
                setLine(x0, y0, x0, y1, color);

                if(x0 > x1)
                  x0--;
                else
                  x0++;

                xDiff--;
            }

        }
        else 
        {
            // best way to draw an unfilled rectangle is to draw four lines
            setLine(x0, y0, x1, y0, color);
            setLine(x0, y1, x1, y1, color);
            setLine(x0, y0, x0, y1, color);
            setLine(x1, y0, x1, y1, color);
        }
      }

      void LCDShield::printLogo(void)
      {
          int x = 4, y = 25, logo_ix = 0, z;
          char logo;

          for (logo_ix = 0; logo_ix < 1120; logo_ix++)
          {
              logo = logo_spark[logo_ix];
            for (z = 0; z < 8; z++)
              {
                  if ((logo & 0x80) == 0x80) setPixel(RED, y, x);
                  x++;
                  if (x == 132)
                  {
                      x = 4;
                      y++;
                  }

                  logo <<= 1;
              }
          }

      }

      void LCDShield::off(void)
      {
        if (driver) // If it's an epson
            LCDCommand(DISOFF);
        else // otherwise it's a phillips
            LCDCommand(DISPOFF);
      }

      void LCDShield::on(void)
      {
        if (driver) // If it's an epson
            LCDCommand(DISON);
        else // otherwise it's a phillips
            LCDCommand(DISPON);
      }
eagle00789 commented 12 years ago

i don't use that much git and to fork it and stuff takes to much time....

stevesparks commented 11 years ago

What was your actual change? We merged in some Philips changes today, maybe its better now...

ToniCorinne commented 11 years ago

Closing this issue due to a lack of response from OP.