Project C accelerometer

Fork of N5110 by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Sun Jan 26 19:30:09 2014 +0000
Parent:
0:d563e74f0ae9
Child:
2:e93021cfb0a9
Commit message:
Started to add documentation. This commit is to test the publishing and documentation.

Changed in this revision

N5110.cpp Show annotated file Show diff for this revision Revisions of this file
N5110.h Show annotated file Show diff for this revision Revisions of this file
--- a/N5110.cpp	Sun Jan 26 18:55:16 2014 +0000
+++ b/N5110.cpp	Sun Jan 26 19:30:09 2014 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "N5110.h"
 
-N5110::N5110(PinName pwrPin, PinName ledPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin)
+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
@@ -18,24 +18,36 @@
 void N5110::init()
 {
     turnOn();    // power up
-    reset();     // reset LCD
+    reset();     // reset LCD - must be done within 100 ms
 
     // function set - extended
     sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_EXTENDED_MODE);
 
-    sendCommand(CMD_VOP_7V38);    // operating voltage
+    sendCommand(CMD_VOP_7V38);    // operating voltage - these values are from Chris Yan's Library
     sendCommand(CMD_TC_TEMP_2);   // temperature control
     sendCommand(CMD_BI_MUX_48);   // bias
 
     // function set - basic
     sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_BASIC_MODE);
+    normalMode();  // normal video mode by default
     sendCommand(CMD_DC_NORMAL_MODE);  // black on white
-    //sendLCDCommand(CMD_DC_INVERT_VIDEO);  // white on black
+    //sendCommand(CMD_DC_INVERT_VIDEO);  // white on black
 
     // RAM is undefined at power-up so clear
     clearRAM();
 
 }
+ 
+// sets normal video mode (black on white) 
+void N5110::normalMode() {
+     sendCommand(CMD_DC_NORMAL_MODE);  
+   
+}
+
+// sets normal video mode (white on black) 
+void N5110::inverseMode() {
+    sendCommand(CMD_DC_INVERT_VIDEO); 
+}
 
 // function to power up the LCD and backlight
 void N5110::turnOn()
@@ -183,6 +195,8 @@
         sendData(font5x7[(c - 32)*5 + j]);
         // array is offset by 32 relative to ASCII, each character is 5 pixels wide
     }
+    
+    sendData(0); // send an empty byte to introduce space between characters
 
 }
 
--- 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;
 
 };