Akizuki I2C 8x2 Character LCD AQM0802A driver class for LPC1768

Fork of AQM0802A by Tetsuya Hoshino

Committer:
tetsuya256
Date:
Thu Sep 04 05:50:13 2014 +0000
Revision:
1:340b8e9780a3
Parent:
0:2b187f29704e
Child:
2:1fe32f818e43
Doxygen document changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tetsuya256 0:2b187f29704e 1 #ifndef AQM0802A_H
tetsuya256 0:2b187f29704e 2 #define AQM0802A_H
tetsuya256 0:2b187f29704e 3
tetsuya256 0:2b187f29704e 4 #include "mbed.h"
tetsuya256 0:2b187f29704e 5
tetsuya256 0:2b187f29704e 6 #define AQM0802A_ADDR 0x7C // I2C slave address
tetsuya256 0:2b187f29704e 7 #define AQM0802A_COLS 8
tetsuya256 0:2b187f29704e 8 #define AQM0802A_ROWS 2
tetsuya256 0:2b187f29704e 9 #define AQM0802A_MAX_COLS (1 << 6)
tetsuya256 0:2b187f29704e 10 #define AQM0802A_MAX_ROWS (1 << 2)
tetsuya256 0:2b187f29704e 11 #define AQM0802A_CMD_WAIT 26 // wait time after sent lcd command (us)
tetsuya256 0:2b187f29704e 12 #define I2C_FREQUENCY 400000 // I2C bus speed (uses only constructor of AQM0802A(PinName, PinName))
tetsuya256 0:2b187f29704e 13
tetsuya256 0:2b187f29704e 14 /**
tetsuya256 0:2b187f29704e 15 * Akizuki I2C 8x2 Character LCD AQM0802A driver class.<br />
tetsuya256 0:2b187f29704e 16 * 秋月 I2C 8x2 小型キャラクタLCD AQM0802A用 ドライバクラスです。<br />
tetsuya256 0:2b187f29704e 17 * &nbsp;http://akizukidenshi.com/catalog/g/gK-06795/<br />
tetsuya256 0:2b187f29704e 18 * Copyright(C)2014 T.Hoshino<br />
tetsuya256 0:2b187f29704e 19 * <br />
tetsuya256 0:2b187f29704e 20 * CAUTION: My English is very poor, it might be wrong. (I rely on Google Translate almost.)
tetsuya256 0:2b187f29704e 21 * <ul>
tetsuya256 0:2b187f29704e 22 * <li>Stream 継承なので、printf() 等も利用可能です。<br />
tetsuya256 0:2b187f29704e 23 * This class inherits Stream, Its public methods (printf() etc.) are also available.</li>
tetsuya256 0:2b187f29704e 24 * <li>文字コード '\\r'(0x0D) の出力でカーソル位置は行頭に移動します。<br />
tetsuya256 0:2b187f29704e 25 * When you output the character code '\\r'(0x0D), the cursor position is move to the beginning of line.</li>
tetsuya256 0:2b187f29704e 26 * <li>文字コード '\\n'(0x0A) の出力でカーソル位置は次の行の先頭に移動します。<br />
tetsuya256 0:2b187f29704e 27 * When you output the character code '\\n'(0x0A), the cursor position is move to the beginning of next line.</li>
tetsuya256 0:2b187f29704e 28 * </ul>
tetsuya256 0:2b187f29704e 29 * @code
tetsuya256 0:2b187f29704e 30 //----------------------------------------
tetsuya256 0:2b187f29704e 31 // Sample code for ST Nucleo F401RE
tetsuya256 0:2b187f29704e 32 //----------------------------------------
tetsuya256 0:2b187f29704e 33 #include <mbed.h>
tetsuya256 0:2b187f29704e 34 #include <AQM0802A.h>
tetsuya256 0:2b187f29704e 35
tetsuya256 0:2b187f29704e 36 AQM0802A lcd(D14, D15); // <-- this !
tetsuya256 0:2b187f29704e 37 Ticker ticker;
tetsuya256 0:2b187f29704e 38
tetsuya256 0:2b187f29704e 39 void tick() {
tetsuya256 0:2b187f29704e 40 static int count = 0;
tetsuya256 0:2b187f29704e 41 lcd.cls();
tetsuya256 0:2b187f29704e 42 lcd.printf("Hello\n %d", count++);
tetsuya256 0:2b187f29704e 43 }
tetsuya256 0:2b187f29704e 44
tetsuya256 0:2b187f29704e 45 int main() {
tetsuya256 0:2b187f29704e 46 ticker.attach(&tick, 0.1);
tetsuya256 0:2b187f29704e 47 while(1) {
tetsuya256 0:2b187f29704e 48 }
tetsuya256 0:2b187f29704e 49 }
tetsuya256 0:2b187f29704e 50 * @endcode
tetsuya256 0:2b187f29704e 51 * ご自由にお使いいただけますが、無保証です。使用は自己責任でどうぞ。<br />
tetsuya256 0:2b187f29704e 52 * The use of this is free, but no warranty. please use at your own risk.<br />
tetsuya256 0:2b187f29704e 53 */
tetsuya256 0:2b187f29704e 54 class AQM0802A : public Stream {
tetsuya256 0:2b187f29704e 55 public:
tetsuya256 0:2b187f29704e 56 /**
tetsuya256 0:2b187f29704e 57 * Constructor.
tetsuya256 0:2b187f29704e 58 * @param sda serial data pin
tetsuya256 0:2b187f29704e 59 * @param scl serial clock pin
tetsuya256 0:2b187f29704e 60 */
tetsuya256 0:2b187f29704e 61 AQM0802A(PinName sda, PinName scl);
tetsuya256 0:2b187f29704e 62
tetsuya256 0:2b187f29704e 63 /**
tetsuya256 0:2b187f29704e 64 * Constructor.
tetsuya256 0:2b187f29704e 65 * @param i2c reference to i2c bus object.
tetsuya256 0:2b187f29704e 66 */
tetsuya256 0:2b187f29704e 67 AQM0802A(I2C &i2c);
tetsuya256 0:2b187f29704e 68
tetsuya256 0:2b187f29704e 69 /**
tetsuya256 0:2b187f29704e 70 * Clear screen. 画面をクリアします。<br />
tetsuya256 0:2b187f29704e 71 * After clear screen, the cursor position will be changed to {x:0, y:0}.<br />
tetsuya256 0:2b187f29704e 72 * 画面クリア後、カーソル位置は {x:0, y:0} に変更されます。<br />
tetsuya256 0:2b187f29704e 73 * @see #home()
tetsuya256 0:2b187f29704e 74 */
tetsuya256 0:2b187f29704e 75 void cls();
tetsuya256 0:2b187f29704e 76
tetsuya256 0:2b187f29704e 77 /**
tetsuya256 0:2b187f29704e 78 * Set cursor to home position. カーソル位置をホームポジションに移動します。<br />
tetsuya256 0:2b187f29704e 79 * The cursor position will be changed to {x:0, y:0}. At that time, it does not clear the screen display.<br />
tetsuya256 0:2b187f29704e 80 * カーソル位置を {x:0, y:0} に変更します。その際、画面表示はクリアしません。<br />
tetsuya256 0:2b187f29704e 81 * @see #cls()
tetsuya256 0:2b187f29704e 82 */
tetsuya256 0:2b187f29704e 83 void home();
tetsuya256 0:2b187f29704e 84
tetsuya256 0:2b187f29704e 85 /**
tetsuya256 0:2b187f29704e 86 * Change the contrast of the screen. 画面のコントラストを変更します。<br />
tetsuya256 0:2b187f29704e 87 * Only the lower 6 bits are valid. 下位6ビットのみ有効です。
tetsuya256 0:2b187f29704e 88 * @param contrast 0(bright) to 63(dark). The default value is 32.
tetsuya256 0:2b187f29704e 89 */
tetsuya256 0:2b187f29704e 90 void setContrast(int contrast);
tetsuya256 0:2b187f29704e 91
tetsuya256 0:2b187f29704e 92 /**
tetsuya256 0:2b187f29704e 93 * Change the cursor position to {x, y}. 指定位置 {x, y} にカーソルを移動します。<br />
tetsuya256 0:2b187f29704e 94 * The position of left top is {0, 0}. Right bottom is {7, 1}.
tetsuya256 0:2b187f29704e 95 * 左上は {0, 0}、右下は{7, 1} です。
tetsuya256 1:340b8e9780a3 96 * @param x 0 to 7 : Column position of the cursor.
tetsuya256 1:340b8e9780a3 97 * @param y 0 to 1 : Row position of the cursor.
tetsuya256 0:2b187f29704e 98 */
tetsuya256 0:2b187f29704e 99 void setCursor(int x, int y);
tetsuya256 0:2b187f29704e 100
tetsuya256 0:2b187f29704e 101 protected:
tetsuya256 0:2b187f29704e 102 virtual int _putc(int);
tetsuya256 0:2b187f29704e 103 virtual int _getc(){ return 0; }
tetsuya256 0:2b187f29704e 104
tetsuya256 0:2b187f29704e 105 private:
tetsuya256 0:2b187f29704e 106 I2C* i2c;
tetsuya256 0:2b187f29704e 107 uint8_t x;
tetsuya256 0:2b187f29704e 108 uint8_t y;
tetsuya256 0:2b187f29704e 109
tetsuya256 0:2b187f29704e 110 void lcd_init();
tetsuya256 0:2b187f29704e 111 void lcd_cmd(uint8_t cmd);
tetsuya256 0:2b187f29704e 112 void lcd_data(char data);
tetsuya256 0:2b187f29704e 113 };
tetsuya256 0:2b187f29704e 114
tetsuya256 0:2b187f29704e 115 #endif