tr

Revision:
44:57f9d32fb521
Parent:
43:c2598020fcac
Child:
45:97e54ea40dac
--- a/N5110.cpp	Tue Mar 21 11:46:14 2017 +0000
+++ b/N5110.cpp	Wed Nov 01 20:48:05 2017 +0000
@@ -57,22 +57,14 @@
 {
     turnOn();     // power up
     reset();      // reset LCD - must be done within 100 ms
-
-    initSPI();
-    // function set - extended
-    sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_EXTENDED_MODE);
-    // Don't completely understand these parameters - they seem to work as they are
-    // Consult the datasheet if you need to change them
-    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);   // changing this can sometimes improve the contrast on some displays
-
-    // function set - basic
-    sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_BASIC_MODE);
+    initSPI();    
+    
+    setContrast(0.40);  // this may need tuning (say 0.4 to 0.6)
+    setBias(3);   // datasheet - 48:1 mux - don't mess with if you don't know what you're doing! 
+    setTempCoefficient(0); // datasheet - may need increasing (range 0 to 3) at very low temperatures
     normalMode();  // normal video mode by default
-    sendCommand(CMD_DC_NORMAL_MODE);  // black on white
-
-    clearRAM();      // RAM is undefined at power-up so clear
+    
+    clearRAM();      // RAM is undefined at power-up so clear to be sure
     clear();   // clear buffer
     setBrightness(0.5);
 }
@@ -80,13 +72,15 @@
 // sets normal video mode (black on white)
 void N5110::normalMode()
 {
-    sendCommand(CMD_DC_NORMAL_MODE);
+    sendCommand(0b00100000);   // basic instruction
+    sendCommand(0b00001100);  // normal video mode- datasheet
 }
 
 // sets normal video mode (white on black)
 void N5110::inverseMode()
 {
-    sendCommand(CMD_DC_INVERT_VIDEO);
+    sendCommand(0b00100000);   // basic instruction
+    sendCommand(0b00001101);   // inverse video mode - datasheet
 }
 
 // function to power up the LCD and backlight - only works when using GPIO to power
@@ -105,16 +99,15 @@
     setBrightness(0.0);  // turn backlight off
     clearRAM();   // clear RAM to ensure specified current consumption
     // send command to ensure we are in basic mode
-    sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_BASIC_MODE);
-    // clear the display
-    sendCommand(CMD_DC_CLEAR_DISPLAY);
-    // enter the extended mode and power down
-    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);
-
+    
+    sendCommand(0b00100000); // basic mode
+    sendCommand(0b00001000); // clear display
+    sendCommand(0b00100001); // extended mode
+    sendCommand(0b00100100); // power down
+    
     // if we are powering the LCD using the GPIO then make it low to turn off
     if (_pwr != NULL) {
+        wait_ms(10);  // small delay and then turn off the power pin
         _pwr->write(0);  // turn off power
     }
 
@@ -132,6 +125,58 @@
     _led->write(brightness);
 }
 
+void N5110::setContrast(float contrast) {
+    
+    // enforce limits
+    if (contrast > 1.0)
+        contrast = 1.0;
+    else if (contrast < 0.0)
+        contrast = 0.0;
+    
+    // convert to char in range 0 to 127 (i.e. 6 bits)
+    char ic = char(contrast*127.0);
+    
+    sendCommand(0b00100001);  // extended instruction set
+    sendCommand(0b10000000 | ic);   // set Vop (which controls contrast)
+    sendCommand(0b00100000);  // back to basic instruction set
+}
+
+void N5110::setTempCoefficient(char tc) {
+    
+    // enforce limits
+    if (tc>3) {
+        tc=3;
+    }
+    
+    // temperature coefficient may need increasing at low temperatures
+
+    sendCommand(0b00100001);  // extended instruction set
+    sendCommand(0b00000100 | tc);
+    sendCommand(0b00100000);  // back to basic instruction set
+}
+    
+void N5110::setBias(char bias) {
+    
+    // from data sheet
+    // bias      mux rate
+    // 0        1:100
+    // 1        1:80
+    // 2        1:65
+    // 3        1:48   (default)
+    // 4        1:40/1:34
+    // 5        1:24
+    // 6        1:18/1:16
+    // 7        1:10/1:9/1:8
+    
+    // enforce limits
+    if (bias>7) {
+        bias=7;
+    }
+        
+    sendCommand(0b00100001);  // extended mode instruction
+    sendCommand(0b00010000 | bias);  
+    sendCommand(0b00100000); // end of extended mode instruction
+}
 
 // pulse the active low reset line
 void N5110::reset()
@@ -182,8 +227,9 @@
                          unsigned int const y)
 {
     if (x<WIDTH && y<HEIGHT) {  // check within range
-        sendCommand(0x80 | x);  // send addresses to display with relevant mask
-        sendCommand(0x40 | y);
+        sendCommand(0b00100000);  // basic instruction
+        sendCommand(0b10000000 | x);  // send addresses to display with relevant mask
+        sendCommand(0b01000000 | y);
     }
 }