AQM1602 library
Dependents: mbed_AQM1602 CatPot_Main_T_2v00 CatPot_2v10_T_Main CatPot_2v20_T_Main ... more
AQM1602.cpp
00001 //********************** 00002 // AQM1602.cpp for mbed 00003 // 00004 // AQM1602 lcd(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // AQM1602 lcd(i2c); 00008 // 00009 // (C)Copyright 2015 All rights reserved by Y.Onodera 00010 // http://einstlab.web.fc2.com 00011 //********************** 00012 00013 #include "mbed.h" 00014 #include "AQM1602.h" 00015 00016 AQM1602::AQM1602 (PinName sda, PinName scl) : _i2c(sda, scl) { 00017 init(); 00018 } 00019 AQM1602::AQM1602 (I2C& p_i2c) : _i2c(p_i2c) { 00020 init(); 00021 } 00022 00023 void AQM1602::put(unsigned char a, unsigned char b) 00024 { 00025 buf[0]=a; 00026 buf[1]=b; 00027 _i2c.write(AQM1602_ADDR, buf, 2); 00028 } 00029 00030 00031 void AQM1602::get(unsigned char a) 00032 { 00033 buf[0] = a; 00034 _i2c.write(AQM1602_ADDR, buf, 1, true); // no stop, repeated 00035 _i2c.read( AQM1602_ADDR, buf, 1); 00036 00037 } 00038 00039 void AQM1602::cls() 00040 { 00041 // Clear Display = 0x01 00042 put(CMD, 0x01); 00043 // Wait 1.08ms 00044 wait_ms(2); 00045 00046 } 00047 00048 void AQM1602::locate(int x, int y) 00049 { 00050 00051 // 16x2 00052 put(CMD, 0x80 + y*0x40 + x); 00053 00054 } 00055 00056 void AQM1602::print(const char *a) 00057 { 00058 00059 while(*a != '\0') 00060 { 00061 put(DAT, *a); 00062 a++; 00063 } 00064 00065 } 00066 00067 void AQM1602::init() 00068 { 00069 // Wait 40ms 00070 wait_ms(100); 00071 // Function set = 0x38 00072 put(CMD, 0x38); 00073 // Wait 26.3us 00074 wait_ms(1); 00075 // Function set = 0x39 00076 put(CMD, 0x39); 00077 // Wait 26.3us 00078 wait_ms(1); 00079 // Internal OSC frequency = 0x14 00080 put(CMD, 0x14); 00081 // Wait 26.3us 00082 wait_ms(1); 00083 // Contrast set = 0x70 00084 put(CMD, 0x70); 00085 // Wait 26.3us 00086 wait_ms(1); 00087 // Power/ICON/Contrast control = 0x56 00088 put(CMD, 0x56); 00089 // Wait 26.3us 00090 wait_ms(1); 00091 // Follower control = 0x6C 00092 put(CMD, 0x6C); 00093 // Wait 200ms 00094 wait_ms(200); 00095 // Function set = 0x38 00096 put(CMD, 0x38); 00097 // Wait 26.3us 00098 wait_ms(1); 00099 // Display ON/OFF control = 0x0C 00100 put(CMD, 0x0C); 00101 // Wait 26.3us 00102 wait_ms(1); 00103 // Clear Display = 0x01 00104 put(CMD, 0x01); 00105 // Wait 1.08ms 00106 wait_ms(2); 00107 00108 } 00109 00110 00111
Generated on Thu Jul 14 2022 13:39:14 by 1.7.2