Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: N5110.h
- Revision:
- 1:df68f34cd32d
- Parent:
- 0:d563e74f0ae9
- Child:
- 2:e93021cfb0a9
diff -r d563e74f0ae9 -r df68f34cd32d N5110.h
--- a/N5110.h Sun Jan 26 18:55:16 2014 +0000
+++ b/N5110.h Sun Jan 26 19:30:09 2014 +0000
@@ -1,8 +1,7 @@
-/*
+/**
+
Simple library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168)
-Uses PCD8544 Controller - 48 rows, 84 columns
-
Chris Yan's Nokia5110 Library proved a useful starting point.
Revision 1.0
@@ -40,43 +39,103 @@
#include "mbed.h"
-class N5110 {
-
- public:
- /** Create instance of N5110 LCD with specified pins */
- N5110(PinName pwr, PinName led, PinName sce, PinName rst, PinName dc, PinName mosi, PinName sclk);
- void init();
- void turnOff();
- void clear();
- void setBrightness(float brightness);
- void setXYAddress(int x, int y);
- void printString(const char * str,int x,int y);
- void printChar(char c);
- void setPixel(int x, int y);
- void clearPixel(int x, int y);
- unsigned char getPixel(int x, int y);
- void refreshDisplay();
- void clearBuffer();
- void randomiseBuffer();
+class N5110
+{
- private:
- void initSPI();
- void turnOn();
- void reset();
- void clearRAM();
- void sendCommand(unsigned char command);
- void sendData(unsigned char data);
-
- public:
- unsigned char buffer[84][6]; // screen buffer - the 6 is for the banks - each one is 8 bits;
-
- private: // private variables
- SPI* spi;
- PwmOut* led;
- DigitalOut* pwr;
- DigitalOut* sce;
- DigitalOut* rst;
- DigitalOut* dc;
+public:
+ /** Create a N5110 object connected to the specified pins
+ *
+ * @param pwr Pin connected to Vcc on the LCD display (pin 1)
+ * @param sce Pin connected to chip enable (pin 3)
+ * @param rst Pin connected to reset (pin 4)
+ * @param dc Pin connected to data/command select (pin 5)
+ * @param mosi Pin connected to data input (MOSI) (pin 6)
+ * @param sclk Pin connected to serial clock (SCLK) (pin 7)
+ * @param led Pin connected to LED backlight (must be PWM) (pin 8)
+ *
+ */
+ N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin);
+
+ /** Initialise display
+ *
+ * Powers up the display and turns on backlight (50% brightness default).
+ * Sets the display up in horizontal addressing mode and with normal video mode.
+ */
+ void init();
+
+ /** Turn off
+ *
+ * Powers down the display and turns of the backlight.
+ * Needs to be reinitialised before being re-used.
+ */
+ void turnOff();
+
+ /** Clears
+ *
+ * Clears the screen.
+ */
+ void clear();
+
+ /** Turn on normal video mode (default)
+ * Black on white
+ */
+ void normalMode();
+
+ /** Turn on inverse video mode (default)
+ * White on black
+ */
+ void inverseMode();
+
+ /** Set Brightness
+ *
+ * Sets brightness of LED backlight.
+ * @param brightness - float in range 0.0 to 1.0
+ */
+ void setBrightness(float brightness);
+
+ /** Set XY Address
+ *
+ * Sets the X and Y address of where the next data sent to the displa will be written in RAM.
+ * @param x - the column number (0 to 83) - is automatically incremented after data is written
+ * @param y - the row number - the diplay is split into 6 banks - each bank can be considered a row
+ */
+ void setXYAddress(int x, int y);
+
+ void printString(const char * str,int x,int y);
+
+ /** Print Character
+ *
+ * Sends a character to the display. Will be printed at the current address.
+ * X address is autoincremented by 1 to leave a pixel between successive characters
+ * @param c - the character to print. Can print ASCII as so printChar('C').
+ */
+ void printChar(char c);
+
+ void setPixel(int x, int y);
+ void clearPixel(int x, int y);
+ unsigned char getPixel(int x, int y);
+ void refreshDisplay();
+ void clearBuffer();
+ void randomiseBuffer();
+
+private:
+ void initSPI();
+ void turnOn();
+ void reset();
+ void clearRAM();
+ void sendCommand(unsigned char command);
+ void sendData(unsigned char data);
+
+public:
+ unsigned char buffer[84][6]; // screen buffer - the 6 is for the banks - each one is 8 bits;
+
+private: // private variables
+ SPI* spi;
+ PwmOut* led;
+ DigitalOut* pwr;
+ DigitalOut* sce;
+ DigitalOut* rst;
+ DigitalOut* dc;
};