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: CatPot_Main_ver1 CatPot_Main_F NuFM401 CatPot_Main_ver2 ... more
AQM0802A.cpp
00001 #include "AQM0802A.h" 00002 00003 AQM0802A::AQM0802A(PinName sda, PinName scl) { 00004 i2c = new I2C(sda, scl); 00005 i2c->frequency(I2C_FREQUENCY); 00006 lcd_init(); 00007 } 00008 00009 AQM0802A::AQM0802A(I2C& i2c) { 00010 AQM0802A::i2c = &i2c; 00011 lcd_init(); 00012 } 00013 00014 void AQM0802A::lcd_init() { 00015 static const char init_cmds[] = { 00016 0x38, 00017 0x39, 00018 0x04, 00019 0x14, 00020 0x70, 00021 0x5E, 00022 0x6C 00023 }; 00024 wait_ms(40); 00025 for (int i = 0; i < sizeof(init_cmds); i++) { 00026 lcd_cmd(init_cmds[i]); 00027 } 00028 wait_ms(200); 00029 lcd_cmd(0x38); 00030 lcd_cmd(0x0C); 00031 cls(); 00032 } 00033 00034 void AQM0802A::lcd_cmd(uint8_t dat) { 00035 char buf[] = { 0, dat }; 00036 i2c->write(AQM0802A_ADDR, buf, sizeof(buf)); 00037 wait_us(AQM0802A_CMD_WAIT); 00038 } 00039 00040 void AQM0802A::lcd_data(char dat) { 00041 char buf[] = { 0x40, dat }; 00042 i2c->write(AQM0802A_ADDR, buf, sizeof(buf)); 00043 wait_us(AQM0802A_CMD_WAIT); 00044 } 00045 00046 void AQM0802A::cls() { 00047 x = y = 0; 00048 lcd_cmd(0x01); 00049 wait_us(1080 - AQM0802A_CMD_WAIT); 00050 } 00051 00052 void AQM0802A::home() { 00053 x = y = 0; 00054 lcd_cmd(0x02); 00055 wait_us(1080 - AQM0802A_CMD_WAIT); 00056 } 00057 00058 void AQM0802A::setContrast(int contrast) { 00059 lcd_cmd(0x39); 00060 lcd_cmd(0x70 | ( contrast & 0xF)); // contrast Low 00061 lcd_cmd(0x5C | ((contrast >> 4) & 0x3)); // icon/booster/contrast High 00062 lcd_cmd(0x38); 00063 } 00064 00065 void AQM0802A::setCursor(int x, int y) { 00066 AQM0802A::x = x; 00067 AQM0802A::y = y; 00068 lcd_cmd(0x80 | 00069 ((y & (AQM0802A_MAX_ROWS - 1)) << 6) | 00070 (x & (AQM0802A_MAX_COLS - 1)) 00071 ); 00072 } 00073 00074 int AQM0802A::_putc(int value) { 00075 switch (value) { 00076 case '\b': 00077 if (x > 0) setCursor(--x, y); 00078 else if (y > 0) setCursor(AQM0802A_MAX_COLS - 1, --y); 00079 else setCursor(AQM0802A_MAX_COLS - 1, AQM0802A_MAX_ROWS - 1); 00080 break; 00081 case '\r': 00082 setCursor(0, y); 00083 break; 00084 default: 00085 if (value == '\n') { 00086 x = 0; 00087 } else { 00088 lcd_data(value); 00089 if (x < AQM0802A_MAX_COLS - 1) x++; 00090 else x = 0; 00091 } 00092 if (x == 0) { 00093 if (y < AQM0802A_MAX_ROWS - 1) y++; 00094 else y = 0; 00095 setCursor(0, y); 00096 } 00097 break; 00098 } 00099 return value; 00100 }
Generated on Wed Jul 13 2022 19:14:45 by
1.7.2