Simple library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website). - koristen softverski SPI umjesto hardverskog

Dependents:   Nokia_FRDM

Fork of N5110 by Craig Evans

Embed: (wiki syntax)

« Back to documentation index

N5110 Class Reference

N5110 Class Reference

Simple library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed. More...

#include <N5110.h>

Public Member Functions

 N5110 (PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
 Create a N5110 object connected to the specified pins.
void init ()
 Initialise display.
void turnOff ()
 Turn off.
void clear ()
 Clears.
void normalMode ()
 Turn on normal video mode (default) Black on white.
void inverseMode ()
 Turn on inverse video mode (default) White on black.
void setBrightness (float brightness)
 Set Brightness.
void setXYAddress (int x, int y)
 Set XY Address.
void printString (const char *str, int x, int y)
 Print String.
void printChar (char c)
 Print Character.
void setPixel (int x, int y)
 Set a Pixel.
void clearPixel (int x, int y)
 Clear a Pixel.
unsigned char getPixel (int x, int y)
 Get a Pixel.
void refresh ()
 Refresh display.
void randomiseBuffer ()
 Randomise buffer.

Detailed Description

Simple library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed.

The display is powered from a GPIO pin meaning it can be controlled via software. The LED backlight is also software-controllable (via PWM pin). Can print characters and strings to the display using the included 5x7 font. The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read.

Acknowledgements to Chris Yan's Nokia_5110 Library.

Revision 1.0

Author:
Craig A. Evans
Date:
January 2014

Example:

 #include "mbed.h"
 #include "N5110.h"
 
  //    VCC,SCE,RST,D/C,MOSI,SCLK,LED
 N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
 
 int main() {
    
   // initialise display 
  lcd.init();
  // print a string in top-left corner
  lcd.printString("Hello, World!",0,0);
  // move cursor to 4th row
  lcd.setXYAddress(0,3);
  // print character
  lcd.printChar('X');
    
  while(1);
 }

Definition at line 77 of file N5110.h.


Constructor & Destructor Documentation

N5110 ( PinName  pwrPin,
PinName  scePin,
PinName  rstPin,
PinName  dcPin,
PinName  mosiPin,
PinName  sclkPin,
PinName  ledPin 
)

Create a N5110 object connected to the specified pins.

Parameters:
pwrPin connected to Vcc on the LCD display (pin 1)
scePin connected to chip enable (pin 3)
rstPin connected to reset (pin 4)
dcPin connected to data/command select (pin 5)
mosiPin connected to data input (MOSI) (pin 6)
sclkPin connected to serial clock (SCLK) (pin 7)
ledPin connected to LED backlight (must be PWM) (pin 8)

Definition at line 11 of file N5110.cpp.


Member Function Documentation

void clear (  )

Clears.

Clears the screen.

Definition at line 248 of file N5110.cpp.

void clearPixel ( int  x,
int  y 
)

Clear a Pixel.

This function clears pixel in the display. A call to refresh() must be made to update the display to reflect the change in pixels.

Parameters:
x- the x co-ordinate of the pixel (0 to 83)
y- the y co-ordinate of the pixel (0 to 47)

Definition at line 177 of file N5110.cpp.

unsigned char getPixel ( int  x,
int  y 
)

Get a Pixel.

This function gets the status of a pixel in the display.

Parameters:
x- the x co-ordinate of the pixel (0 to 83)
y- the y co-ordinate of the pixel (0 to 47)
Returns:
0 - pixel is clear non-zero - pixel is set

Definition at line 183 of file N5110.cpp.

void init (  )

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.

Definition at line 29 of file N5110.cpp.

void inverseMode (  )

Turn on inverse video mode (default) White on black.

Definition at line 60 of file N5110.cpp.

void normalMode (  )

Turn on normal video mode (default) Black on white.

Definition at line 54 of file N5110.cpp.

void printChar ( char  c )

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.

Parameters:
c- the character to print. Can print ASCII as so printChar('C').

Definition at line 219 of file N5110.cpp.

void printString ( const char *  str,
int  x,
int  y 
)

Print String.

Prints a string of characters to the display.

Parameters:
x- the column number (0 to 83)
y- the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row

Definition at line 233 of file N5110.cpp.

void randomiseBuffer (  )

Randomise buffer.

This function fills the buffer with random data. Can be used to test the display. A call to refresh() must be made to update the display to reflect the change in pixels. The seed is not set and so the generated pattern will probably be the same each time. TODO: Randomise the seed - maybe using the noise on the AnalogIn pins.

Definition at line 207 of file N5110.cpp.

void refresh (  )

Refresh display.

This functions refreshes the display to reflect the current data in the buffer.

Definition at line 191 of file N5110.cpp.

void setBrightness ( float  brightness )

Set Brightness.

Sets brightness of LED backlight.

Parameters:
brightness- float in range 0.0 to 1.0

Definition at line 90 of file N5110.cpp.

void setPixel ( int  x,
int  y 
)

Set a Pixel.

This function sets a pixel in the display. A call to refresh() must be made to update the display to reflect the change in pixels.

Parameters:
x- the x co-ordinate of the pixel (0 to 83)
y- the y co-ordinate of the pixel (0 to 47)

Definition at line 171 of file N5110.cpp.

void setXYAddress ( int  x,
int  y 
)

Set XY Address.

Sets the X and Y address of where the next data sent to the displa will be written in RAM.

Parameters:
x- the column number (0 to 83) - is automatically incremented after data is written
y- the row number (0 to 5) - the diplay is split into 6 banks - each bank can be considered a row

Definition at line 152 of file N5110.cpp.

void turnOff (  )

Turn off.

Powers down the display and turns of the backlight. Needs to be reinitialised before being re-used.

Definition at line 73 of file N5110.cpp.