TextLCD compatible wrapper for NOKIA_5110 library

Dependencies:   NOKIA_5110

Fork of TextLCD by Simon Ford

Committer:
davervw
Date:
Sat Jan 18 20:19:20 2014 +0000
Revision:
9:8a3f38cbadd5
Parent:
TextLCD.cpp@7:44f34c09bd37
TextLCD compatible wrapper for NOKIA_5110 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davervw 9:8a3f38cbadd5 1 /* mbed TextLCD5110 Library, for a Nokia 5110 Lcd
davervw 9:8a3f38cbadd5 2 * Original Copyright (c) 2007-2010, sford, http://mbed.org
davervw 9:8a3f38cbadd5 3 * Revisions Copyright (c) 2014, David R. Van Wagner, https://mbed.org/users/davervw/
simon 1:ac48b187213c 4 *
simon 1:ac48b187213c 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 6 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 7 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 9 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 10 * furnished to do so, subject to the following conditions:
simon 1:ac48b187213c 11 *
simon 1:ac48b187213c 12 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 13 * all copies or substantial portions of the Software.
simon 1:ac48b187213c 14 *
simon 1:ac48b187213c 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 21 * THE SOFTWARE.
simon 1:ac48b187213c 22 */
simon 1:ac48b187213c 23
davervw 9:8a3f38cbadd5 24 #include "TextLCD_NOKIA_5110.h"
simon 1:ac48b187213c 25 #include "mbed.h"
simon 1:ac48b187213c 26
davervw 9:8a3f38cbadd5 27 TextLCD5110::TextLCD5110(PinName mosi, PinName sclk, PinName dc, PinName cse,
davervw 9:8a3f38cbadd5 28 PinName reset)
davervw 9:8a3f38cbadd5 29 {
davervw 9:8a3f38cbadd5 30 LcdPins pins = { mosi, NC, sclk, dc, cse, reset };
davervw 9:8a3f38cbadd5 31 pLcd = new NokiaLcd( pins ); // SPI is started here (8-bits, mode 1)
davervw 9:8a3f38cbadd5 32 pLcd->InitLcd(); // LCD is reset and DDRAM is cleared
davervw 9:8a3f38cbadd5 33 locate(0, 0);
simon 1:ac48b187213c 34 }
simon 1:ac48b187213c 35
davervw 9:8a3f38cbadd5 36 void TextLCD5110::character(int column, int row, int c) {
davervw 9:8a3f38cbadd5 37 locate(column, row);
davervw 9:8a3f38cbadd5 38 pLcd->DrawChar(c);
simon 1:ac48b187213c 39 }
simon 1:ac48b187213c 40
davervw 9:8a3f38cbadd5 41 void TextLCD5110::cls() {
davervw 9:8a3f38cbadd5 42 pLcd->ClearLcdMem();
simon 1:ac48b187213c 43 locate(0, 0);
simon 1:ac48b187213c 44 }
simon 1:ac48b187213c 45
davervw 9:8a3f38cbadd5 46 void TextLCD5110::locate(int column, int row) {
davervw 9:8a3f38cbadd5 47 _column = column;
davervw 9:8a3f38cbadd5 48 _row = row;
davervw 9:8a3f38cbadd5 49 pLcd->SetXY(column*6, row);
simon 1:ac48b187213c 50 }
simon 1:ac48b187213c 51
davervw 9:8a3f38cbadd5 52 int TextLCD5110::_putc(int value) {
simon 1:ac48b187213c 53 if (value == '\n') {
simon 1:ac48b187213c 54 _column = 0;
simon 1:ac48b187213c 55 _row++;
simon 1:ac48b187213c 56 if (_row >= rows()) {
simon 1:ac48b187213c 57 _row = 0;
simon 1:ac48b187213c 58 }
simon 1:ac48b187213c 59 } else {
simon 1:ac48b187213c 60 character(_column, _row, value);
simon 1:ac48b187213c 61 _column++;
simon 1:ac48b187213c 62 if (_column >= columns()) {
simon 1:ac48b187213c 63 _column = 0;
simon 1:ac48b187213c 64 _row++;
simon 1:ac48b187213c 65 if (_row >= rows()) {
simon 1:ac48b187213c 66 _row = 0;
simon 1:ac48b187213c 67 }
simon 1:ac48b187213c 68 }
simon 1:ac48b187213c 69 }
simon 1:ac48b187213c 70 return value;
simon 1:ac48b187213c 71 }
simon 1:ac48b187213c 72
davervw 9:8a3f38cbadd5 73 int TextLCD5110::_getc() {
simon 1:ac48b187213c 74 return -1;
simon 1:ac48b187213c 75 }
simon 1:ac48b187213c 76
davervw 9:8a3f38cbadd5 77 int TextLCD5110::columns() {
davervw 9:8a3f38cbadd5 78 return 14;
simon 1:ac48b187213c 79 }
simon 1:ac48b187213c 80
davervw 9:8a3f38cbadd5 81 int TextLCD5110::rows() {
davervw 9:8a3f38cbadd5 82 return 6;
simon 1:ac48b187213c 83 }
simon 1:ac48b187213c 84
davervw 9:8a3f38cbadd5 85 int TextLCD5110::get_column() {
davervw 9:8a3f38cbadd5 86 return _column;
simon 1:ac48b187213c 87 }
simon 1:ac48b187213c 88
davervw 9:8a3f38cbadd5 89 int TextLCD5110::get_row() {
davervw 9:8a3f38cbadd5 90 return _row;
simon 1:ac48b187213c 91 }