Library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website).

Dependents:   LV7_LCDtest LV7_Grupa5_Tim003_Zadatak1 lv7_Grupa5_Tim008_zad1 LV7_PAI_Grupa5_tim10_Zadatak1 ... more

This library is designed to make it easy to interface an mbed with a Nokia 5110 LCD display.

These can be found at Sparkfun (https://www.sparkfun.com/products/10168) and Adafruit (http://www.adafruit.com/product/338).

The library uses the SPI peripheral on the mbed which means it is much faster sending data to the display than other libraries available on other platforms that use software SPI.

The library can print strings as well as controlling individual pixels, meaning that both text and primitive graphics can be displayed.

Revision:
21:4cbdc20fea9f
Parent:
20:8db6aa25f55e
Child:
22:31c54fc61f12
--- a/N5110.cpp	Thu Jan 19 19:42:34 2017 +0000
+++ b/N5110.cpp	Sat Jan 28 20:25:43 2017 +0000
@@ -7,10 +7,11 @@
 #include "mbed.h"
 #include "N5110.h"
 
-
+// overloaded constructor includes power pin - LCD Vcc connected to GPIO pin
+// this constructor works fine with LPC1768 - enough current sourced from GPIO
+// to power LCD. Doesn't work well with K64F.
 N5110::N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
 {
-
     spi = new SPI(mosiPin,NC,sclkPin); // create new SPI instance and initialise
     initSPI();
 
@@ -23,6 +24,22 @@
 
 }
 
+// overloaded constructor does not include power pin - LCD Vcc must be tied to +3V3
+// Best to use this with K64F as the GPIO hasn't sufficient output current to reliably
+// drive the LCD.
+N5110::N5110(PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
+{
+    spi = new SPI(mosiPin,NC,sclkPin); // create new SPI instance and initialise
+    initSPI();
+
+    // set up pins as required
+    led = new PwmOut(ledPin);
+    sce = new DigitalOut(scePin);
+    rst = new DigitalOut(rstPin);
+    dc = new DigitalOut(dcPin);
+
+}
+
 // initialise function - powers up and sends the initialisation commands
 void N5110::init()
 {
@@ -66,7 +83,12 @@
 {
     // set brightness of LED - 0.0 to 1.0 - default is 50%
     setBrightness(0.5);
-    pwr->write(1);  // apply power
+
+    // if we are powering the LCD using the GPIO then make it high to turn on
+    // DigitalOut pointer won't be NULL if we used the constructor with power pin
+    if (pwr != NULL) {
+        pwr->write(1);  // apply power
+    }
 }
 
 // function to power down LCD
@@ -82,7 +104,12 @@
     sendCommand(0x20 | CMD_FS_POWER_DOWN_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_EXTENDED_MODE);
     // small delay and then turn off the power pin
     wait_ms(10);
-    pwr->write(0);
+    
+    // if we are powering the LCD using the GPIO then make it low to turn off
+    // DigitalOut pointer won't be NULL if we used the constructor with power pin
+    if (pwr != NULL) {
+        pwr->write(0);  // turn off power
+    }
 
 }
 
@@ -291,7 +318,7 @@
         // elements are normalised from 0.0 to 1.0, so multiply
         // by 47 to convert to pixel range, and subtract from 47
         // since top-left is 0,0 in the display geometry
-        setPixel(i,47 - int(array[i]*47.0));
+        setPixel(i,47 - int(array[i]*47.0f));
     }
 
     refresh();