A fork of Chris Yan's Nokia 5110 LCD library, adapted to LPC1347. Should work on a DipCortex M3 and an EzSBC2 dev board.

Dependencies:   mbed

Fork of Nokia5110 by Krissi Yan

Revision:
3:41063eb2a040
Parent:
1:e25ab356dc9b
Child:
4:46e538ce39d4
--- a/NOKIA_5110.cpp	Fri Jan 10 19:57:40 2014 +0000
+++ b/NOKIA_5110.cpp	Fri Jan 10 22:22:17 2014 +0000
@@ -2,7 +2,7 @@
 // File: NOKIA_5110.cpp
 // Author: Chris Yan
 // Created: January, 2012
-// Revised: 
+// Revised: January, 2014
 //  Desc: Supporting code for the NokiaLcd class
 
 #include "NOKIA_5110.h"
@@ -44,29 +44,20 @@
 
 void NokiaLcd::ClearLcdMem()
 {
-    Pins[PIN_SCE]->write(0);    // Chip Select goes low
-    Pins[PIN_DC]->write(1);     // Data/CMD goes high
-    
     for(int tick = 0; tick <= 503; tick++)
         LcdSpi->write(0x00);
-        
-    Pins[PIN_SCE]->write(1);    // Chip Select goes high
 }
 
 void NokiaLcd::TestLcd(char test_pattern)
 {
-    Pins[PIN_SCE]->write(0);    // Chip Select goes low
-    Pins[PIN_DC]->write(1);     // Data/CMD goes high
-    
     for(int tick = 0; tick <= 503; tick++)
         LcdSpi->write(test_pattern);         // Command gets sent
-    
-    Pins[PIN_SCE]->write(1);    // Chip Select goes high
 }
 
 void NokiaLcd::InitLcd()
 {
     ResetLcd();
+    Pins[PIN_SCE]->write(0);     // Chip Select goes low
     
     // Redefine the FunctionChar in case it has changed
     FunctionSet.V   = CMD_FS_HORIZONTAL_MODE;
@@ -82,6 +73,7 @@
     SendFunction( DispControlChar );        // | Display Mode
     
     ClearLcdMem();
+    Pins[PIN_DC]->write(1);     // Data/CMD goes back to Data mode
 }
 
 void NokiaLcd::ResetLcd()
@@ -97,12 +89,7 @@
 
 void NokiaLcd::SendDrawData(char data)
 {
-    Pins[PIN_SCE]->write(0);    // Chip Select goes low
-    Pins[PIN_DC]->write(1);     // Data/CMD goes high
-    
     LcdSpi->write(data);         // Command gets sent
-    
-    Pins[PIN_SCE]->write(1);    // Chip Select goes high
 }
 
 void NokiaLcd::DrawChar(char character)
@@ -111,15 +98,73 @@
         SendDrawData( FONT_6x6[ ((character - 32)*6) + i] );
 }
 
+void NokiaLcd::DrawString(char* s)
+{
+    char len = strlen(s);
+    for( int idx = 0; idx < len; idx++ )
+    {
+        for( int i = 0; i < 6; i++)
+            SendDrawData( FONT_6x6[ ((s[idx] - 32)*6) + i] );
+    }
+}
+
+void NokiaLcd::DrawFrameChar(char character)
+{
+    for( int i = 0; i < 6; i++)
+        SendDrawData((( FONT_6x6[ ((character - 32)*6) + i]  ) << 1 ) | 0x81);
+}
+
+void NokiaLcd::DrawNegFrameChar(char character)
+{
+    for( int i = 0; i < 6; i++)
+        SendDrawData(~(( FONT_6x6[ ((character - 32)*6) + i]  ) << 1 ) | 0x81);
+}
+
+char* NokiaLcd::NumToStr(int num)
+{
+    if(num <= 0)
+        return "0";
+
+    double length = 0;
+    int tlen = 0;
+    int temp = 1;
+    char c;
+    
+    // Get number of digits
+    while( temp <= num )
+    {
+        temp *= 10;
+        length++;
+    }
+    tlen = length;
+    char* numString = new char[tlen+1];
+    
+    // Convert each place in number to a stand-alone representative number
+    temp = 0;
+    for(int idx = pow(10, length); idx>1; idx = (idx/10))
+    {
+        c = (char)( ((num % idx)-(num % (idx/10)))/(idx/10) + 48);
+        numString[temp] = c;
+        temp++;
+    }
+    numString[temp] = '\0';
+    return numString;
+}
+
+void NokiaLcd::SetXY(char x, char y)
+{
+    if( (x > 83) || (y > 5) )
+        return;
+
+    SendFunction( x | 0x80 );
+    SendFunction( y | 0x40 );
+}
+
 void NokiaLcd::SendFunction(char cmd) //TODO:Detection of what H should be
 {
-    Pins[PIN_SCE]->write(0);    // Chip Select goes low
     Pins[PIN_DC]->write(0);     // Data/CMD goes low
-    
     LcdSpi->write(cmd);         // Command gets sent
-    
     Pins[PIN_DC]->write(1);     // Data/CMD goes back to Data mode
-    Pins[PIN_SCE]->write(1);    // Chip Select goes high
 }
 
 NokiaLcd::~NokiaLcd()