1 /* mbed TextLCD Library
2 * Copyright (c) 2007-2009 sford
3 * Released under the MIT License: http://mbed.org/license/mit
10 * useful info found at http://www.a-netz.de/lcd.en.php
15 * After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state
17 * - wait approximately 15 ms so the display is ready to execute commands
18 * - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now).
19 * - 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.
20 * - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
21 * - Execute the "clear display" command
26 * Nearly all commands transmitted to the display need 40us for execution.
27 * Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position"
28 * These commands need 1.64ms for execution. These timings are valid for all displays working with an
29 * internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you
30 * can use the busy flag to test if the display is ready to accept the next command.
32 * _e is kept high apart from calling clock
33 * _rw is kept 0 (write) apart from actions that uyse it differently
34 * _rs is set by the data/command writes
37 TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
38 PinName d2, PinName d3, const char *name) : TextDisplay(name), _rw(rw), _rs(rs),
39 _e(e), _d(d0, d1, d2, d3) {
43 _rs = 0; // command mode
45 // Should theoretically wait 15ms, but most things will be powered up pre-reset
46 // so i'll disable that for the minute. If implemented, could wait 15ms post reset
50 // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
51 for(int i=0; i<3; i++) {
53 wait(0.00164); // this command takes 1.64ms, so wait for it
55 writeByte(0x2); // 4-bit mode
57 writeCommand(0x28); // Function set 001 BW N F - -
59 writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
63 void TextLCD::character(int column, int row, int c) {
64 int address = 0x80 + (row * 40) + column; // memory starts at 0x80, and is 40 chars long per row
65 writeCommand(address);
69 int TextLCD::columns() {
77 void TextLCD::writeByte(int value) {
79 wait(0.000040f); // most instructions take 40us
86 wait(0.000040f); // most instructions take 40us
90 void TextLCD::writeCommand(int command) {
95 void TextLCD::writeData(int data) {