character LCD module to I2C adapter Reference http://mbed.org/users/okini3939/notebook/i2c-lcd-library/

Dependents:   JRO_CR2 frdm_test JRO_DDSv2 JRO_DDSv2_rev2019

Fork of I2CLCD by Suga koubou

Revision:
2:bc4583ce560e
Parent:
1:bf21aa3f7cdc
Child:
3:0c291dbc7acc
--- a/I2CLCD.cpp	Tue Oct 19 07:08:54 2010 +0000
+++ b/I2CLCD.cpp	Sun Feb 27 14:28:40 2011 +0000
@@ -1,19 +1,25 @@
 /*
  * mbed library for I2C LCD
- * Copyright (c) 2010 Hiroshi Suga
+ * Copyright (c) 2011 Hiroshi Suga
  * Released under the MIT License: http://mbed.org/license/mit
  *
- * Using some of the source code:
+ * This product includes:
  * mbed TextLCD Library, for a 4-bit LCD based on HD44780
  * Copyright (c) 2007-2010, sford
  */
 
+/** @file I2CLCD.cpp
+ * @brief I2C LCD library (mbed Phone Platform)
+ */
+
 #include "mbed.h"
 #include "I2CLCD.h"
 
-#define I2CLCD_ADDR 0x7c
-
-
+/**
+ * @brief put character to LCD
+ * @param value ASCII character code
+ * @retval value
+ */
 int I2CLCD::_putc (int value) {
 
     if (value == '\n') {
@@ -42,30 +48,46 @@
     return value;
 }
 
+/**
+ * @brief get character from LCD
+ * @retval ASCII character code
+ */
 int I2CLCD::_getc() {
     return lcd_in(0);
 }
 
 
-I2CLCD::I2CLCD (PinName p_sda, PinName p_scl, I2CLCDType p_type, I2CLCDConfig p_config) : i2c(p_sda, p_scl) {
-    init(p_type, p_config);
+/**
+ * @brief put character to LCD
+ * @param p_sda port of I2C SDA
+ * @param p_scl port of I2C SCL
+ * @param p_i2caddr I2C address
+ */
+I2CLCD::I2CLCD (PinName p_sda, PinName p_scl, int p_i2caddr, I2CLCDType p_type, I2CLCDConfig p_config) : i2c(p_sda, p_scl) {
+    init(p_i2caddr, p_type, p_config);
 }
 
-I2CLCD::I2CLCD (I2C& p_i2c, I2CLCDType p_type, I2CLCDConfig p_config) : i2c(p_i2c) {
-    init(p_type, p_config);
+/**
+ * @brief put character to LCD
+ * @param p_i2c instance of I2C class
+ * @param p_i2caddr I2C address
+ */
+I2CLCD::I2CLCD (I2C& p_i2c, int p_i2caddr, I2CLCDType p_type, I2CLCDConfig p_config) : i2c(p_i2c) {
+    init(p_i2caddr, p_type, p_config);
 }
 
-void I2CLCD::init (I2CLCDType p_type, I2CLCDConfig p_config) {
+void I2CLCD::init (int p_i2caddr, I2CLCDType p_type, I2CLCDConfig p_config) {
 
+    i2caddr = p_i2caddr;
     type = p_type;
 
     lcd_cfg(p_config);
 
-    wait(0.5);
+    wait_ms(500);
     lcd_out(0x30, 0);
-    wait(0.005);
+    wait_ms(5);
     lcd_out(0x30, 0);
-    wait(0.002);
+    wait_ms(2);
     lcd_out(0x30, 0);
 
     lcd_out(0x38, 0); // func 
@@ -77,9 +99,9 @@
 
 void I2CLCD::cls() {
     lcd_out(0x01, 0); // clear
-    wait(0.002);
+    wait_ms(2);
     lcd_out(0x02, 0); // home
-    wait(0.002);
+    wait_ms(2);
     locate(0, 0);
 }
 
@@ -149,28 +171,28 @@
 
 void I2CLCD::lcd_cfg (I2CLCDConfig cfg) {
     i2c.start();
-    i2c.write(I2CLCD_ADDR);
+    i2c.write(i2caddr);
     i2c.write(LCDCFG_ENABLE | (cfg & 0x1f));
     i2c.stop();
 }
 
-void I2CLCD::lcd_out (int dat, int rs) {
+void I2CLCD::lcd_out (char dat, char rs) {
     i2c.start();
-    i2c.write(I2CLCD_ADDR);
+    i2c.write(i2caddr);
     i2c.write(rs ? 0x40 : 0);
     i2c.write(dat);
     i2c.stop();
 }
 
-int I2CLCD::lcd_in (int rs) {
-    int i;
+char I2CLCD::lcd_in (char rs) {
+    char i;
 
     i2c.start();
-    i2c.write(I2CLCD_ADDR);
+    i2c.write(i2caddr);
     i2c.write(rs ? 0x40 : 0);
 
     i2c.start();
-    i2c.write(I2CLCD_ADDR | 0x01);
+    i2c.write(i2caddr | 0x01);
     i = i2c.read(0);
     i2c.stop();