64x128 Graphic LCD Library

Dependencies:   LCD_fonts

Fork of C12832_lcd by Peter Drescher

Files at this revision

API Documentation at this revision

Comitter:
tonydbeck
Date:
Fri Nov 01 10:19:59 2013 +0000
Parent:
9:4b0d5aee5371
Child:
11:cbee83ead206
Commit message:
Version 2.0 1/11/2013

Changed in this revision

LCD_fonts.lib Show annotated file Show diff for this revision Revisions of this file
TextDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
TextDisplay.h Show annotated file Show diff for this revision Revisions of this file
gLCD.cpp Show annotated file Show diff for this revision Revisions of this file
gLCD.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_fonts.lib	Fri Nov 01 10:19:59 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/LCD_fonts/#d0b7d7bf1f56
--- a/TextDisplay.cpp	Sat Oct 26 17:38:46 2013 +0000
+++ b/TextDisplay.cpp	Fri Nov 01 10:19:59 2013 +0000
@@ -18,7 +18,7 @@
     
 int TextDisplay::_putc(int value) {
     if(value == '\n') {
-        _column = 0;
+        _column = lastcol;
         _row++;
         if(_row >= rows()) {
             _row = 0;
@@ -27,7 +27,7 @@
         character(_column, _row, value);
         _column++;
         if(_column >= columns()) {
-            _column = 0;
+            _column = lastcol;
             _row++;
             if(_row >= rows()) {
                 _row = 0;
@@ -48,6 +48,7 @@
 void TextDisplay::locate(int column, int row) {
     _column = column;
     _row = row;
+    lastcol = column;
 }
 
 int TextDisplay::_getc() {
@@ -75,3 +76,4 @@
     setvbuf(stdout, NULL, _IOLBF, columns());
     return true;
 } 
+
--- a/TextDisplay.h	Sat Oct 26 17:38:46 2013 +0000
+++ b/TextDisplay.h	Fri Nov 01 10:19:59 2013 +0000
@@ -70,6 +70,7 @@
     // character location
     uint16_t _column;
     uint16_t _row;
+    uint16_t lastcol;
 
     // colours
     uint16_t _foreground;
--- a/gLCD.cpp	Sat Oct 26 17:38:46 2013 +0000
+++ b/gLCD.cpp	Fri Nov 01 10:19:59 2013 +0000
@@ -22,12 +22,17 @@
 #include "gLCD.h"
 #include "mbed.h"
 #include "stdio.h"
-#include "Small_7.h"
+
 
 #define BPP    1       // Bits per pixel
 
-gLCD::gLCD(const char* name)
-    : _spi(p5,NC,p7),_reset(p6),_A0(p8),_CS(p11),GraphicsDisplay(name)
+gLCD::gLCD(PinName cs, 
+           PinName res, 
+           PinName rs, 
+           PinName sdo, PinName sdi, PinName scl,
+           PinName bcl,
+           const char* name)
+    : _spi(sdo,sdi,scl),_reset(res),_A0(rs),_CS(cs),backLight(bcl),GraphicsDisplay(name)
 {
     orientation = 1;
     draw_mode = NORMAL;
@@ -37,18 +42,32 @@
 
 int gLCD::width()
 {
-    if (orientation == 0 || orientation == 2) return 32;
+    if (orientation == 0 || orientation == 2) return 64;
     else return 128;
 }
 
 int gLCD::height()
 {
     if (orientation == 0 || orientation == 2) return 128;
-    else return 32;
+    else return 64;
 }
+float bclValue = 1;
 
+void gLCD::bclIncrease()
+{
+    bclValue+=0.1;
+    if(bclValue > 1) bclValue = 1;
+    backLight = bclValue;
+}
+void gLCD::bclDecrease()
+{
+    bclValue-=0.1;
+    if(bclValue < 0) bclValue = 0;
+    backLight = bclValue;
+}
+     
 
-/*void gLCD::set_orientation(unsigned int o)
+void gLCD::set_orientation(unsigned int o)
 {
     orientation = o;
     switch (o) {
@@ -71,7 +90,7 @@
     }
 }
 
-*/
+
 
 void gLCD::invert(unsigned int o)
 {
@@ -106,7 +125,10 @@
 #else
     _spi.write(cmd);
 #endif
-_CS = 1;
+    _A0 = 1;
+    wait(0.000040f);
+    _A0 = 0;
+    _CS = 1;
 }
 
 // write data to lcd controller
@@ -122,6 +144,9 @@
 #else
     _spi.write(dat);
 #endif
+    _A0 = 0;
+    wait(0.000040f);
+    _A0 = 1;
     _CS = 1;
 }
 
@@ -130,23 +155,23 @@
 void gLCD::lcd_reset()
 {
 
-    _spi.format(8,3);                 // 8 bit spi mode 3
+    _spi.format(8,0);                 // 8 bit spi mode 0
     _spi.frequency(20000000);          // 19,2 Mhz SPI clock
-    DigitalOut _reset(p6);
     _A0 = 0;
     _CS = 1;
     _reset = 0;                        // display reset
-    wait_us(50);
+    wait(0.015);                      //Give display 15ms to reset
     _reset = 1;                       // end reset
     wait_ms(5);
-
+    backLight.period_ms(1);
+    backLight.pulsewidth_ms(1);
+    backLight = 1;
     /* Start Initial Sequence ----------------------------------------------------*/
 
-    wr_cmd(0xAE);   //  display off
+ /*   wr_cmd(0xAE);   //  display off
     wr_cmd(0xA2);   //  bias voltage
 
-    wr_cmd(0xA0);
-    wr_cmd(0xC8);   //  colum normal
+    
 
     wr_cmd(0x22);   //  voltage resistor ratio
     wr_cmd(0x2F);   //  power on
@@ -158,8 +183,26 @@
     wr_cmd(0x17);   //  set contrast
 
     wr_cmd(0xA6);     // display normal
-
-    
+*/
+    wr_cmd(0xA0);       //SEG1->SEG132 x direction
+    wr_cmd(0xC8);       //COM1->COM64 y direction
+    wr_cmd(0xA3);       // 1/9 bias
+    wr_cmd(0x2C);       //Voltage converter on
+    wait(0.001);
+    wr_cmd(0x2E);       //Voltage regulator on
+    wait(0.001);
+    wr_cmd(0x2F);       //Voltage follower on
+    wr_cmd(0x26);       //voltage reg ratio = 5.29
+    wr_cmd(0x81);       //Enter voltage resistor set mode
+    wr_cmd(0x8);        //Set volt res (contrast)
+    wr_cmd(0x40);       //initial display line = 0
+    wr_cmd(0xB0);       //initial page address = 0
+    wr_cmd(0x00);   
+    wr_cmd(0x10);       //Sets first col
+    wr_cmd(0xA6);       //not inverse display
+    wr_cmd(0xAD);       //Static indicator off
+    wr_cmd(0x00);       //no blinking
+    wr_cmd(0xAF);       //display on
 #if defined TARGET_LPC1768          //setup DMA channel 0       
     LPC_SC->PCONP |= (1UL << 29);   // Power up the GPDMA
     LPC_GPDMA->DMACConfig = 1;      // enable DMA controller
@@ -171,9 +214,9 @@
     memset(buffer,0x00,512);  // clear display buffer
     copy_to_lcd();
     auto_up = 1;              // switch on auto update
-    claim(stdout);           // redirekt printf to lcd
+    claim(stdout);           // redirect printf to lcd
     locate(0,0);
-    set_font((unsigned char*)Small_7);  // standart font 
+    set_font((unsigned char*)Small_7);  // standard font 
 }
 
 // set one pixel in buffer
@@ -181,7 +224,7 @@
 void gLCD::pixel(int x, int y, int color)
 {
     // first check parameter
-    if(x > 128 || y > 32 || x < 0 || y < 0) return;
+    if(x > 128 || y > 64 || x < 0 || y < 0) return;
 
     if(draw_mode == NORMAL) {
         if(color == 0)
@@ -302,12 +345,116 @@
     for(i=384;i<512;i++){
         wr_dat(buffer[i]);
         }
+#endif
+
+   //page 4
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB4);      // set page address  4
+    _A0 = 1;
+    
+     _CS = 0;
+#if defined TARGET_LPC1768     
+    // start 128 byte DMA transfer to SPI1
+    LPC_GPDMA->DMACIntTCClear = 0x1;
+    LPC_GPDMA->DMACIntErrClr = 0x1;
+    LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 512);
+    LPC_GPDMACH0->DMACCControl = 128  | (1UL << 31) |  DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
+    LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
+    LPC_GPDMA->DMACSoftSReq = 0x1;
+    do {
+    } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
+    do {
+    } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
+    _CS = 1;
+#else // no DMA
+    for(i=512;i<640;i++){
+        wr_dat(buffer[i]);
+        }
+#endif  
+
+ //page 5
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB5);      // set page address  5
+    _A0 = 1;
+    
+     _CS = 0;
+#if defined TARGET_LPC1768     
+    // start 128 byte DMA transfer to SPI1
+    LPC_GPDMA->DMACIntTCClear = 0x1;
+    LPC_GPDMA->DMACIntErrClr = 0x1;
+    LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 640);
+    LPC_GPDMACH0->DMACCControl = 128  | (1UL << 31) |  DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
+    LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
+    LPC_GPDMA->DMACSoftSReq = 0x1;
+    do {
+    } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
+    do {
+    } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
+    _CS = 1;
+#else // no DMA
+    for(i=640;i<768;i++){
+        wr_dat(buffer[i]);
+        }
+#endif  
+
+ //page 6
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB6);      // set page address  6
+    _A0 = 1;
+    
+     _CS = 0;
+#if defined TARGET_LPC1768     
+    // start 128 byte DMA transfer to SPI1
+    LPC_GPDMA->DMACIntTCClear = 0x1;
+    LPC_GPDMA->DMACIntErrClr = 0x1;
+    LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 768);
+    LPC_GPDMACH0->DMACCControl = 128  | (1UL << 31) |  DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
+    LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
+    LPC_GPDMA->DMACSoftSReq = 0x1;
+    do {
+    } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
+    do {
+    } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
+    _CS = 1;
+#else // no DMA
+    for(i=768;i<896;i++){
+        wr_dat(buffer[i]);
+        }
+#endif  
+
+ //page 7
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB7);      // set page address  7
+    _A0 = 1;
+    
+     _CS = 0;
+#if defined TARGET_LPC1768     
+    // start 128 byte DMA transfer to SPI1
+    LPC_GPDMA->DMACIntTCClear = 0x1;
+    LPC_GPDMA->DMACIntErrClr = 0x1;
+    LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 896);
+    LPC_GPDMACH0->DMACCControl = 128  | (1UL << 31) |  DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
+    LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
+    LPC_GPDMA->DMACSoftSReq = 0x1;
+    do {
+    } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
+    do {
+    } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
+    _CS = 1;
+#else // no DMA
+    for(i=896;i<1024;i++){
+        wr_dat(buffer[i]);
+        }
 #endif   
 }
 
 void gLCD::cls(void)
 {
-    memset(buffer,0x00,512);  // clear display buffer
+    memset(buffer,0x00,1024);  // clear display buffer
     copy_to_lcd();
 }
 
@@ -553,6 +700,7 @@
 {
     char_x = x;
     char_y = y;
+    oldchar_x = x;
 }
 
 
@@ -574,7 +722,7 @@
 int gLCD::_putc(int value)
 {
     if (value == '\n') {    // new line
-        char_x = 0;
+        char_x = oldchar_x;
         char_y = char_y + font[2];
         if (char_y >= height() - font[2]) {
             char_y = 0;
@@ -635,7 +783,13 @@
 
 void gLCD::set_auto_up(unsigned int up)
 {
-    if(up ) auto_up = 1;
+    if(up )
+    {
+     auto_up = 1;
+     }else
+     {
+     auto_up = 0;
+     }
 }
 
 unsigned int gLCD::get_auto_up(void){
@@ -644,3 +798,4 @@
 
 
 
+
--- a/gLCD.h	Sat Oct 26 17:38:46 2013 +0000
+++ b/gLCD.h	Fri Nov 01 10:19:59 2013 +0000
@@ -12,11 +12,15 @@
  * THE SOFTWARE.
  */
 
+/** 64x128pixel graphic LCD display class adapted from the C12832 library */
 #ifndef GLCD_H
 #define GLCD_H
 
 #include "mbed.h"
 #include "GraphicsDisplay.h"
+#include "Small_7.h"
+#include "Arial12x12.h"
+#include "Arial24x23.h"
 
 
 /** optional Defines :
@@ -44,11 +48,16 @@
 class gLCD : public GraphicsDisplay
 {
 public:
-    /** Create a gLCD object connected to SPI1
+    /** Create a gLCD object connected to SPI bus
       *
       */
 
-    gLCD(const char* name = "LCD");
+    gLCD(PinName cs, //chip select
+         PinName res, //reset
+         PinName rs, //register select
+         PinName sdo, PinName sdi, PinName scl, //spi bus pins 
+         PinName bcl, //backlight
+         const char* name = "LCD");
 
     /** Get the width of the screen in pixel
       *
@@ -71,6 +80,8 @@
      * @param y vertical position
      * @param colour ,1 set pixel ,0 erase pixel
      */
+     
+    void set_orientation(unsigned int o);
     virtual void pixel(int x, int y,int colour);
 
     /** draw a circle
@@ -80,6 +91,8 @@
       * @param colour ,1 set pixel ,0 erase pixel
       *
       */
+    void bclIncrease();
+    void bclDecrease();  
     void circle(int x, int y, int r, int colour);
 
     /** draw a filled circle
@@ -217,6 +230,7 @@
     DigitalOut _reset;
     DigitalOut _A0;
     DigitalOut _CS;
+    PwmOut backLight;
     unsigned char* font;
     unsigned int draw_mode;
 
@@ -281,8 +295,9 @@
 
     unsigned int orientation;
     unsigned int char_x;
+    unsigned int oldchar_x;
     unsigned int char_y;
-    unsigned char buffer[512];
+    unsigned char buffer[1024];
     unsigned int contrast;
     unsigned int auto_up;