Had to create default object constructors so that it can be used with the Vodafone library and the mbed rtos when creating dynamic objects on the heap.

Fork of TextLCD by Sukkin Pang

Committer:
nherriot
Date:
Tue Jul 30 13:11:35 2013 +0000
Revision:
1:cb0d67c3953d
Parent:
0:ec079a141883
Creating default constructor with a void type.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pangsk 0:ec079a141883 1 /* mbed TextLCD Library
pangsk 0:ec079a141883 2 * Copyright (c) 2007-2009 sford
pangsk 0:ec079a141883 3 * Released under the MIT License: http://mbed.org/license/mit
pangsk 0:ec079a141883 4 */
pangsk 0:ec079a141883 5
pangsk 0:ec079a141883 6 #include "TextLCD.h"
pangsk 0:ec079a141883 7
pangsk 0:ec079a141883 8 #include "mbed.h"
pangsk 0:ec079a141883 9 #include "error.h"
pangsk 0:ec079a141883 10
pangsk 0:ec079a141883 11 using namespace mbed;
pangsk 0:ec079a141883 12
pangsk 0:ec079a141883 13 /*
pangsk 0:ec079a141883 14 * useful info found at http://www.a-netz.de/lcd.en.php
pangsk 0:ec079a141883 15 *
pangsk 0:ec079a141883 16 *
pangsk 0:ec079a141883 17 * Initialisation
pangsk 0:ec079a141883 18 * ==============
pangsk 0:ec079a141883 19 *
pangsk 0:ec079a141883 20 * After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state
pangsk 0:ec079a141883 21 *
pangsk 0:ec079a141883 22 * - wait approximately 15 ms so the display is ready to execute commands
pangsk 0:ec079a141883 23 * - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now).
pangsk 0:ec079a141883 24 * - The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command.
pangsk 0:ec079a141883 25 * - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
pangsk 0:ec079a141883 26 * - Execute the "clear display" command
pangsk 0:ec079a141883 27 *
pangsk 0:ec079a141883 28 * Timing
pangsk 0:ec079a141883 29 * ======
pangsk 0:ec079a141883 30 *
pangsk 0:ec079a141883 31 * Nearly all commands transmitted to the display need 40us for execution.
pangsk 0:ec079a141883 32 * Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position"
pangsk 0:ec079a141883 33 * These commands need 1.64ms for execution. These timings are valid for all displays working with an
pangsk 0:ec079a141883 34 * internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you
pangsk 0:ec079a141883 35 * can use the busy flag to test if the display is ready to accept the next command.
pangsk 0:ec079a141883 36 *
pangsk 0:ec079a141883 37 * _e is kept high apart from calling clock
pangsk 0:ec079a141883 38 * _rw is kept 0 (write) apart from actions that uyse it differently
pangsk 0:ec079a141883 39 * _rs is set by the data/command writes
pangsk 0:ec079a141883 40 */
pangsk 0:ec079a141883 41
nherriot 1:cb0d67c3953d 42 TextLCD::TextLCD(void): _rw(p18), _rs(p19), _e(p20), _d(p17, p16, p15, p14), _columns(16), _rows(2)
nherriot 1:cb0d67c3953d 43 {
nherriot 1:cb0d67c3953d 44
nherriot 1:cb0d67c3953d 45 // nothing much happens here in my default constructor
nherriot 1:cb0d67c3953d 46 }
nherriot 1:cb0d67c3953d 47
nherriot 1:cb0d67c3953d 48
nherriot 1:cb0d67c3953d 49 TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, int columns, int rows)
nherriot 1:cb0d67c3953d 50 : _rw(rw), _rs(rs), _e(e), _d(d0, d1, d2, d3), _columns(columns), _rows(rows) {
pangsk 0:ec079a141883 51
pangsk 0:ec079a141883 52 // _rows = 2;
pangsk 0:ec079a141883 53 // _columns = 16;
pangsk 0:ec079a141883 54 // Mon, 27 Apr 2009 23:32:34 +0200
pangsk 0:ec079a141883 55 // Kevin Konradt:
pangsk 0:ec079a141883 56 // When using a LCD with 1 row x 16 characters
pangsk 0:ec079a141883 57 // instead of 2x16, try changing _columns to 8.
pangsk 0:ec079a141883 58 // (display seems to split the 16 characters into
pangsk 0:ec079a141883 59 // 2 virtual rows with 8 characters each.)
pangsk 0:ec079a141883 60
pangsk 0:ec079a141883 61 _rw = 0;
pangsk 0:ec079a141883 62 _e = 1;
pangsk 0:ec079a141883 63 _rs = 0; // command mode
pangsk 0:ec079a141883 64
pangsk 0:ec079a141883 65 // Should theoretically wait 15ms, but most things will be powered up pre-reset
pangsk 0:ec079a141883 66 // so i'll disable that for the minute. If implemented, could wait 15ms post reset
pangsk 0:ec079a141883 67 // instead
pangsk 0:ec079a141883 68 // wait(0.015);
pangsk 0:ec079a141883 69
pangsk 0:ec079a141883 70 // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
pangsk 0:ec079a141883 71 for(int i=0; i<3; i++) {
pangsk 0:ec079a141883 72 writeNibble(0x3);
pangsk 0:ec079a141883 73 wait(0.00164); // this command takes 1.64ms, so wait for it
pangsk 0:ec079a141883 74 }
pangsk 0:ec079a141883 75 writeNibble(0x2); // 4-bit mode
pangsk 0:ec079a141883 76
pangsk 0:ec079a141883 77 writeCommand(0x28); // Function set 001 BW N F - -
pangsk 0:ec079a141883 78 writeCommand(0x0C);
pangsk 0:ec079a141883 79 writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
pangsk 0:ec079a141883 80
pangsk 0:ec079a141883 81 cls();
pangsk 0:ec079a141883 82 }
pangsk 0:ec079a141883 83
pangsk 0:ec079a141883 84 int TextLCD::_putc(int value) {
pangsk 0:ec079a141883 85 if(value == '\n') {
pangsk 0:ec079a141883 86 newline();
pangsk 0:ec079a141883 87 } else {
pangsk 0:ec079a141883 88 writeData(value);
pangsk 0:ec079a141883 89 }
pangsk 0:ec079a141883 90 return value;
pangsk 0:ec079a141883 91 }
pangsk 0:ec079a141883 92
pangsk 0:ec079a141883 93 int TextLCD::_getc() {
pangsk 0:ec079a141883 94 return 0;
pangsk 0:ec079a141883 95 }
pangsk 0:ec079a141883 96
pangsk 0:ec079a141883 97 void TextLCD::newline() {
pangsk 0:ec079a141883 98 _column = 0;
pangsk 0:ec079a141883 99 _row++;
pangsk 0:ec079a141883 100 if(_row >= _rows) {
pangsk 0:ec079a141883 101 _row = 0;
pangsk 0:ec079a141883 102 }
pangsk 0:ec079a141883 103 locate(_column, _row);
pangsk 0:ec079a141883 104 }
pangsk 0:ec079a141883 105
pangsk 0:ec079a141883 106 void TextLCD::locate(int column, int row) {
pangsk 0:ec079a141883 107 if(column < 0 || column >= _columns || row < 0 || row >= _rows) {
pangsk 0:ec079a141883 108 error("locate(%d,%d) out of range on %dx%d display", column, row, _columns, _rows);
pangsk 0:ec079a141883 109 return;
pangsk 0:ec079a141883 110 }
pangsk 0:ec079a141883 111
pangsk 0:ec079a141883 112 _row = row;
pangsk 0:ec079a141883 113 _column = column;
pangsk 0:ec079a141883 114 int address = 0x80 + (_row * 40) + _column; // memory starts at 0x80, and is 40 chars long per row
pangsk 0:ec079a141883 115 writeCommand(address);
pangsk 0:ec079a141883 116 }
pangsk 0:ec079a141883 117
pangsk 0:ec079a141883 118 void TextLCD::cls() {
pangsk 0:ec079a141883 119 writeCommand(0x01); // Clear Display
pangsk 0:ec079a141883 120 wait(0.00164f); // This command takes 1.64 ms
pangsk 0:ec079a141883 121 locate(0, 0);
pangsk 0:ec079a141883 122 }
pangsk 0:ec079a141883 123
pangsk 0:ec079a141883 124 void TextLCD::reset() {
pangsk 0:ec079a141883 125 cls();
pangsk 0:ec079a141883 126 }
pangsk 0:ec079a141883 127
pangsk 0:ec079a141883 128 void TextLCD::clock() {
pangsk 0:ec079a141883 129 wait(0.000040f);
pangsk 0:ec079a141883 130 _e = 0;
pangsk 0:ec079a141883 131 wait(0.000040f); // most instructions take 40us
pangsk 0:ec079a141883 132 _e = 1;
pangsk 0:ec079a141883 133 }
pangsk 0:ec079a141883 134
pangsk 0:ec079a141883 135 void TextLCD::writeNibble(int value) {
pangsk 0:ec079a141883 136 _d = value;
pangsk 0:ec079a141883 137 clock();
pangsk 0:ec079a141883 138 }
pangsk 0:ec079a141883 139
pangsk 0:ec079a141883 140 void TextLCD::writeByte(int value) {
pangsk 0:ec079a141883 141 writeNibble(value >> 4);
pangsk 0:ec079a141883 142 writeNibble(value >> 0);
pangsk 0:ec079a141883 143 }
pangsk 0:ec079a141883 144
pangsk 0:ec079a141883 145 void TextLCD::writeCommand(int command) {
pangsk 0:ec079a141883 146 _rs = 0;
pangsk 0:ec079a141883 147 writeByte(command);
pangsk 0:ec079a141883 148 }
pangsk 0:ec079a141883 149
pangsk 0:ec079a141883 150 void TextLCD::writeData(int data) {
pangsk 0:ec079a141883 151 _rs = 1;
pangsk 0:ec079a141883 152 writeByte(data);
pangsk 0:ec079a141883 153 _column++;
pangsk 0:ec079a141883 154 if(_column >= _columns) {
pangsk 0:ec079a141883 155 newline();
pangsk 0:ec079a141883 156 }
pangsk 0:ec079a141883 157 }