|
/* |
|
September 5th, 2011 |
|
Wade Smith |
|
Based on code by Nathan Seidle |
|
|
|
This code is free and open, like NyanCat |
|
Written for the Nokia 5110 84×48 graphic LCD: |
|
http://www.sparkfun.com/products/10168 |
|
http://www.adafruit.com/products/338 |
|
*/ |
|
|
|
#define PIN_SCE 7 |
|
#define PIN_RESET 6 |
|
#define PIN_DC 5 |
|
#define PIN_SDIN 4 |
|
#define PIN_SCLK 3 |
|
|
|
//The DC pin tells the LCD if we are sending a command or data |
|
#define LCD_COMMAND 0 |
|
#define LCD_DATA 1 |
|
|
|
//You may find a different size screen, but this one is 84 by 48 pixels |
|
#define LCD_X 84 |
|
#define LCD_Y 48 |
|
|
|
char hhmx[] = { |
|
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, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, |
|
0x80, 0x80, 0x80, 0x80, 0xFC, 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
0x00, 0x00, 0x00, 0x80, 0x80, 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, 0x01, 0x03, 0x07, 0xC6, 0xF0, 0x38, 0x1C, |
|
0x0E, 0xC7, 0xE3, 0x63, 0xE1, 0xC1, 0xE1, 0x78, 0x18, 0x18, 0x78, 0xE1, 0xC1, 0xE1, 0x63, 0xE3, |
|
0xC7, 0x0E, 0x1C, 0x38, 0xF6, 0xC7, 0x03, 0x01, 0x01, 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, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0xFF, |
|
0xFF, 0x00, 0x00, 0x78, 0x78, 0xD9, 0xDF, 0x8F, 0x00, 0x00, 0xF8, 0xDC, 0x8C, 0x8C, 0xDC, 0xFC, |
|
0x20, 0x00, 0x87, 0xCF, 0xD9, 0x78, 0x78, 0x00, 0x00, 0xFF, 0xFF, 0x30, 0x30, 0x30, 0x30, 0x30, |
|
0x10, 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, 0x07, 0x0F, 0x3C, 0x70, 0xE0, 0x8C, 0x1F, 0x3B, 0x18, 0x1C, 0x1E, 0x0F, |
|
0x01, 0x01, 0x07, 0x1E, 0x0C, 0x18, 0x3B, 0x1F, 0x8E, 0xE0, 0xF0, 0x3C, 0x0F, 0x07, 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, 0x01, 0x8F, 0xFE, 0xF0, |
|
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFE, 0x9F, 0x03, 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, |
|
0x01, 0x03, 0x3B, 0x3B, 0x3B, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0x3B, 0x3B, 0x3B, |
|
0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
}; |
|
|
|
|
|
void setup(void) { |
|
LCDInit(); //Init the LCD |
|
} |
|
|
|
void loop(void) { |
|
LCDBitmap(hhmx); |
|
} |
|
|
|
void gotoXY(int x, int y) { |
|
LCDWrite(0, 0x80 | x); // Column. |
|
LCDWrite(0, 0x40 | y); // Row. ? |
|
} |
|
|
|
void LCDBitmap(char my_array[]){ |
|
for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) |
|
LCDWrite(LCD_DATA, my_array[index]); |
|
} |
|
|
|
void LCDClear(void) { |
|
for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) |
|
LCDWrite(LCD_DATA, 0x00); |
|
|
|
gotoXY(0, 0); |
|
} |
|
|
|
//This sends the magical commands to the PCD8544 |
|
void LCDInit(void) { |
|
|
|
//Configure control pins |
|
pinMode(PIN_SCE, OUTPUT); |
|
pinMode(PIN_RESET, OUTPUT); |
|
pinMode(PIN_DC, OUTPUT); |
|
pinMode(PIN_SDIN, OUTPUT); |
|
pinMode(PIN_SCLK, OUTPUT); |
|
|
|
//Reset the LCD to a known state |
|
digitalWrite(PIN_RESET, LOW); |
|
digitalWrite(PIN_RESET, HIGH); |
|
|
|
LCDWrite(LCD_COMMAND, 0x21); //Tell LCD that extended commands follow |
|
LCDWrite(LCD_COMMAND, 0xB0); //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark |
|
LCDWrite(LCD_COMMAND, 0x04); //Set Temp coefficent |
|
LCDWrite(LCD_COMMAND, 0x14); //LCD bias mode 1:48: Try 0x13 or 0x14 |
|
|
|
LCDWrite(LCD_COMMAND, 0x20); //We must send 0x20 before modifying the display control mode |
|
LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse |
|
} |
|
|
|
//There are two memory banks in the LCD, data/RAM and commands. This |
|
//function sets the DC pin high or low depending, and then sends |
|
//the data byte |
|
void LCDWrite(byte data_or_command, byte data) { |
|
digitalWrite(PIN_DC, data_or_command); //Tell the LCD that we are writing either to data or a command |
|
|
|
//Send the data |
|
digitalWrite(PIN_SCE, LOW); |
|
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data); |
|
digitalWrite(PIN_SCE, HIGH); |
|
} |