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.
Revision 0:f86833c58a5f, committed 2020-01-28
- Comitter:
- piroro4560
- Date:
- Tue Jan 28 08:03:22 2020 +0000
- Child:
- 1:ab257f9b56d2
- Commit message:
- aqm0802
Changed in this revision
| aqm0802.cpp | Show annotated file Show diff for this revision Revisions of this file |
| aqm0802.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aqm0802.cpp Tue Jan 28 08:03:22 2020 +0000
@@ -0,0 +1,87 @@
+#include "aqm0802.h"
+
+aqm0802::aqm0802(PinName sda, PinName scl)
+ : i2c_(sda, scl)
+{
+ wait_ms(40);
+ // LCD initialize
+ cmd(0x39); // function set
+ cmd(0x14); // interval osc
+ cmd(0x70); // contrast Low
+ cmd(0x56); // contast High/icon/power
+ cmd(0x6C); // follower control
+ wait_ms(200);
+ cmd(0x38); // function set
+ cmd(0x0C); // Display On
+ cmd(0x01); // Clear Display
+ wait_ms(200);
+}
+
+void aqm0802::cmd(char x)
+{
+ char data[2];
+ data[0] = 0x00; // CO = 0,RS = 0
+ data[1] = x;
+ i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::contdata(char x)
+{
+ char data[2];
+ data[0] = 0xC0; //0b11000000 CO = 1, RS = 1
+ data[1] = x;
+ i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::lastdata(char x)
+{
+ char data[2];
+ data[0] = 0x40; //0b11000000 CO = 0, RS = 1
+ data[1] = x;
+ i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::print(const char *s)
+{
+ while(*s) {
+ if (*(s + 1)) {
+ contdata(*s);
+ } else {
+ lastdata(*s);
+ }
+ s++;
+ }
+}
+
+void aqm0802::print(int num)
+{
+ char itoa[8];
+ sprintf(itoa, "%d", num);
+ print(itoa);
+}
+
+void aqm0802::setCursor(uint8_t x,uint8_t y)
+{
+ cmd(0x80 | (y*0x40 + x));
+}
+
+void aqm0802::setCG(int src,int dst,int len)
+{
+ cmd(0x38);
+ cmd(0x40 + dst);
+
+ for (int i = 0;i < len;i++) contdata(cg[src + i] * (src>=0));
+}
+
+void aqm0802::setContrast(uint8_t c)
+{
+ cmd(0x39);
+ cmd(0x70 | (c & 0x0f)); // contrast Low
+ cmd(0x5C | ((c >> 4) & 0x03)); // contast High/icon/power
+ cmd(0x38);
+}
+
+void aqm0802::clear()
+{
+ cmd(0x01);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aqm0802.h Tue Jan 28 08:03:22 2020 +0000
@@ -0,0 +1,78 @@
+//-------------------------------------------------------
+// Class for LCD, AQM0802A (Header)
+//
+// Default pin assignments
+// D14 SDA ---- to pin4 of LCD module
+// D15 SCL ---- to pin3 of LCD module
+//
+// Assignment of I2C ports
+// SDA SCL
+// I2C1 PB_7 or PB_9(D14) PB_6(D10) or PB_8(D15)
+// I2C2 PB_3(D3) PB_10(D6)
+// I2C3 PB_4(D5) or PC_9 PA_8(D7)
+//
+// 01234567 x
+// +--------+
+// 0| |
+// 1| |
+// y+--------+
+//
+//
+//-------------------------------------------------------
+
+#ifndef AQM0802_H
+#define AQM0802_H
+
+#include "mbed.h"
+
+class aqm0802 {
+public :
+ // Constructor
+ aqm0802(PinName sda, PinName scl);
+
+ // Send command
+ void cmd(char x);
+
+ // Write string
+ void print(const char *s);
+
+ void print(int num);
+
+ // Set cursol
+ void setCursor(uint8_t x,uint8_t y);
+
+ // Set contrast
+ void setContrast(uint8_t c);
+
+ void contdata(char x);
+
+ void lastdata(char x);
+
+ void setCG(int src,int dst,int len);
+
+ void clear();
+
+//private :
+ const int AQCM0802_addr = 0x7C;
+
+ I2C i2c_;
+ unsigned char cg[13 * 8] = {
+
+0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S
+0x11,0x11,0x11,0x15,0x15,0x15,0x0A,0x00, // W
+0x0E,0x04,0x04,0x04,0x04,0x04,0x0E,0x00, // I
+0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x00, // T
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x11,0x11,0x11,0x1F,0x11,0x11,0x11,0x00, // H
+
+0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x0E,0x04,0x04,0x04,0x04,0x04,0x0E,0x00, // I
+0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00, // E
+0x11,0x11,0x19,0x15,0x13,0x11,0x11,0x00, // N
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00 // E
+};
+
+};
+#endif
\ No newline at end of file