Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: i2clcd_lib WeatherPlatform_20110408 WeatherPlatform WeatherStation ... more
Revision 2:bc4583ce560e, committed 2011-02-27
- Comitter:
- okini3939
- Date:
- Sun Feb 27 14:28:40 2011 +0000
- Parent:
- 1:bf21aa3f7cdc
- Commit message:
Changed in this revision
| I2CLCD.cpp | Show annotated file Show diff for this revision Revisions of this file |
| I2CLCD.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r bf21aa3f7cdc -r bc4583ce560e I2CLCD.cpp
--- 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();
diff -r bf21aa3f7cdc -r bc4583ce560e I2CLCD.h
--- a/I2CLCD.h Tue Oct 19 07:08:54 2010 +0000
+++ b/I2CLCD.h Sun Feb 27 14:28:40 2011 +0000
@@ -1,18 +1,30 @@
/*
* 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.h
+ * @brief I2C LCD library (mbed Phone Platform)
+ */
#ifndef I2CLCD_H
#define I2CLCD_H
#include "mbed.h"
+/**
+ * @brief default I2C address
+ */
+#define I2CLCD_ADDR 0x7c
+
+/**
+ * @brief LCD type
+ */
enum I2CLCDType {
LCD8x2,
LCD16x1,
@@ -23,6 +35,9 @@
LCD20x4
};
+/**
+ * @brief LCD config
+ */
enum I2CLCDConfig {
LCDCFG_ENABLE = 0x20,
LCDCFG_PWMCOUNT = 0x10,
@@ -32,10 +47,13 @@
LCDCFG_INIT = 0x01
};
+/**
+ * @brief I2CLCD class
+ */
class I2CLCD : public Stream {
public:
- I2CLCD (PinName p_sda, PinName p_scl, I2CLCDType p_type = LCD16x2, I2CLCDConfig p_config = LCDCFG_3V);
- I2CLCD (I2C& p_i2c, I2CLCDType p_type = LCD16x2, I2CLCDConfig p_config = LCDCFG_3V);
+ I2CLCD (PinName p_sda, PinName p_scl, int p_i2caddr = I2CLCD_ADDR, I2CLCDType p_type = LCD16x2, I2CLCDConfig p_config = LCDCFG_3V);
+ I2CLCD (I2C& p_i2c, int p_i2caddr = I2CLCD_ADDR, I2CLCDType p_type = LCD16x2, I2CLCDConfig p_config = LCDCFG_3V);
void locate (int, int);
void cls ();
@@ -48,11 +66,12 @@
int address (int, int);
int rows ();
int cols ();
- void init (I2CLCDType, I2CLCDConfig);
- void lcd_out (int, int);
- int lcd_in (int);
+ void init (int, I2CLCDType, I2CLCDConfig);
+ void lcd_out (char, char);
+ char lcd_in (char);
I2C i2c;
+ int i2caddr;
I2CLCDType type;
int x, y;
};