Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Committer:
hlipka
Date:
Sun Nov 28 22:09:54 2010 +0000
Revision:
3:e5d5e2fe4bf6
Parent:
2:5ac5bab7daaf
Child:
9:2fe93daa2106
Made LCD driver thread safe (to allow usage from timers)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:ae5037e3d6e0 1 /*
hlipka 0:ae5037e3d6e0 2 * mbed LCDWindow library
hlipka 0:ae5037e3d6e0 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 0:ae5037e3d6e0 4 *
hlipka 0:ae5037e3d6e0 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:ae5037e3d6e0 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 0:ae5037e3d6e0 7 * in the Software without restriction, including without limitation the rights
hlipka 0:ae5037e3d6e0 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:ae5037e3d6e0 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 0:ae5037e3d6e0 10 * furnished to do so, subject to the following conditions:
hlipka 0:ae5037e3d6e0 11 *
hlipka 0:ae5037e3d6e0 12 * The above copyright notice and this permission notice shall be included in
hlipka 0:ae5037e3d6e0 13 * all copies or substantial portions of the Software.
hlipka 0:ae5037e3d6e0 14 *
hlipka 0:ae5037e3d6e0 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:ae5037e3d6e0 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:ae5037e3d6e0 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:ae5037e3d6e0 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:ae5037e3d6e0 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:ae5037e3d6e0 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:ae5037e3d6e0 21 * THE SOFTWARE.
hlipka 0:ae5037e3d6e0 22 */
hlipka 0:ae5037e3d6e0 23
hlipka 0:ae5037e3d6e0 24 #include "dogm_spi.h"
hlipka 0:ae5037e3d6e0 25
hlipka 0:ae5037e3d6e0 26 #include "SPI.h"
hlipka 0:ae5037e3d6e0 27 #include "DigitalOut.h"
hlipka 0:ae5037e3d6e0 28 #include "wait_api.h"
hlipka 0:ae5037e3d6e0 29
hlipka 0:ae5037e3d6e0 30 DogmLCDSPI::DogmLCDSPI
hlipka 2:5ac5bab7daaf 31 (unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs)
hlipka 2:5ac5bab7daaf 32 :SPILCDBase(columns,rows,spi,enable,rs)
hlipka 0:ae5037e3d6e0 33 {
hlipka 0:ae5037e3d6e0 34 }
hlipka 0:ae5037e3d6e0 35
hlipka 0:ae5037e3d6e0 36 void DogmLCDSPI::init()
hlipka 0:ae5037e3d6e0 37 {
hlipka 0:ae5037e3d6e0 38 unsigned char initCmd[10]={0x38,0x39,0x14,0x55,0x6d,0x78,0x38,0x0c,0x01,0x06};
hlipka 0:ae5037e3d6e0 39
hlipka 0:ae5037e3d6e0 40 _enable->write(1);
hlipka 0:ae5037e3d6e0 41 wait_ms(80);
hlipka 0:ae5037e3d6e0 42
hlipka 0:ae5037e3d6e0 43 for (int i=0;i<sizeof(initCmd);i++)
hlipka 0:ae5037e3d6e0 44 {
hlipka 0:ae5037e3d6e0 45 sendCmd(initCmd[i]);
hlipka 0:ae5037e3d6e0 46 wait_ms(4);
hlipka 0:ae5037e3d6e0 47 }
hlipka 0:ae5037e3d6e0 48 }
hlipka 0:ae5037e3d6e0 49
hlipka 2:5ac5bab7daaf 50 void DogmLCDSPI::character(int column, int row, int c)
hlipka 0:ae5037e3d6e0 51 {
hlipka 2:5ac5bab7daaf 52 int address=(row)*0x40+(column);
hlipka 3:e5d5e2fe4bf6 53 _guard->take();
hlipka 2:5ac5bab7daaf 54 sendCmd((char)address|0x80);
hlipka 2:5ac5bab7daaf 55 wait_ms(1);
hlipka 2:5ac5bab7daaf 56 sendData(c);
hlipka 3:e5d5e2fe4bf6 57 _guard->release();
hlipka 2:5ac5bab7daaf 58 wait_ms(1);
hlipka 2:5ac5bab7daaf 59 }
hlipka 2:5ac5bab7daaf 60
hlipka 2:5ac5bab7daaf 61 void DogmLCDSPI::writeText(const unsigned int column, const unsigned int row, const char text[])
hlipka 2:5ac5bab7daaf 62 {
hlipka 2:5ac5bab7daaf 63 int address=(row)*0x40+(column);
hlipka 3:e5d5e2fe4bf6 64 _guard->take();
hlipka 0:ae5037e3d6e0 65 sendCmd((char)address|0x80);
hlipka 0:ae5037e3d6e0 66 wait_ms(1);
hlipka 0:ae5037e3d6e0 67
hlipka 0:ae5037e3d6e0 68 int i=0;
hlipka 0:ae5037e3d6e0 69 while(text[i]!=0)
hlipka 0:ae5037e3d6e0 70 {
hlipka 0:ae5037e3d6e0 71 sendData(text[i]);
hlipka 0:ae5037e3d6e0 72 wait_ms(1);
hlipka 0:ae5037e3d6e0 73 i++;
hlipka 0:ae5037e3d6e0 74 }
hlipka 3:e5d5e2fe4bf6 75 _guard->release();
hlipka 0:ae5037e3d6e0 76 }
hlipka 0:ae5037e3d6e0 77
hlipka 0:ae5037e3d6e0 78 void DogmLCDSPI::clear()
hlipka 0:ae5037e3d6e0 79 {
hlipka 3:e5d5e2fe4bf6 80 _guard->take();
hlipka 0:ae5037e3d6e0 81 sendCmd(1);
hlipka 3:e5d5e2fe4bf6 82 _guard->release();
hlipka 0:ae5037e3d6e0 83 }
hlipka 0:ae5037e3d6e0 84