elec 350 courcework by oscar simons

Dependencies:   BMP280

Fork of Task617-mbedos by University of Plymouth - Stages 1, 2 and 3

Committer:
jkfadsjk
Date:
Tue Jan 09 19:38:56 2018 +0000
Revision:
8:eb72f789f912
Oscar Simons courcework;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jkfadsjk 8:eb72f789f912 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
jkfadsjk 8:eb72f789f912 2 * Copyright (c) 2007-2010, sford, http://mbed.org
jkfadsjk 8:eb72f789f912 3 *
jkfadsjk 8:eb72f789f912 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
jkfadsjk 8:eb72f789f912 5 * of this software and associated documentation files (the "Software"), to deal
jkfadsjk 8:eb72f789f912 6 * in the Software without restriction, including without limitation the rights
jkfadsjk 8:eb72f789f912 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jkfadsjk 8:eb72f789f912 8 * copies of the Software, and to permit persons to whom the Software is
jkfadsjk 8:eb72f789f912 9 * furnished to do so, subject to the following conditions:
jkfadsjk 8:eb72f789f912 10 *
jkfadsjk 8:eb72f789f912 11 * The above copyright notice and this permission notice shall be included in
jkfadsjk 8:eb72f789f912 12 * all copies or substantial portions of the Software.
jkfadsjk 8:eb72f789f912 13 *
jkfadsjk 8:eb72f789f912 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jkfadsjk 8:eb72f789f912 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jkfadsjk 8:eb72f789f912 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jkfadsjk 8:eb72f789f912 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jkfadsjk 8:eb72f789f912 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jkfadsjk 8:eb72f789f912 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jkfadsjk 8:eb72f789f912 20 * THE SOFTWARE.
jkfadsjk 8:eb72f789f912 21 */
jkfadsjk 8:eb72f789f912 22
jkfadsjk 8:eb72f789f912 23 #ifndef MBED_TEXTLCD_H
jkfadsjk 8:eb72f789f912 24 #define MBED_TEXTLCD_H
jkfadsjk 8:eb72f789f912 25
jkfadsjk 8:eb72f789f912 26 #include "mbed.h"
jkfadsjk 8:eb72f789f912 27
jkfadsjk 8:eb72f789f912 28 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
jkfadsjk 8:eb72f789f912 29 *
jkfadsjk 8:eb72f789f912 30 * Currently supports 16x2, 20x2 and 20x4 panels
jkfadsjk 8:eb72f789f912 31 *
jkfadsjk 8:eb72f789f912 32 * @code
jkfadsjk 8:eb72f789f912 33 * #include "mbed.h"
jkfadsjk 8:eb72f789f912 34 * #include "TextLCD.h"
jkfadsjk 8:eb72f789f912 35 *
jkfadsjk 8:eb72f789f912 36 * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
jkfadsjk 8:eb72f789f912 37 *
jkfadsjk 8:eb72f789f912 38 * int main() {
jkfadsjk 8:eb72f789f912 39 * lcd.printf("Hello World!\n");
jkfadsjk 8:eb72f789f912 40 * }
jkfadsjk 8:eb72f789f912 41 * @endcode
jkfadsjk 8:eb72f789f912 42 */
jkfadsjk 8:eb72f789f912 43 class TextLCD : public Stream {
jkfadsjk 8:eb72f789f912 44 public:
jkfadsjk 8:eb72f789f912 45
jkfadsjk 8:eb72f789f912 46 /** LCD panel format */
jkfadsjk 8:eb72f789f912 47 enum LCDType {
jkfadsjk 8:eb72f789f912 48 LCD16x2 /**< 16x2 LCD panel (default) */
jkfadsjk 8:eb72f789f912 49 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
jkfadsjk 8:eb72f789f912 50 , LCD20x2 /**< 20x2 LCD panel */
jkfadsjk 8:eb72f789f912 51 , LCD20x4 /**< 20x4 LCD panel */
jkfadsjk 8:eb72f789f912 52 };
jkfadsjk 8:eb72f789f912 53
jkfadsjk 8:eb72f789f912 54 /** Create a TextLCD interface
jkfadsjk 8:eb72f789f912 55 *
jkfadsjk 8:eb72f789f912 56 * @param rs Instruction/data control line
jkfadsjk 8:eb72f789f912 57 * @param e Enable line (clock)
jkfadsjk 8:eb72f789f912 58 * @param d4-d7 Data lines for using as a 4-bit interface
jkfadsjk 8:eb72f789f912 59 * @param type Sets the panel size/addressing mode (default = LCD16x2)
jkfadsjk 8:eb72f789f912 60 */
jkfadsjk 8:eb72f789f912 61 TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
jkfadsjk 8:eb72f789f912 62
jkfadsjk 8:eb72f789f912 63 #if DOXYGEN_ONLY
jkfadsjk 8:eb72f789f912 64 /** Write a character to the LCD
jkfadsjk 8:eb72f789f912 65 *
jkfadsjk 8:eb72f789f912 66 * @param c The character to write to the display
jkfadsjk 8:eb72f789f912 67 */
jkfadsjk 8:eb72f789f912 68 int putc(int c);
jkfadsjk 8:eb72f789f912 69
jkfadsjk 8:eb72f789f912 70 /** Write a formated string to the LCD
jkfadsjk 8:eb72f789f912 71 *
jkfadsjk 8:eb72f789f912 72 * @param format A printf-style format string, followed by the
jkfadsjk 8:eb72f789f912 73 * variables to use in formating the string.
jkfadsjk 8:eb72f789f912 74 */
jkfadsjk 8:eb72f789f912 75 int printf(const char* format, ...);
jkfadsjk 8:eb72f789f912 76 #endif
jkfadsjk 8:eb72f789f912 77
jkfadsjk 8:eb72f789f912 78 /** Locate to a screen column and row
jkfadsjk 8:eb72f789f912 79 *
jkfadsjk 8:eb72f789f912 80 * @param column The horizontal position from the left, indexed from 0
jkfadsjk 8:eb72f789f912 81 * @param row The vertical position from the top, indexed from 0
jkfadsjk 8:eb72f789f912 82 */
jkfadsjk 8:eb72f789f912 83 void locate(int column, int row);
jkfadsjk 8:eb72f789f912 84
jkfadsjk 8:eb72f789f912 85 /** Clear the screen and locate to 0,0 */
jkfadsjk 8:eb72f789f912 86 void cls();
jkfadsjk 8:eb72f789f912 87
jkfadsjk 8:eb72f789f912 88 int rows();
jkfadsjk 8:eb72f789f912 89 int columns();
jkfadsjk 8:eb72f789f912 90
jkfadsjk 8:eb72f789f912 91 protected:
jkfadsjk 8:eb72f789f912 92
jkfadsjk 8:eb72f789f912 93 // Stream implementation functions
jkfadsjk 8:eb72f789f912 94 virtual int _putc(int value);
jkfadsjk 8:eb72f789f912 95 virtual int _getc();
jkfadsjk 8:eb72f789f912 96
jkfadsjk 8:eb72f789f912 97 int address(int column, int row);
jkfadsjk 8:eb72f789f912 98 void character(int column, int row, int c);
jkfadsjk 8:eb72f789f912 99 void writeByte(int value);
jkfadsjk 8:eb72f789f912 100 void writeCommand(int command);
jkfadsjk 8:eb72f789f912 101 void writeData(int data);
jkfadsjk 8:eb72f789f912 102
jkfadsjk 8:eb72f789f912 103 DigitalOut _rs, _e;
jkfadsjk 8:eb72f789f912 104 BusOut _d;
jkfadsjk 8:eb72f789f912 105 LCDType _type;
jkfadsjk 8:eb72f789f912 106
jkfadsjk 8:eb72f789f912 107 int _column;
jkfadsjk 8:eb72f789f912 108 int _row;
jkfadsjk 8:eb72f789f912 109 };
jkfadsjk 8:eb72f789f912 110
jkfadsjk 8:eb72f789f912 111 #endif