Simple libary for AQM1602XA I2C Character LCD.
Revision 0:933748ca1307, committed 2016-04-24
- Comitter:
- kazz12211
- Date:
- Sun Apr 24 11:50:38 2016 +0000
- Commit message:
- Simple class for AQM1602XA I2C LCD.
Changed in this revision
AQM1602XA.cpp | Show annotated file Show diff for this revision Revisions of this file |
AQM1602XA.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 933748ca1307 AQM1602XA.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AQM1602XA.cpp Sun Apr 24 11:50:38 2016 +0000 @@ -0,0 +1,44 @@ +#include "AQM1602XA.h" + +AQM1602XA::AQM1602XA(PinName sda, PinName scl, char slave_adr) + : wire(sda, scl) { + address = slave_adr; + initialize(); +} + + +void AQM1602XA::writeCommand(char cmd) { + char bytes[2]; + bytes[0] = 0x00; + bytes[1] = cmd; + wire.write(address, bytes, 2); + wait(0.01); +} + +void AQM1602XA::writeData(char data) { + char bytes[2]; + bytes[0] = 0x40; + bytes[1] = data; + wire.write(address, bytes, 2); + wait(0.001); +} + +void AQM1602XA::initialize() { + char cmd[] = {0x38, 0x39, 0x14, 0x73, 0x56, 0x6c, 0x38, 0x01, 0x0c}; + wait(0.1); + for(int i = 0; i < 9; i++) { + writeCommand(cmd[i]); + } +} + +void AQM1602XA::printString(int row, char *str) { + int len = strlen(str); + if(len > 16) + len = 16; + if(row == 1) { + writeCommand(0x40 + 0x80); + } + for(int i = 0; i < len; i++) { + writeData(*(str + i)); + } +} \ No newline at end of file
diff -r 000000000000 -r 933748ca1307 AQM1602XA.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AQM1602XA.h Sun Apr 24 11:50:38 2016 +0000 @@ -0,0 +1,40 @@ +/** + * Simple class to handle I2C 16 chars x 2 rows Character LCD + * By K. Tsubaki + * Date: 2016/04/24 + * Tested with: mbed LPC1114 + * Usage: + * mbed <---> LCD + * dp5 <---> SDA + * dp27 <---> SCL + * VIN <---> +V + * GND <---> GND + **/ +#ifndef __AQM1602XA__ + +#include "mbed.h" + +#define AQM1602XA_ADDR (0x3E << 1) + +class AQM1602XA { + private: + I2C wire; + char address; + + void initialize(void); + void writeCommand(char cmd); + void writeData(char data); + public: + /** + * Constructor - default device address is 0x3E + **/ + AQM1602XA(PinName sda, PinName scl, char slave_adr = AQM1602XA_ADDR); + /** + * print characters on the LCD + * params: row (0 or 1) + * str - string to show on the LCD. The length is up to 16 characters + **/ + void printString(int row, char *str); +}; + +#endif