Display on Sparkfun SerLCD v2.5

Wiring Diagram:

Tested using a Serial Enabled 16x2 LCD - White on Black 5V from SparkFun (LCD-09395)

 -LCD-        -MBed-
|   RX|------|p13   |
|  VDD|------|Vu    |
|  GND|------|GND   |
 -----        ------

Thinking about picking up the 3.3V Model (LCD-09067)

 -LCD-        -MBed-
|   RX|------|p13   |
|  VDD|------|VOUT  |
|  GND|------|GND   |
 -----        ------

Inital Setup in MBed:

Very Simple setup... Serial Interface on pin 13 and 14

Serial lcd(p13,p14)

Code Snippits:

Clearing the Screen

clearLCD();
void clearLCD() {
    lcd.printf("%c%c",0xFE,0x01);
}

Setting the Position (for 16 character wide displays)

setLCDpos(lineNumber, columnNumber);
void setLCDpos(int xpos, int ypos) {
    int pos = 0x80;
    switch (xpos){
    case 1: 
        pos +=0; 
        break;
    case 2: 
        pos +=64; 
        break;
    case 3: 
        pos +=16; 
        break;
    case 4: 
        pos +=80;
        break;
    }
    pos += (ypos-1);
    lcd.printf("%c%c",0xFE,pos);
}

Setting the Position (for 20 character wide displays)

setLCDpos(lineNumber, columnNumber);
void setLCDpos(int xpos, int ypos) {
    int pos = 0x80;
    switch (xpos){
    case 1: 
        pos +=0; 
        break;
    case 2: 
        pos +=64; 
        break;
    case 3: 
        pos +=20; 
        break;
    case 4: 
        pos +=84;
        break;
    }
    pos += (ypos-1);
    lcd.printf("%c%c",0xFE,pos);
}

Setting the Brightness

setBrightness(1-30); 1=off 30=Full
void setBrightness(int lev) {
    lcd.printf("%c%c",0x7C,lev+127);
    wait(.1);
}

Simple Test Program:

I put together a simple test program using these functions, it displays "Hello World!" on the first line and the Led status on the second line, and the number from a running counter.

LCDtest


0 comments

You need to log in to post a comment