Help me please

Dependencies:   mbed HCSR04

Committer:
koko1121
Date:
Wed Jan 15 17:17:21 2020 +0000
Revision:
0:b78e02ab7cde
Error: Too many arguments in function call in "main.cpp", Line: 27, Col: 28;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
koko1121 0:b78e02ab7cde 1 #include "LiquidCrystal_I2C.h"
koko1121 0:b78e02ab7cde 2 #include "mbed.h"
koko1121 0:b78e02ab7cde 3
koko1121 0:b78e02ab7cde 4 // When the display powers up, it is configured as follows:
koko1121 0:b78e02ab7cde 5 //
koko1121 0:b78e02ab7cde 6 // 1. Display clear
koko1121 0:b78e02ab7cde 7 // 2. Function set:
koko1121 0:b78e02ab7cde 8 // DL = 1; 8-bit interface data
koko1121 0:b78e02ab7cde 9 // N = 0; 1-line display
koko1121 0:b78e02ab7cde 10 // F = 0; 5x8 dot character font
koko1121 0:b78e02ab7cde 11 // 3. Display on/off control:
koko1121 0:b78e02ab7cde 12 // D = 0; Display off
koko1121 0:b78e02ab7cde 13 // C = 0; Cursor off
koko1121 0:b78e02ab7cde 14 // B = 0; Blinking off
koko1121 0:b78e02ab7cde 15 // 4. Entry mode set:
koko1121 0:b78e02ab7cde 16 // I/D = 1; Increment by 1
koko1121 0:b78e02ab7cde 17 // S = 0; No shift
koko1121 0:b78e02ab7cde 18 //
koko1121 0:b78e02ab7cde 19 // Note, however, that resetting the Arduino doesn't reset the LCD, so we
koko1121 0:b78e02ab7cde 20 // can't assume that its in that state when a sketch starts (and the
koko1121 0:b78e02ab7cde 21 // LiquidCrystal constructor is called).
koko1121 0:b78e02ab7cde 22
koko1121 0:b78e02ab7cde 23
koko1121 0:b78e02ab7cde 24 I2C _i2c(D14, D15); // SDA, SCL
koko1121 0:b78e02ab7cde 25
koko1121 0:b78e02ab7cde 26 LiquidCrystal_I2C::LiquidCrystal_I2C(unsigned char lcd_addr, unsigned char lcd_cols, unsigned char lcd_rows, unsigned char charsize)
koko1121 0:b78e02ab7cde 27 {
koko1121 0:b78e02ab7cde 28 _addr = lcd_addr;
koko1121 0:b78e02ab7cde 29 _cols = lcd_cols;
koko1121 0:b78e02ab7cde 30 _rows = lcd_rows;
koko1121 0:b78e02ab7cde 31 _charsize = charsize;
koko1121 0:b78e02ab7cde 32 _backlightval = LCD_BACKLIGHT;
koko1121 0:b78e02ab7cde 33 }
koko1121 0:b78e02ab7cde 34
koko1121 0:b78e02ab7cde 35 void LiquidCrystal_I2C::begin() {
koko1121 0:b78e02ab7cde 36 //Wire.begin();
koko1121 0:b78e02ab7cde 37 _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
koko1121 0:b78e02ab7cde 38
koko1121 0:b78e02ab7cde 39 if (_rows > 1) {
koko1121 0:b78e02ab7cde 40 _displayfunction |= LCD_2LINE;
koko1121 0:b78e02ab7cde 41 }
koko1121 0:b78e02ab7cde 42
koko1121 0:b78e02ab7cde 43 // for some 1 line displays you can select a 10 pixel high font
koko1121 0:b78e02ab7cde 44 if ((_charsize != 0) && (_rows == 1)) {
koko1121 0:b78e02ab7cde 45 _displayfunction |= LCD_5x10DOTS;
koko1121 0:b78e02ab7cde 46 }
koko1121 0:b78e02ab7cde 47
koko1121 0:b78e02ab7cde 48 // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
koko1121 0:b78e02ab7cde 49 // according to datasheet, we need at least 40ms after power rises above 2.7V
koko1121 0:b78e02ab7cde 50 // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
koko1121 0:b78e02ab7cde 51 wait_ms(50);
koko1121 0:b78e02ab7cde 52
koko1121 0:b78e02ab7cde 53 // Now we pull both RS and R/W low to begin commands
koko1121 0:b78e02ab7cde 54 expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
koko1121 0:b78e02ab7cde 55 wait_ms(1000);
koko1121 0:b78e02ab7cde 56
koko1121 0:b78e02ab7cde 57 //put the LCD into 4 bit mode
koko1121 0:b78e02ab7cde 58 // this is according to the hitachi HD44780 datasheet
koko1121 0:b78e02ab7cde 59 // figure 24, pg 46
koko1121 0:b78e02ab7cde 60
koko1121 0:b78e02ab7cde 61 // we start in 8bit mode, try to set 4 bit mode
koko1121 0:b78e02ab7cde 62 write4bits(0x03 << 4);
koko1121 0:b78e02ab7cde 63 wait_us(4500); // wait min 4.1ms
koko1121 0:b78e02ab7cde 64
koko1121 0:b78e02ab7cde 65 // second try
koko1121 0:b78e02ab7cde 66 write4bits(0x03 << 4);
koko1121 0:b78e02ab7cde 67 wait_us(4500); // wait min 4.1ms
koko1121 0:b78e02ab7cde 68
koko1121 0:b78e02ab7cde 69 // third go!
koko1121 0:b78e02ab7cde 70 write4bits(0x03 << 4);
koko1121 0:b78e02ab7cde 71 wait_us(150);
koko1121 0:b78e02ab7cde 72
koko1121 0:b78e02ab7cde 73 // finally, set to 4-bit interface
koko1121 0:b78e02ab7cde 74 write4bits(0x02 << 4);
koko1121 0:b78e02ab7cde 75
koko1121 0:b78e02ab7cde 76 // set # lines, font size, etc.
koko1121 0:b78e02ab7cde 77 command(LCD_FUNCTIONSET | _displayfunction);
koko1121 0:b78e02ab7cde 78
koko1121 0:b78e02ab7cde 79 // turn the display on with no cursor or blinking default
koko1121 0:b78e02ab7cde 80 _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
koko1121 0:b78e02ab7cde 81 display();
koko1121 0:b78e02ab7cde 82
koko1121 0:b78e02ab7cde 83 // clear it off
koko1121 0:b78e02ab7cde 84 clear();
koko1121 0:b78e02ab7cde 85
koko1121 0:b78e02ab7cde 86 // Initialize to default text direction (for roman languages)
koko1121 0:b78e02ab7cde 87 _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
koko1121 0:b78e02ab7cde 88
koko1121 0:b78e02ab7cde 89 // set the entry mode
koko1121 0:b78e02ab7cde 90 command(LCD_ENTRYMODESET | _displaymode);
koko1121 0:b78e02ab7cde 91
koko1121 0:b78e02ab7cde 92 home();
koko1121 0:b78e02ab7cde 93 }
koko1121 0:b78e02ab7cde 94
koko1121 0:b78e02ab7cde 95 /********** high level commands, for the user! */
koko1121 0:b78e02ab7cde 96 void LiquidCrystal_I2C::clear(){
koko1121 0:b78e02ab7cde 97 command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
koko1121 0:b78e02ab7cde 98 wait_us(2000); // this command takes a long time!
koko1121 0:b78e02ab7cde 99 }
koko1121 0:b78e02ab7cde 100
koko1121 0:b78e02ab7cde 101 void LiquidCrystal_I2C::home(){
koko1121 0:b78e02ab7cde 102 command(LCD_RETURNHOME); // set cursor position to zero
koko1121 0:b78e02ab7cde 103 wait_us(2000); // this command takes a long time!
koko1121 0:b78e02ab7cde 104 }
koko1121 0:b78e02ab7cde 105
koko1121 0:b78e02ab7cde 106 void LiquidCrystal_I2C::setCursor(unsigned char col, unsigned char row){
koko1121 0:b78e02ab7cde 107 int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
koko1121 0:b78e02ab7cde 108 if (row > _rows) {
koko1121 0:b78e02ab7cde 109 row = _rows-1; // we count rows starting w/0
koko1121 0:b78e02ab7cde 110 }
koko1121 0:b78e02ab7cde 111 command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
koko1121 0:b78e02ab7cde 112 }
koko1121 0:b78e02ab7cde 113
koko1121 0:b78e02ab7cde 114 // Turn the display on/off (quickly)
koko1121 0:b78e02ab7cde 115 void LiquidCrystal_I2C::noDisplay() {
koko1121 0:b78e02ab7cde 116 _displaycontrol &= ~LCD_DISPLAYON;
koko1121 0:b78e02ab7cde 117 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 118 }
koko1121 0:b78e02ab7cde 119 void LiquidCrystal_I2C::display() {
koko1121 0:b78e02ab7cde 120 _displaycontrol |= LCD_DISPLAYON;
koko1121 0:b78e02ab7cde 121 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 122 }
koko1121 0:b78e02ab7cde 123
koko1121 0:b78e02ab7cde 124 // Turns the underline cursor on/off
koko1121 0:b78e02ab7cde 125 void LiquidCrystal_I2C::noCursor() {
koko1121 0:b78e02ab7cde 126 _displaycontrol &= ~LCD_CURSORON;
koko1121 0:b78e02ab7cde 127 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 128 }
koko1121 0:b78e02ab7cde 129 void LiquidCrystal_I2C::cursor() {
koko1121 0:b78e02ab7cde 130 _displaycontrol |= LCD_CURSORON;
koko1121 0:b78e02ab7cde 131 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 132 }
koko1121 0:b78e02ab7cde 133
koko1121 0:b78e02ab7cde 134 // Turn on and off the blinking cursor
koko1121 0:b78e02ab7cde 135 void LiquidCrystal_I2C::noBlink() {
koko1121 0:b78e02ab7cde 136 _displaycontrol &= ~LCD_BLINKON;
koko1121 0:b78e02ab7cde 137 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 138 }
koko1121 0:b78e02ab7cde 139 void LiquidCrystal_I2C::blink() {
koko1121 0:b78e02ab7cde 140 _displaycontrol |= LCD_BLINKON;
koko1121 0:b78e02ab7cde 141 command(LCD_DISPLAYCONTROL | _displaycontrol);
koko1121 0:b78e02ab7cde 142 }
koko1121 0:b78e02ab7cde 143
koko1121 0:b78e02ab7cde 144 // These commands scroll the display without changing the RAM
koko1121 0:b78e02ab7cde 145 void LiquidCrystal_I2C::scrollDisplayLeft(void) {
koko1121 0:b78e02ab7cde 146 command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
koko1121 0:b78e02ab7cde 147 }
koko1121 0:b78e02ab7cde 148 void LiquidCrystal_I2C::scrollDisplayRight(void) {
koko1121 0:b78e02ab7cde 149 command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
koko1121 0:b78e02ab7cde 150 }
koko1121 0:b78e02ab7cde 151
koko1121 0:b78e02ab7cde 152 // This is for text that flows Left to Right
koko1121 0:b78e02ab7cde 153 void LiquidCrystal_I2C::leftToRight(void) {
koko1121 0:b78e02ab7cde 154 _displaymode |= LCD_ENTRYLEFT;
koko1121 0:b78e02ab7cde 155 command(LCD_ENTRYMODESET | _displaymode);
koko1121 0:b78e02ab7cde 156 }
koko1121 0:b78e02ab7cde 157
koko1121 0:b78e02ab7cde 158 // This is for text that flows Right to Left
koko1121 0:b78e02ab7cde 159 void LiquidCrystal_I2C::rightToLeft(void) {
koko1121 0:b78e02ab7cde 160 _displaymode &= ~LCD_ENTRYLEFT;
koko1121 0:b78e02ab7cde 161 command(LCD_ENTRYMODESET | _displaymode);
koko1121 0:b78e02ab7cde 162 }
koko1121 0:b78e02ab7cde 163
koko1121 0:b78e02ab7cde 164 // This will 'right justify' text from the cursor
koko1121 0:b78e02ab7cde 165 void LiquidCrystal_I2C::autoscroll(void) {
koko1121 0:b78e02ab7cde 166 _displaymode |= LCD_ENTRYSHIFTINCREMENT;
koko1121 0:b78e02ab7cde 167 command(LCD_ENTRYMODESET | _displaymode);
koko1121 0:b78e02ab7cde 168 }
koko1121 0:b78e02ab7cde 169
koko1121 0:b78e02ab7cde 170 // This will 'left justify' text from the cursor
koko1121 0:b78e02ab7cde 171 void LiquidCrystal_I2C::noAutoscroll(void) {
koko1121 0:b78e02ab7cde 172 _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
koko1121 0:b78e02ab7cde 173 command(LCD_ENTRYMODESET | _displaymode);
koko1121 0:b78e02ab7cde 174 }
koko1121 0:b78e02ab7cde 175
koko1121 0:b78e02ab7cde 176 // Allows us to fill the first 8 CGRAM locations
koko1121 0:b78e02ab7cde 177 // with custom characters
koko1121 0:b78e02ab7cde 178 void LiquidCrystal_I2C::createChar(unsigned char location, unsigned char charmap[]) {
koko1121 0:b78e02ab7cde 179 location &= 0x7; // we only have 8 locations 0-7
koko1121 0:b78e02ab7cde 180 command(LCD_SETCGRAMADDR | (location << 3));
koko1121 0:b78e02ab7cde 181 for (int i=0; i<8; i++) {
koko1121 0:b78e02ab7cde 182 write(charmap[i]);
koko1121 0:b78e02ab7cde 183 }
koko1121 0:b78e02ab7cde 184 }
koko1121 0:b78e02ab7cde 185
koko1121 0:b78e02ab7cde 186 // Turn the (optional) backlight off/on
koko1121 0:b78e02ab7cde 187 void LiquidCrystal_I2C::noBacklight(void) {
koko1121 0:b78e02ab7cde 188 _backlightval=LCD_NOBACKLIGHT;
koko1121 0:b78e02ab7cde 189 expanderWrite(0);
koko1121 0:b78e02ab7cde 190 }
koko1121 0:b78e02ab7cde 191
koko1121 0:b78e02ab7cde 192 void LiquidCrystal_I2C::backlight(void) {
koko1121 0:b78e02ab7cde 193 _backlightval=LCD_BACKLIGHT;
koko1121 0:b78e02ab7cde 194 expanderWrite(0);
koko1121 0:b78e02ab7cde 195 }
koko1121 0:b78e02ab7cde 196 bool LiquidCrystal_I2C::getBacklight() {
koko1121 0:b78e02ab7cde 197 return _backlightval == LCD_BACKLIGHT;
koko1121 0:b78e02ab7cde 198 }
koko1121 0:b78e02ab7cde 199
koko1121 0:b78e02ab7cde 200
koko1121 0:b78e02ab7cde 201 /*********** mid level commands, for sending data/cmds */
koko1121 0:b78e02ab7cde 202
koko1121 0:b78e02ab7cde 203 inline void LiquidCrystal_I2C::command(unsigned char value) {
koko1121 0:b78e02ab7cde 204 send(value, 0);
koko1121 0:b78e02ab7cde 205 }
koko1121 0:b78e02ab7cde 206
koko1121 0:b78e02ab7cde 207 inline int LiquidCrystal_I2C::write(unsigned char value) {
koko1121 0:b78e02ab7cde 208 send(value, Rs);
koko1121 0:b78e02ab7cde 209 return 1;
koko1121 0:b78e02ab7cde 210 }
koko1121 0:b78e02ab7cde 211
koko1121 0:b78e02ab7cde 212
koko1121 0:b78e02ab7cde 213 /************ low level data pushing commands **********/
koko1121 0:b78e02ab7cde 214
koko1121 0:b78e02ab7cde 215 // write either command or data
koko1121 0:b78e02ab7cde 216 void LiquidCrystal_I2C::send(unsigned char value, unsigned char mode) {
koko1121 0:b78e02ab7cde 217 unsigned char highnib=value&0xf0;
koko1121 0:b78e02ab7cde 218 unsigned char lownib=(value<<4)&0xf0;
koko1121 0:b78e02ab7cde 219 write4bits((highnib)|mode);
koko1121 0:b78e02ab7cde 220 write4bits((lownib)|mode);
koko1121 0:b78e02ab7cde 221 }
koko1121 0:b78e02ab7cde 222
koko1121 0:b78e02ab7cde 223 void LiquidCrystal_I2C::write4bits(unsigned char value) {
koko1121 0:b78e02ab7cde 224 expanderWrite(value);
koko1121 0:b78e02ab7cde 225 pulseEnable(value);
koko1121 0:b78e02ab7cde 226 }
koko1121 0:b78e02ab7cde 227
koko1121 0:b78e02ab7cde 228 void LiquidCrystal_I2C::expanderWrite(unsigned char _data){
koko1121 0:b78e02ab7cde 229 char data_write[2];
koko1121 0:b78e02ab7cde 230 data_write[0] = _data | _backlightval;
koko1121 0:b78e02ab7cde 231 //Wire.beginTransmission(_addr);
koko1121 0:b78e02ab7cde 232 //Wire.write((int)(_data) | _backlightval);
koko1121 0:b78e02ab7cde 233 //Wire.endTransmission();
koko1121 0:b78e02ab7cde 234 _i2c.write(_addr, data_write, 1, 0);
koko1121 0:b78e02ab7cde 235 _i2c.stop();
koko1121 0:b78e02ab7cde 236 }
koko1121 0:b78e02ab7cde 237
koko1121 0:b78e02ab7cde 238 void LiquidCrystal_I2C::pulseEnable(unsigned char _data){
koko1121 0:b78e02ab7cde 239 expanderWrite(_data | En); // En high
koko1121 0:b78e02ab7cde 240 wait_us(1); // enable pulse must be >450ns
koko1121 0:b78e02ab7cde 241
koko1121 0:b78e02ab7cde 242 expanderWrite(_data & ~En); // En low
koko1121 0:b78e02ab7cde 243 wait_us(50); // commands need > 37us to settle
koko1121 0:b78e02ab7cde 244 }
koko1121 0:b78e02ab7cde 245
koko1121 0:b78e02ab7cde 246 void LiquidCrystal_I2C::load_custom_character(unsigned char char_num, unsigned char *rows){
koko1121 0:b78e02ab7cde 247 createChar(char_num, rows);
koko1121 0:b78e02ab7cde 248 }
koko1121 0:b78e02ab7cde 249
koko1121 0:b78e02ab7cde 250 void LiquidCrystal_I2C::setBacklight(unsigned char new_val){
koko1121 0:b78e02ab7cde 251 if (new_val) {
koko1121 0:b78e02ab7cde 252 backlight(); // turn backlight on
koko1121 0:b78e02ab7cde 253 } else {
koko1121 0:b78e02ab7cde 254 noBacklight(); // turn backlight off
koko1121 0:b78e02ab7cde 255 }
koko1121 0:b78e02ab7cde 256 }
koko1121 0:b78e02ab7cde 257
koko1121 0:b78e02ab7cde 258 void LiquidCrystal_I2C::printstr(const char c[]){
koko1121 0:b78e02ab7cde 259 //This function is not identical to the function used for "real" I2C displays
koko1121 0:b78e02ab7cde 260 //it's here so the user sketch doesn't have to be changed
koko1121 0:b78e02ab7cde 261 //print(c);
koko1121 0:b78e02ab7cde 262 }
koko1121 0:b78e02ab7cde 263
koko1121 0:b78e02ab7cde 264 int LiquidCrystal_I2C::print(const char* text) {
koko1121 0:b78e02ab7cde 265
koko1121 0:b78e02ab7cde 266 while (*text !=0) {
koko1121 0:b78e02ab7cde 267 //_putc(*text);
koko1121 0:b78e02ab7cde 268 send(*text, Rs);
koko1121 0:b78e02ab7cde 269 text++;
koko1121 0:b78e02ab7cde 270 }
koko1121 0:b78e02ab7cde 271 return 0;
koko1121 0:b78e02ab7cde 272 }
koko1121 0:b78e02ab7cde 273
koko1121 0:b78e02ab7cde 274 /*
koko1121 0:b78e02ab7cde 275 void lcd_dat(unsigned char p)
koko1121 0:b78e02ab7cde 276 {
koko1121 0:b78e02ab7cde 277 PORTC |= (1 << RS)|(1 << EN); // RS = 1, EN = 1 (начало записи команды в LCD)
koko1121 0:b78e02ab7cde 278 PORTD = p; // Вывод команды на шину DB0-7 LCD
koko1121 0:b78e02ab7cde 279 _delay_us(100); // Длительность сигнала EN
koko1121 0:b78e02ab7cde 280 PORTC &= ~(1 << EN); // EN = 0 (конец записи команды в LCD)
koko1121 0:b78e02ab7cde 281 _delay_us(100); // Пауза для выполнения команды
koko1121 0:b78e02ab7cde 282 }
koko1121 0:b78e02ab7cde 283 */