LCD driver
Dependents: ecu_reader ecu_reader ecu_simulator regulator_napona
TextLCD.h@0:ec079a141883, 2012-07-27 (annotated)
- Committer:
- pangsk
- Date:
- Fri Jul 27 15:06:59 2012 +0000
- Revision:
- 0:ec079a141883
[mbed] converted /ecu_reader/TextLCD
Who changed what in which revision?
User | Revision | Line number | New 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 | #ifndef MBED_TEXTLCD_H |
pangsk | 0:ec079a141883 | 7 | #define MBED_TEXTLCD_H |
pangsk | 0:ec079a141883 | 8 | |
pangsk | 0:ec079a141883 | 9 | #include "Stream.h" |
pangsk | 0:ec079a141883 | 10 | #include "DigitalOut.h" |
pangsk | 0:ec079a141883 | 11 | #include "BusOut.h" |
pangsk | 0:ec079a141883 | 12 | |
pangsk | 0:ec079a141883 | 13 | namespace mbed { |
pangsk | 0:ec079a141883 | 14 | |
pangsk | 0:ec079a141883 | 15 | /* Class: TextLCD |
pangsk | 0:ec079a141883 | 16 | * A 16x2 Text LCD controller |
pangsk | 0:ec079a141883 | 17 | * |
pangsk | 0:ec079a141883 | 18 | * Allows you to print to a Text LCD screen, and locate/cls. Could be |
pangsk | 0:ec079a141883 | 19 | * turned in to a more generic libray. |
pangsk | 0:ec079a141883 | 20 | * |
pangsk | 0:ec079a141883 | 21 | * If you are connecting multiple displays, you can connect them all in |
pangsk | 0:ec079a141883 | 22 | * parallel except for the enable (e) pin, which must be unique for each |
pangsk | 0:ec079a141883 | 23 | * display. |
pangsk | 0:ec079a141883 | 24 | * |
pangsk | 0:ec079a141883 | 25 | * Example: |
pangsk | 0:ec079a141883 | 26 | * > #include "mbed.h" |
pangsk | 0:ec079a141883 | 27 | * > #include "TextLCD.h" |
pangsk | 0:ec079a141883 | 28 | * > |
pangsk | 0:ec079a141883 | 29 | * > TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3 |
pangsk | 0:ec079a141883 | 30 | * > |
pangsk | 0:ec079a141883 | 31 | * > int main() { |
pangsk | 0:ec079a141883 | 32 | * > lcd.printf("Hello World!"); |
pangsk | 0:ec079a141883 | 33 | * > } |
pangsk | 0:ec079a141883 | 34 | */ |
pangsk | 0:ec079a141883 | 35 | class TextLCD : public Stream { |
pangsk | 0:ec079a141883 | 36 | |
pangsk | 0:ec079a141883 | 37 | public: |
pangsk | 0:ec079a141883 | 38 | /* Constructor: TextLCD |
pangsk | 0:ec079a141883 | 39 | * Create a TextLCD object, connected to the specified pins |
pangsk | 0:ec079a141883 | 40 | * |
pangsk | 0:ec079a141883 | 41 | * All signals must be connected to DigitalIn compatible pins. |
pangsk | 0:ec079a141883 | 42 | * |
pangsk | 0:ec079a141883 | 43 | * Variables: |
pangsk | 0:ec079a141883 | 44 | * rs - Used to specify data or command |
pangsk | 0:ec079a141883 | 45 | * rw - Used to determine read or write |
pangsk | 0:ec079a141883 | 46 | * e - enable |
pangsk | 0:ec079a141883 | 47 | * d0..d3 - The data lines |
pangsk | 0:ec079a141883 | 48 | */ |
pangsk | 0:ec079a141883 | 49 | TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, |
pangsk | 0:ec079a141883 | 50 | PinName d2, PinName d3, int columns = 16, int rows = 2); |
pangsk | 0:ec079a141883 | 51 | |
pangsk | 0:ec079a141883 | 52 | #if 0 // Inhereted from Stream, for documentation only |
pangsk | 0:ec079a141883 | 53 | /* Function: putc |
pangsk | 0:ec079a141883 | 54 | * Write a character |
pangsk | 0:ec079a141883 | 55 | * |
pangsk | 0:ec079a141883 | 56 | * Variables: |
pangsk | 0:ec079a141883 | 57 | * c - The character to write to the serial port |
pangsk | 0:ec079a141883 | 58 | */ |
pangsk | 0:ec079a141883 | 59 | int putc(int c); |
pangsk | 0:ec079a141883 | 60 | |
pangsk | 0:ec079a141883 | 61 | /* Function: printf |
pangsk | 0:ec079a141883 | 62 | * Write a formated string |
pangsk | 0:ec079a141883 | 63 | * |
pangsk | 0:ec079a141883 | 64 | * Variables: |
pangsk | 0:ec079a141883 | 65 | * format - A printf-style format string, followed by the |
pangsk | 0:ec079a141883 | 66 | * variables to use in formating the string. |
pangsk | 0:ec079a141883 | 67 | */ |
pangsk | 0:ec079a141883 | 68 | int printf(const char* format, ...); |
pangsk | 0:ec079a141883 | 69 | #endif |
pangsk | 0:ec079a141883 | 70 | |
pangsk | 0:ec079a141883 | 71 | /* Function: locate |
pangsk | 0:ec079a141883 | 72 | * Locate to a certian position |
pangsk | 0:ec079a141883 | 73 | * |
pangsk | 0:ec079a141883 | 74 | * Variables: |
pangsk | 0:ec079a141883 | 75 | * column - the column to locate to, from 0..15 |
pangsk | 0:ec079a141883 | 76 | * row - the row to locate to, from 0..1 |
pangsk | 0:ec079a141883 | 77 | */ |
pangsk | 0:ec079a141883 | 78 | virtual void locate(int column, int row); |
pangsk | 0:ec079a141883 | 79 | |
pangsk | 0:ec079a141883 | 80 | /* Function: cls |
pangsk | 0:ec079a141883 | 81 | * Clear the screen, and locate to 0,0 |
pangsk | 0:ec079a141883 | 82 | */ |
pangsk | 0:ec079a141883 | 83 | virtual void cls(); |
pangsk | 0:ec079a141883 | 84 | |
pangsk | 0:ec079a141883 | 85 | virtual void reset(); |
pangsk | 0:ec079a141883 | 86 | |
pangsk | 0:ec079a141883 | 87 | protected: |
pangsk | 0:ec079a141883 | 88 | |
pangsk | 0:ec079a141883 | 89 | void clock(); |
pangsk | 0:ec079a141883 | 90 | void writeData(int data); |
pangsk | 0:ec079a141883 | 91 | void writeCommand(int command); |
pangsk | 0:ec079a141883 | 92 | void writeByte(int value); |
pangsk | 0:ec079a141883 | 93 | void writeNibble(int value); |
pangsk | 0:ec079a141883 | 94 | virtual int _putc(int c); |
pangsk | 0:ec079a141883 | 95 | virtual int _getc(); |
pangsk | 0:ec079a141883 | 96 | virtual void newline(); |
pangsk | 0:ec079a141883 | 97 | |
pangsk | 0:ec079a141883 | 98 | int _row; |
pangsk | 0:ec079a141883 | 99 | int _column; |
pangsk | 0:ec079a141883 | 100 | DigitalOut _rw, _rs, _e; |
pangsk | 0:ec079a141883 | 101 | BusOut _d; |
pangsk | 0:ec079a141883 | 102 | int _columns; |
pangsk | 0:ec079a141883 | 103 | int _rows; |
pangsk | 0:ec079a141883 | 104 | |
pangsk | 0:ec079a141883 | 105 | }; |
pangsk | 0:ec079a141883 | 106 | |
pangsk | 0:ec079a141883 | 107 | } |
pangsk | 0:ec079a141883 | 108 | |
pangsk | 0:ec079a141883 | 109 | #endif |