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