A basic LCD output test which uses the NXP LPC1768\'s SPI interface to display pixels, characters, and numbers on the Nokia 5110 or Nokia 3310 LCD.

Dependencies:   mbed NOKIA_5110

Quick and versatile LCD screen control. Works as a great alternative to serial consoles!

---------

/media/uploads/Fuzball/debug_gui_1.jpg

Inverted-color text function makes easy menus and borders

/media/uploads/Fuzball/oscil_1.jpg

Uses a simple SetXY(char, char) function to draw data-plots or patterns

- Wiring -

/media/uploads/Fuzball/debug_gui_2.jpg

LCD's connections from left to right:

1) +3.3v (V_lcd) - mbed's VOUT

2) GND - mbed's GND

3) SCE (chip select) - mbed's p8

4) RST (reset) - mbed's p9

5) DC (data/command) - mbed's p10

6) MOSI - mbed's p11

7) SCLK (serial clock) - mbed's p13

8) +3.3v (V_backlight) - mbed's VOUT

The code for this setup would be...

LcdPins myPins;

myPins.sce = p8;

myPins.rst = p9;

myPins.dc = p10;

myPins.mosi = p11;

myPins.miso = NC;

myPins.sclk = p13;

or more easily...

LcdPins myPins = { p11, NC, p13, p10, p8, p9 };

Init the NokiaLcd class using the above struct...

NokiaLcd myLcd( myPins );

then start the LCD using...

myLcd.InitLcd();

Simple text output is achieved with either of these functions:

void DrawString(char* str);

void DrawChar(char character);

------

Better documentation, pre/post conditions, and extended draw functions are coming soon :)

Revision:
3:41063eb2a040
Parent:
1:e25ab356dc9b
--- a/NOKIA_5110.h	Fri Jan 10 19:57:40 2014 +0000
+++ b/NOKIA_5110.h	Fri Jan 10 22:22:17 2014 +0000
@@ -2,7 +2,7 @@
 // File: NOKIA_5110.h
 // Author: Chris Yan
 // Created: January, 2012
-// Revised: 
+// Revised: January, 2014
 //  Desc: Commands, fonts, and class for using a
 //      Nokia 5110 LCD via the Phillips 8554 LCD driver.
 // 
@@ -36,6 +36,11 @@
 
 // Command Instructions
 //       H = 0
+#ifndef __NOKIA_5110_H__
+#define __NOKIA_5110_H__
+
+// Command Instructions
+//       H = 0
 #define CMD_DC_CLEAR_DISPLAY   0x08
 #define CMD_DC_NORMAL_MODE     0x0C
 #define CMD_DC_FILL_DISPLAY    0x09
@@ -58,9 +63,11 @@
 #define CMD_VOP_7V38           0xC8
 
 // LCD Characteristics
-#define LCD_FREQ 4000000
+#define LCD_FREQ 2000000
 #define LCD_SPI_MODE 0x01
 #define LCD_SPI_BITS 0x08
+#define LCD_X_MAX 84
+#define LCD_Y_MAX 48
 
 #define PIN_RST  0x00
 #define PIN_SCE  0x01
@@ -102,11 +109,17 @@
         void ClearLcdMem();
         void ShutdownLcd();
         void SendFunction(char cmd);
-
         void TestLcd(char test_pattern);
+        void SendDrawData(char data);
+        
+    public:
+        void DrawString(char* str);
         void DrawChar(char character);
-        void SendDrawData(char data);
-
+        void SetXY(char x, char y);
+        void DrawFrameChar(char character);
+        void DrawNegFrameChar(char character);
+        char* NumToStr(int num);
+        
     private:
         char CreateFunctionChar();
         void ResetLcd();
@@ -217,7 +230,9 @@
  0x2C, 0x30, 0x1C, 0x00, 0x00, 0x00, // y   90
  0x24, 0x34, 0x2C, 0x24, 0x00, 0x00, // z
  0x00, 0x00, 0x08, 0x3E, 0x22, 0x00, // {
- 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, // |
+ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, // |
  0x22, 0x3E, 0x08, 0x00, 0x00, 0x00, // }
  0x10, 0x08, 0x18, 0x10, 0x08, 0x00, // ~   95
 };
+
+#endif