Library for the I2C connected LCD display EA DOGM204.

Example use of the LCD library.

main.cpp

include "mbed.h"
#include "lcd_DOGM204_i2c.h"

DOGM204I2C  lcd(P0_0, P0_1, 0, 100000);

int main() {

    lcd.init();  // Initialize display
    lcd.cls();   // Clear display

    lcd.display_set(DOGM204I2C::LCD_DISPLAY_ON);  // optional | LCD_CURSOR_ON | LCD_BLINK_ON

    lcd.set_pos(DOGM204I2C::LCD_LINE1);
    lcd.write((char *)"*** Hello world *** ");

    lcd.set_pos(DOGM204I2C::LCD_LINE2);
    lcd.write((char *)"01234567890123456789");

    lcd.set_pos(DOGM204I2C::LCD_LINE3);
    lcd.write((char *)"ABCDEFGHIJKLMNOPQRST");

    lcd.set_pos(DOGM204I2C::LCD_LINE4);
    lcd.write((char *)"abcdefghijklmnopqrst");

}

Committer:
bcsd69
Date:
Thu Jan 02 16:20:12 2020 +0000
Revision:
0:ee339d42b34d
Library for the I2C connected EA DOG204 LCD display. Version 1.00.000.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcsd69 0:ee339d42b34d 1 /** EA DOGM204 LCD header file
bcsd69 0:ee339d42b34d 2 *
bcsd69 0:ee339d42b34d 3 * Provides access to the I2C connected Electronic Assembly DOGM204 LCD display
bcsd69 0:ee339d42b34d 4 * with SSD1803A controller (www.lcd-module.de)
bcsd69 0:ee339d42b34d 5 *
bcsd69 0:ee339d42b34d 6 * Version: 1.00.000
bcsd69 0:ee339d42b34d 7 * Date : 02.01.2020
bcsd69 0:ee339d42b34d 8 * Author: Marjan Hanc, www.m-hub.eu
bcsd69 0:ee339d42b34d 9 *
bcsd69 0:ee339d42b34d 10 * Note: This library does not support SPI and 4/8-Bit I/O modes of display.
bcsd69 0:ee339d42b34d 11 * It is assumed, that the RS address selection pin is statically connected
bcsd69 0:ee339d42b34d 12 * either to the GND (SA0=0) or VCC (SA0=1).
bcsd69 0:ee339d42b34d 13 **/
bcsd69 0:ee339d42b34d 14
bcsd69 0:ee339d42b34d 15 #ifndef MBED_LCD_DOGM204
bcsd69 0:ee339d42b34d 16 #define MBED_LCD_DOGM204
bcsd69 0:ee339d42b34d 17
bcsd69 0:ee339d42b34d 18 #include "mbed.h"
bcsd69 0:ee339d42b34d 19
bcsd69 0:ee339d42b34d 20 class DOGM204I2C {
bcsd69 0:ee339d42b34d 21
bcsd69 0:ee339d42b34d 22 public:
bcsd69 0:ee339d42b34d 23
bcsd69 0:ee339d42b34d 24 enum LCD_Commands {
bcsd69 0:ee339d42b34d 25 LCD_ADR = 0x78, // SA0=0, 0x7A when SA0=1
bcsd69 0:ee339d42b34d 26 LCD_CLEAR = 0x00, // Clear Display
bcsd69 0:ee339d42b34d 27 LCD_RTHOME = 0x02 // Return home
bcsd69 0:ee339d42b34d 28 };
bcsd69 0:ee339d42b34d 29
bcsd69 0:ee339d42b34d 30 enum LCD_Status {
bcsd69 0:ee339d42b34d 31 LCD_STATUS = 0x00,
bcsd69 0:ee339d42b34d 32 LCD_DATA = 0x40,
bcsd69 0:ee339d42b34d 33 LCD_BUSY = 0x80
bcsd69 0:ee339d42b34d 34 };
bcsd69 0:ee339d42b34d 35
bcsd69 0:ee339d42b34d 36 enum LCD_Charset {
bcsd69 0:ee339d42b34d 37 LCD_ROMA = 0x00,
bcsd69 0:ee339d42b34d 38 LCD_ROMB = 0x04,
bcsd69 0:ee339d42b34d 39 LCD_ROMC = 0x0C
bcsd69 0:ee339d42b34d 40 };
bcsd69 0:ee339d42b34d 41
bcsd69 0:ee339d42b34d 42 enum LCD_Mode {
bcsd69 0:ee339d42b34d 43 LCD_CURSOR_LINE = 0x00,
bcsd69 0:ee339d42b34d 44 LCD_CURSOR_BLOCK = 0x02,
bcsd69 0:ee339d42b34d 45 LCD_TOPVIEW = 0x05,
bcsd69 0:ee339d42b34d 46 LCD_BOTVIEW = 0x06,
bcsd69 0:ee339d42b34d 47 LCD_2LINE_MODE = 0x08, // Base setting for 1 & 2 line mode
bcsd69 0:ee339d42b34d 48 LCD_4LINE_MODE = 0x09, // Base setting for 3 & 4 line mode
bcsd69 0:ee339d42b34d 49 LCD_FONT_5DOT = 0x00,
bcsd69 0:ee339d42b34d 50 LCD_FONT_6DOT = 0x04
bcsd69 0:ee339d42b34d 51 };
bcsd69 0:ee339d42b34d 52
bcsd69 0:ee339d42b34d 53 enum LCD_Settings {
bcsd69 0:ee339d42b34d 54 LCD_DISPLAY_ON = 0x04,
bcsd69 0:ee339d42b34d 55 LCD_DISPLAY_OFF = 0x03,
bcsd69 0:ee339d42b34d 56 LCD_CURSOR_ON = 0x02,
bcsd69 0:ee339d42b34d 57 LCD_CURSOR_OFF = 0x05,
bcsd69 0:ee339d42b34d 58 LCD_BLINK_ON = 0x01,
bcsd69 0:ee339d42b34d 59 LCD_BLINK_OFF = 0x06
bcsd69 0:ee339d42b34d 60 };
bcsd69 0:ee339d42b34d 61
bcsd69 0:ee339d42b34d 62 enum LCD_Positions {
bcsd69 0:ee339d42b34d 63 LCD_HOME = 0x80,
bcsd69 0:ee339d42b34d 64 LCD_LINE1 = 0x00,
bcsd69 0:ee339d42b34d 65 LCD_LINE2 = 0x20,
bcsd69 0:ee339d42b34d 66 LCD_LINE3 = 0x40,
bcsd69 0:ee339d42b34d 67 LCD_LINE4 = 0x60
bcsd69 0:ee339d42b34d 68 };
bcsd69 0:ee339d42b34d 69
bcsd69 0:ee339d42b34d 70 enum Frequency {
bcsd69 0:ee339d42b34d 71 Frequency_100KHz = 100000,
bcsd69 0:ee339d42b34d 72 Frequency_400KHz = 400000
bcsd69 0:ee339d42b34d 73 };
bcsd69 0:ee339d42b34d 74
bcsd69 0:ee339d42b34d 75 DOGM204I2C(PinName sda, PinName scl, char SA, int frequency);
bcsd69 0:ee339d42b34d 76
bcsd69 0:ee339d42b34d 77 void display_set(char mode);
bcsd69 0:ee339d42b34d 78 void set_pos(char pos);
bcsd69 0:ee339d42b34d 79 void write_char(char line, char pos, char ch);
bcsd69 0:ee339d42b34d 80 void write(char *s);
bcsd69 0:ee339d42b34d 81 void cls();
bcsd69 0:ee339d42b34d 82 void init();
bcsd69 0:ee339d42b34d 83
bcsd69 0:ee339d42b34d 84 private:
bcsd69 0:ee339d42b34d 85 char _baseAdr; // LCD base address (0x78 or 0x7A, depends on SA0)
bcsd69 0:ee339d42b34d 86
bcsd69 0:ee339d42b34d 87 I2C i2c; // I2C interface
bcsd69 0:ee339d42b34d 88
bcsd69 0:ee339d42b34d 89 bool lcd_i2c_write(char cmd, char dta);
bcsd69 0:ee339d42b34d 90 char lcd_i2c_read(char cmd);
bcsd69 0:ee339d42b34d 91 bool lcd_write_cmd(char data);
bcsd69 0:ee339d42b34d 92 bool lcd_write_data(char data);
bcsd69 0:ee339d42b34d 93 };
bcsd69 0:ee339d42b34d 94
bcsd69 0:ee339d42b34d 95
bcsd69 0:ee339d42b34d 96 #endif