Demo program for driving the memory LCD on the Zero Gecko Starter Kit.

Dependencies:   MemoryLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "LS013B7DH03.h"
00002 #include "mbed_logo.h"
00003 /******************** Define I/O *****************************/
00004 DigitalOut myled(LED1);
00005 
00006 #if defined(TARGET_EFM32ZG_STK3200)
00007 #define SCK_PIN     PC15
00008 #define MOSI_PIN    PD7
00009 #define CS_PIN      PE11
00010 #define EXTCOM_PIN  PE10
00011 #define DISP_PIN    PA10
00012 #define DISPSEL_PIN PA8
00013 #elif defined (TARGET_EFM32HG_STK3400)
00014 #define SCK_PIN     PE12
00015 #define MOSI_PIN    PE10
00016 #define CS_PIN      PA10
00017 #define EXTCOM_PIN  PF3
00018 #define DISPSEL_PIN PA8
00019 #else
00020 #error "undefined pinout"
00021 #endif
00022  
00023 DigitalOut CS(CS_PIN);
00024 DigitalOut EXTCOM(EXTCOM_PIN);
00025 #ifdef DISP_PIN
00026 DigitalOut DISP(DISP_PIN);
00027 #endif
00028 DigitalOut DISP_SEL(DISPSEL_PIN);
00029  
00030 SPI displaySPI(MOSI_PIN, NC, SCK_PIN);
00031 silabs::LS013B7DH03 display(&displaySPI, &CS, &EXTCOM);
00032 
00033 /******************** Define Timers *****************************/
00034  
00035 LowPowerTicker timeKeeping;
00036  
00037 /***************** Define global variables **********************/
00038 #define INIT_SECONDS        17600
00039  
00040 volatile uint32_t prevSeconds = INIT_SECONDS, seconds = INIT_SECONDS;
00041 volatile bool refreshed = false;
00042  
00043 /***************** Define callback handlers *********************/
00044 void secondsCallback(void);
00045 void refreshCallback(void);
00046  
00047 void secondsCallback(void) {
00048     seconds++;
00049 }
00050  
00051 /**
00052  * Callback for refresh completion
00053  */
00054 void refreshCallback(void) {
00055     refreshed = true;
00056 }
00057  
00058 /*************************** MAIN *******************************/
00059 int main() {
00060     // Enable the LCD
00061     DISP_SEL = 1;
00062 #ifdef DISP_PIN
00063     DISP = 1;
00064 #endif
00065  
00066     // Start generating the 1Hz call for keeping time
00067     timeKeeping.attach(&secondsCallback, 1.0f);
00068  
00069     // Reset the LCD to a blank state. (All white)
00070     refreshed = false;
00071     display.clearImmediate(refreshCallback);
00072     while(refreshed == false) sleep();
00073  
00074     printf("Initialization done! \n");
00075  
00076     // Apply mbed logo bitmap to the pixel buffer
00077     display.showBMP((uint8_t*)mbed_enabled_logo, 128, 128, 0, 0);
00078     display.printf("I like MBED!");
00079  
00080     // Push update to the display
00081     refreshed = false;
00082     display.update(refreshCallback);
00083  
00084     // Sleep while doing the transmit
00085     while(refreshed == false) sleep();
00086  
00087     // Go into clock mode
00088     while(1) {
00089         sleep();
00090  
00091         // In clock mode, only update once per second
00092         if(prevSeconds != seconds) {
00093             display.locate(4,15);
00094             display.printf("%02d:%02d:%02d", (seconds / 1200) % 24, (seconds / 60) % 60, seconds % 60);
00095             if(refreshed == true) {
00096                 prevSeconds = seconds;
00097                 refreshed = false;
00098                 display.update(refreshCallback);
00099                 while(!refreshed) sleep();
00100             }
00101         }
00102     }
00103 }