Simple libary for AQM1602XA I2C Character LCD.
Diff: AQM1602XA.cpp
- Revision:
- 0:933748ca1307
--- /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