LCD I2C Library New depot for last update : https://github.com/YSI-LPS/lib_LCD_i2c_SPTLYI

Dependents:   TD1_exo1 TD1_exe1_suite TP3_exo1 TP3_exo2 ... more

New depot for last update : https://github.com/YSI-LPS/lib_LCD_i2c_SPTLYI

Library for Character / Alphanumeric LCD Module 2 lines of 16 characters - 2 x 16

http://fr.farnell.com/midas/mccog21605b6w-sptlyi/lcd-cog-2x16-stn-vert-b-l-i2c/dp/2063208

Committer:
YSI
Date:
Wed May 02 15:03:36 2018 +0000
Revision:
13:b0c643bbf1fa
Parent:
12:65ab16b1561b
update interrupt bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSI 8:71a280580031 1 /** LCD i2c SPTLYI class
YSI 8:71a280580031 2 *
YSI 8:71a280580031 3 * @purpose library for i2c LCD
YSI 8:71a280580031 4 *
YSI 8:71a280580031 5 * Utilisée pour écrire sur l'afficheur i2c SPTLYI 2x16.
YSI 8:71a280580031 6 *
YSI 8:71a280580031 7 * http://fr.farnell.com/midas/mccog21605b6w-sptlyi/lcd-cog-2x16-stn-vert-b-l-i2c/dp/2063208
YSI 8:71a280580031 8 *
YSI 8:71a280580031 9 * Copyright (c) 2014, cstyles (http://mbed.org)
YSI 8:71a280580031 10 *
YSI 8:71a280580031 11 * Exemple:
YSI 8:71a280580031 12 * @code
YSI 8:71a280580031 13 * #include "mbed.h"
YSI 8:71a280580031 14 * #include "lib_LCD_i2c_SPTLYI.h"
YSI 8:71a280580031 15 *
YSI 9:0acc7e2330c6 16 * LCD_I2C LCD;
YSI 9:0acc7e2330c6 17 * //LCD_I2C LCD(p28, p27, p26, 0x7C); //sda, scl, rst, only 4 slave address 0x7C 0x7D 0x7E 0x7F
YSI 9:0acc7e2330c6 18 *
YSI 8:71a280580031 19 * int main()
YSI 8:71a280580031 20 * {
YSI 9:0acc7e2330c6 21 * while(1)
YSI 9:0acc7e2330c6 22 * {
YSI 9:0acc7e2330c6 23 * for(int i = 0; i < 9999; i++)
YSI 9:0acc7e2330c6 24 * {
YSI 9:0acc7e2330c6 25 * LCD.clear();
YSI 9:0acc7e2330c6 26 * LCD.print(i);
YSI 9:0acc7e2330c6 27 * wait(0.25);
YSI 9:0acc7e2330c6 28 * }
YSI 9:0acc7e2330c6 29 * }
YSI 8:71a280580031 30 * }
YSI 8:71a280580031 31 * @endcode
YSI 8:71a280580031 32 * @file lib_LCD_i2c_SPTLYI.cpp
YSI 8:71a280580031 33 * @date Jan 2014
YSI 8:71a280580031 34 * @author Yannic Simon
YSI 8:71a280580031 35 */
YSI 0:0549f4c4896c 36 #include "lib_LCD_i2c_SPTLYI.h"
YSI 0:0549f4c4896c 37
YSI 6:65cf99fe9f91 38 #define I2C_Frequency 200000
YSI 8:71a280580031 39 #define Interrupts_OFF __disable_irq()
YSI 8:71a280580031 40 #define Interrupts_ON __enable_irq()
YSI 1:a805daa83dd0 41 #define Last_Controle_Byte 0x00
YSI 1:a805daa83dd0 42 #define First_Controle_Byte 0x80
YSI 1:a805daa83dd0 43 #define Register_Select_CByte 0x40
YSI 1:a805daa83dd0 44 #define Function_Set_IS0 0x38
YSI 1:a805daa83dd0 45 #define Function_Set_IS1 0x39
YSI 1:a805daa83dd0 46 #define Shift_Right_Cursor_Set 0x14
YSI 1:a805daa83dd0 47 #define Shift_Left_Cursor_Set 0x10
YSI 1:a805daa83dd0 48 #define Contrast_Set 0x79
YSI 1:a805daa83dd0 49 #define Power_Icon_Set 0x50
YSI 1:a805daa83dd0 50 #define Follower_Controle_Set 0x6F
YSI 1:a805daa83dd0 51 #define Entry_Mode_Set 0x04
YSI 1:a805daa83dd0 52 #define Display_ON_Set 0x0F
YSI 1:a805daa83dd0 53 #define Display_OFF_Set 0x08
YSI 1:a805daa83dd0 54 #define Cursor_ON_Set 0x0F
YSI 1:a805daa83dd0 55 #define Cursor_OFF_Set 0x0C
YSI 1:a805daa83dd0 56 #define Clear_Display 0x01
YSI 1:a805daa83dd0 57 #define Return_Home 0x02
YSI 1:a805daa83dd0 58
YSI 1:a805daa83dd0 59
YSI 0:0549f4c4896c 60
YSI 0:0549f4c4896c 61 LCD_I2C::LCD_I2C(PinName pin_sda, PinName pin_scl, PinName pin_rst, int address) : I2C(pin_sda, pin_scl), m_pin_rst(pin_rst), m_address(address)
YSI 0:0549f4c4896c 62 {
YSI 0:0549f4c4896c 63 reset();
YSI 0:0549f4c4896c 64 init();
YSI 0:0549f4c4896c 65 }
YSI 0:0549f4c4896c 66
YSI 0:0549f4c4896c 67 int LCD_I2C::init(void)
YSI 0:0549f4c4896c 68 {
YSI 1:a805daa83dd0 69 I2C::frequency(I2C_Frequency);
YSI 0:0549f4c4896c 70
YSI 1:a805daa83dd0 71 char data[12]={First_Controle_Byte,Function_Set_IS0,Last_Controle_Byte,Function_Set_IS1,Shift_Right_Cursor_Set,Contrast_Set,Power_Icon_Set,Follower_Controle_Set,Display_ON_Set,Clear_Display,Return_Home,Entry_Mode_Set};
YSI 13:b0c643bbf1fa 72 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 73 int ack = I2C::write(m_address, data, 12);
YSI 13:b0c643bbf1fa 74 // Interrupts_ON;
YSI 0:0549f4c4896c 75 wait_ms(1);
YSI 0:0549f4c4896c 76 return ack;
YSI 0:0549f4c4896c 77 }
YSI 0:0549f4c4896c 78
YSI 0:0549f4c4896c 79 void LCD_I2C::reset(void)
YSI 0:0549f4c4896c 80 {
YSI 0:0549f4c4896c 81 m_pin_rst.output();
YSI 0:0549f4c4896c 82 wait_ms(1);
YSI 0:0549f4c4896c 83 m_pin_rst.input();
YSI 0:0549f4c4896c 84 wait_ms(1);
YSI 4:38d0fe9c8eb6 85 X40_position_cursor = 0;
YSI 4:38d0fe9c8eb6 86 X80_position_cursor = 0;
YSI 4:38d0fe9c8eb6 87 Y2_position_cursor = 0;
YSI 0:0549f4c4896c 88 }
YSI 0:0549f4c4896c 89
YSI 0:0549f4c4896c 90 int LCD_I2C::clear(void)
YSI 0:0549f4c4896c 91 {
YSI 1:a805daa83dd0 92 char data[2]={Last_Controle_Byte,Clear_Display};
YSI 13:b0c643bbf1fa 93 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 94 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 95 // Interrupts_ON;
YSI 4:38d0fe9c8eb6 96 X40_position_cursor = 0;
YSI 4:38d0fe9c8eb6 97 X80_position_cursor = 0;
YSI 4:38d0fe9c8eb6 98 Y2_position_cursor = 0;
YSI 0:0549f4c4896c 99 wait_ms(1);
YSI 0:0549f4c4896c 100 return ack;
YSI 0:0549f4c4896c 101 }
YSI 0:0549f4c4896c 102
YSI 0:0549f4c4896c 103 int LCD_I2C::turn_on_cursor(void)
YSI 0:0549f4c4896c 104 {
YSI 1:a805daa83dd0 105 char data[2]={Last_Controle_Byte,Cursor_ON_Set};
YSI 13:b0c643bbf1fa 106 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 107 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 108 // Interrupts_ON;
YSI 0:0549f4c4896c 109 return ack;
YSI 0:0549f4c4896c 110 }
YSI 0:0549f4c4896c 111
YSI 0:0549f4c4896c 112 int LCD_I2C::turn_off_cursor(void)
YSI 0:0549f4c4896c 113 {
YSI 1:a805daa83dd0 114 char data[2]={Last_Controle_Byte,Cursor_OFF_Set};
YSI 13:b0c643bbf1fa 115 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 116 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 117 // Interrupts_ON;
YSI 0:0549f4c4896c 118 return ack;
YSI 0:0549f4c4896c 119 }
YSI 0:0549f4c4896c 120
YSI 0:0549f4c4896c 121 int LCD_I2C::turn_on_display(void)
YSI 0:0549f4c4896c 122 {
YSI 1:a805daa83dd0 123 char data[2]={Last_Controle_Byte,Display_ON_Set};
YSI 13:b0c643bbf1fa 124 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 125 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 126 // Interrupts_ON;
YSI 0:0549f4c4896c 127 return ack;
YSI 0:0549f4c4896c 128 }
YSI 0:0549f4c4896c 129
YSI 0:0549f4c4896c 130 int LCD_I2C::turn_off_display(void)
YSI 0:0549f4c4896c 131 {
YSI 1:a805daa83dd0 132 char data[2]={Last_Controle_Byte,Display_OFF_Set};
YSI 13:b0c643bbf1fa 133 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 134 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 135 // Interrupts_ON;
YSI 0:0549f4c4896c 136 return ack;
YSI 0:0549f4c4896c 137 }
YSI 0:0549f4c4896c 138
YSI 0:0549f4c4896c 139 int LCD_I2C::return_home_cursor(void)
YSI 0:0549f4c4896c 140 {
YSI 1:a805daa83dd0 141 char data[2]={Last_Controle_Byte,Return_Home};
YSI 13:b0c643bbf1fa 142 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 143 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 144 // Interrupts_ON;
YSI 4:38d0fe9c8eb6 145 X40_position_cursor = 0;
YSI 4:38d0fe9c8eb6 146 X80_position_cursor = 0;
YSI 4:38d0fe9c8eb6 147 Y2_position_cursor = 0;
YSI 0:0549f4c4896c 148 return ack;
YSI 0:0549f4c4896c 149 }
YSI 0:0549f4c4896c 150
YSI 0:0549f4c4896c 151 void LCD_I2C::shift_left_cursor(int n)
YSI 0:0549f4c4896c 152 {
YSI 1:a805daa83dd0 153 char data[3]={Last_Controle_Byte,Function_Set_IS0,Shift_Left_Cursor_Set};
YSI 0:0549f4c4896c 154 int i=0;
YSI 0:0549f4c4896c 155 for(i=0;i<n;i++)
YSI 0:0549f4c4896c 156 {
YSI 13:b0c643bbf1fa 157 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 158 I2C::write(m_address, data, 3);
YSI 13:b0c643bbf1fa 159 // Interrupts_ON;
YSI 0:0549f4c4896c 160 }
YSI 1:a805daa83dd0 161 X_move_position(-n);
YSI 0:0549f4c4896c 162 }
YSI 0:0549f4c4896c 163
YSI 0:0549f4c4896c 164 void LCD_I2C::shift_right_cursor(int n)
YSI 0:0549f4c4896c 165 {
YSI 1:a805daa83dd0 166 char data[3]={Last_Controle_Byte,Function_Set_IS0,Shift_Right_Cursor_Set};
YSI 0:0549f4c4896c 167 int i=0;
YSI 0:0549f4c4896c 168 for(i=0;i<n;i++)
YSI 0:0549f4c4896c 169 {
YSI 13:b0c643bbf1fa 170 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 171 I2C::write(m_address, data, 3);
YSI 13:b0c643bbf1fa 172 // Interrupts_ON;
YSI 0:0549f4c4896c 173 }
YSI 1:a805daa83dd0 174 X_move_position(n);
YSI 0:0549f4c4896c 175 }
YSI 0:0549f4c4896c 176
YSI 0:0549f4c4896c 177 int LCD_I2C::shift_line_cursor(void)
YSI 0:0549f4c4896c 178 {
YSI 1:a805daa83dd0 179 char data[4]={Last_Controle_Byte,Function_Set_IS0,0x40+0x00,0x80+0x40};
YSI 13:b0c643bbf1fa 180 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 181 int ack = I2C::write(m_address, data, 4);
YSI 13:b0c643bbf1fa 182 // Interrupts_ON;
YSI 4:38d0fe9c8eb6 183 X40_position_cursor = 0;
YSI 4:38d0fe9c8eb6 184 X80_position_cursor = 0;
YSI 4:38d0fe9c8eb6 185 Y2_position_cursor = 1;
YSI 0:0549f4c4896c 186 return ack;
YSI 0:0549f4c4896c 187 }
YSI 0:0549f4c4896c 188
YSI 1:a805daa83dd0 189 int LCD_I2C::set_position_cursor(int X)
YSI 0:0549f4c4896c 190 {
YSI 6:65cf99fe9f91 191 char CGRAM = 0x00;
YSI 6:65cf99fe9f91 192 char DDRAM = 0x00;
YSI 1:a805daa83dd0 193
YSI 4:38d0fe9c8eb6 194 if(X < 0) X = 0;
YSI 4:38d0fe9c8eb6 195 else if(X > 39) X = 39;
YSI 1:a805daa83dd0 196
YSI 4:38d0fe9c8eb6 197 if(Y2_position_cursor == 1)
YSI 0:0549f4c4896c 198 {
YSI 1:a805daa83dd0 199 CGRAM = X + 39; //0x27
YSI 1:a805daa83dd0 200 DDRAM = X + 64; //0x40
YSI 4:38d0fe9c8eb6 201 X80_position_cursor = X + 40;
YSI 0:0549f4c4896c 202 }else{
YSI 1:a805daa83dd0 203 CGRAM = X;
YSI 1:a805daa83dd0 204 DDRAM = X;
YSI 4:38d0fe9c8eb6 205 X80_position_cursor = X;
YSI 0:0549f4c4896c 206 }
YSI 1:a805daa83dd0 207
YSI 4:38d0fe9c8eb6 208 X40_position_cursor = X;
YSI 1:a805daa83dd0 209
YSI 6:65cf99fe9f91 210 CGRAM += 0x40;
YSI 6:65cf99fe9f91 211 DDRAM += 0x80;
YSI 6:65cf99fe9f91 212
YSI 6:65cf99fe9f91 213 char data[4]={Last_Controle_Byte,Function_Set_IS0,CGRAM,DDRAM};
YSI 13:b0c643bbf1fa 214 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 215 int ack = I2C::write(m_address, data, 4);
YSI 13:b0c643bbf1fa 216 // Interrupts_ON;
YSI 1:a805daa83dd0 217 return ack;
YSI 1:a805daa83dd0 218 }
YSI 1:a805daa83dd0 219
YSI 1:a805daa83dd0 220 int LCD_I2C::set_position_cursor(int X, int Y)
YSI 1:a805daa83dd0 221 {
YSI 6:65cf99fe9f91 222 char CGRAM = 0x00;
YSI 6:65cf99fe9f91 223 char DDRAM = 0x00;
YSI 1:a805daa83dd0 224
YSI 4:38d0fe9c8eb6 225 if(X < 0) X = 0;
YSI 4:38d0fe9c8eb6 226 else if(X > 39) X = 39;
YSI 4:38d0fe9c8eb6 227 if(Y < 0) Y = 0;
YSI 4:38d0fe9c8eb6 228 else if(Y > 1) Y = 1;
YSI 1:a805daa83dd0 229
YSI 1:a805daa83dd0 230 if(Y == 1)
YSI 1:a805daa83dd0 231 {
YSI 1:a805daa83dd0 232 CGRAM = X + 39; //0x27
YSI 1:a805daa83dd0 233 DDRAM = X + 64; //0x40
YSI 4:38d0fe9c8eb6 234 X80_position_cursor = X + 40;
YSI 1:a805daa83dd0 235 }else{
YSI 1:a805daa83dd0 236 CGRAM = X;
YSI 1:a805daa83dd0 237 DDRAM = X;
YSI 4:38d0fe9c8eb6 238 X80_position_cursor = X;
YSI 1:a805daa83dd0 239 }
YSI 1:a805daa83dd0 240
YSI 4:38d0fe9c8eb6 241 X40_position_cursor = X;
YSI 4:38d0fe9c8eb6 242 Y2_position_cursor = Y;
YSI 1:a805daa83dd0 243
YSI 6:65cf99fe9f91 244 CGRAM += 0x40;
YSI 6:65cf99fe9f91 245 DDRAM += 0x80;
YSI 6:65cf99fe9f91 246
YSI 6:65cf99fe9f91 247 char data[4]={Last_Controle_Byte,Function_Set_IS0,CGRAM,DDRAM};
YSI 13:b0c643bbf1fa 248 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 249 int ack = I2C::write(m_address, data, 4);
YSI 13:b0c643bbf1fa 250 // Interrupts_ON;
YSI 0:0549f4c4896c 251 return ack;
YSI 0:0549f4c4896c 252 }
YSI 0:0549f4c4896c 253
YSI 0:0549f4c4896c 254 void LCD_I2C::shift_left_display(int n)
YSI 0:0549f4c4896c 255 {
YSI 1:a805daa83dd0 256 char data[3]={Last_Controle_Byte,Function_Set_IS0,0x18};
YSI 0:0549f4c4896c 257 int i=0;
YSI 0:0549f4c4896c 258 for(i=0;i<n;i++)
YSI 0:0549f4c4896c 259 {
YSI 13:b0c643bbf1fa 260 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 261 I2C::write(m_address, data, 3);
YSI 13:b0c643bbf1fa 262 // Interrupts_ON;
YSI 0:0549f4c4896c 263 }
YSI 0:0549f4c4896c 264 }
YSI 0:0549f4c4896c 265
YSI 0:0549f4c4896c 266 void LCD_I2C::shift_right_display(int n)
YSI 0:0549f4c4896c 267 {
YSI 1:a805daa83dd0 268 char data[3]={Last_Controle_Byte,Function_Set_IS0,0x1C};
YSI 0:0549f4c4896c 269 int i=0;
YSI 0:0549f4c4896c 270 for(i=0;i<n;i++)
YSI 0:0549f4c4896c 271 {
YSI 13:b0c643bbf1fa 272 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 273 I2C::write(m_address, data, 3);
YSI 13:b0c643bbf1fa 274 // Interrupts_ON;
YSI 0:0549f4c4896c 275 }
YSI 0:0549f4c4896c 276 }
YSI 0:0549f4c4896c 277
YSI 0:0549f4c4896c 278 int LCD_I2C::enable_auto_shift_right_display(void)
YSI 0:0549f4c4896c 279 {
YSI 1:a805daa83dd0 280 char data[2]={Last_Controle_Byte,0x05};
YSI 13:b0c643bbf1fa 281 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 282 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 283 // Interrupts_ON;
YSI 0:0549f4c4896c 284 return ack;
YSI 0:0549f4c4896c 285 }
YSI 0:0549f4c4896c 286
YSI 0:0549f4c4896c 287 int LCD_I2C::enable_auto_shift_left_display(void)
YSI 0:0549f4c4896c 288 {
YSI 1:a805daa83dd0 289 char data[2]={Last_Controle_Byte,0x07};
YSI 13:b0c643bbf1fa 290 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 291 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 292 // Interrupts_ON;
YSI 0:0549f4c4896c 293 return ack;
YSI 0:0549f4c4896c 294 }
YSI 0:0549f4c4896c 295
YSI 0:0549f4c4896c 296 int LCD_I2C::disable_auto_shift_display(void)
YSI 0:0549f4c4896c 297 {
YSI 1:a805daa83dd0 298 char data[2]={Last_Controle_Byte,0x06};
YSI 13:b0c643bbf1fa 299 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 300 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 301 // Interrupts_ON;
YSI 0:0549f4c4896c 302 return ack;
YSI 0:0549f4c4896c 303 }
YSI 0:0549f4c4896c 304
YSI 0:0549f4c4896c 305 int LCD_I2C::auto_shift_right_cursor(void)
YSI 0:0549f4c4896c 306 {
YSI 1:a805daa83dd0 307 char data[2]={Last_Controle_Byte,0x06};
YSI 13:b0c643bbf1fa 308 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 309 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 310 // Interrupts_ON;
YSI 0:0549f4c4896c 311 return ack;
YSI 0:0549f4c4896c 312 }
YSI 0:0549f4c4896c 313
YSI 0:0549f4c4896c 314 int LCD_I2C::auto_shift_left_cursor(void)
YSI 0:0549f4c4896c 315 {
YSI 1:a805daa83dd0 316 char data[2]={Last_Controle_Byte,0x04};
YSI 13:b0c643bbf1fa 317 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 318 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 319 // Interrupts_ON;
YSI 0:0549f4c4896c 320 return ack;
YSI 0:0549f4c4896c 321 }
YSI 0:0549f4c4896c 322
YSI 1:a805daa83dd0 323 void LCD_I2C::X_move_position(int n)
YSI 1:a805daa83dd0 324 {
YSI 4:38d0fe9c8eb6 325 X80_position_cursor = (X80_position_cursor + n + 80)%80;
YSI 4:38d0fe9c8eb6 326 X40_position_cursor = X80_position_cursor%40;
YSI 4:38d0fe9c8eb6 327
YSI 4:38d0fe9c8eb6 328 if(X80_position_cursor > 39) Y2_position_cursor = 1;
YSI 4:38d0fe9c8eb6 329 else Y2_position_cursor = 0;
YSI 1:a805daa83dd0 330 }
YSI 1:a805daa83dd0 331
YSI 1:a805daa83dd0 332 int LCD_I2C::get_X_position_cursor(void)
YSI 1:a805daa83dd0 333 {
YSI 4:38d0fe9c8eb6 334 return X40_position_cursor;
YSI 1:a805daa83dd0 335 }
YSI 1:a805daa83dd0 336
YSI 1:a805daa83dd0 337 int LCD_I2C::get_Y_position_cursor(void)
YSI 1:a805daa83dd0 338 {
YSI 4:38d0fe9c8eb6 339 return Y2_position_cursor;
YSI 4:38d0fe9c8eb6 340 }
YSI 4:38d0fe9c8eb6 341
YSI 4:38d0fe9c8eb6 342 char LCD_I2C::read(void)
YSI 4:38d0fe9c8eb6 343 {
YSI 4:38d0fe9c8eb6 344 return LCD_Data_Register[X80_position_cursor];
YSI 4:38d0fe9c8eb6 345 }
YSI 4:38d0fe9c8eb6 346
YSI 4:38d0fe9c8eb6 347 char LCD_I2C::read(int X, int Y)
YSI 4:38d0fe9c8eb6 348 {
YSI 4:38d0fe9c8eb6 349 if(X < 0) X = 0;
YSI 4:38d0fe9c8eb6 350 else if(X > 39) X = 39;
YSI 4:38d0fe9c8eb6 351 if(Y < 0) Y = 0;
YSI 4:38d0fe9c8eb6 352 else if(Y > 1) Y = 1;
YSI 4:38d0fe9c8eb6 353
YSI 4:38d0fe9c8eb6 354 return LCD_Data_Register[X+(40*Y)];
YSI 1:a805daa83dd0 355 }
YSI 1:a805daa83dd0 356
YSI 0:0549f4c4896c 357 int LCD_I2C::print(char c)
YSI 0:0549f4c4896c 358 {
YSI 1:a805daa83dd0 359 char data[2]={Register_Select_CByte,c};
YSI 13:b0c643bbf1fa 360 // Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 4:38d0fe9c8eb6 361 int ack = I2C::write(m_address, data, 2);
YSI 13:b0c643bbf1fa 362 // Interrupts_ON;
YSI 4:38d0fe9c8eb6 363 LCD_Data_Register[X80_position_cursor] = c;
YSI 4:38d0fe9c8eb6 364 X_move_position(1);
YSI 0:0549f4c4896c 365 return ack;
YSI 0:0549f4c4896c 366 }
YSI 0:0549f4c4896c 367
YSI 1:a805daa83dd0 368 int LCD_I2C::print(short nb)
YSI 1:a805daa83dd0 369 {
YSI 1:a805daa83dd0 370 int n=0;
YSI 10:246c6f2dc45b 371 char buffer[30]={0};
YSI 10:246c6f2dc45b 372 n = snprintf(buffer,30,"%d",nb);
YSI 4:38d0fe9c8eb6 373 return putnc(buffer,n);
YSI 1:a805daa83dd0 374 }
YSI 1:a805daa83dd0 375
YSI 1:a805daa83dd0 376 int LCD_I2C::print(unsigned short nb)
YSI 1:a805daa83dd0 377 {
YSI 1:a805daa83dd0 378 int n=0;
YSI 10:246c6f2dc45b 379 char buffer[30]={0};
YSI 10:246c6f2dc45b 380 n = snprintf(buffer,30,"%u",nb);
YSI 4:38d0fe9c8eb6 381 return putnc(buffer,n);
YSI 1:a805daa83dd0 382 }
YSI 1:a805daa83dd0 383
YSI 1:a805daa83dd0 384 int LCD_I2C::print(int nb)
YSI 1:a805daa83dd0 385 {
YSI 1:a805daa83dd0 386 int n=0;
YSI 10:246c6f2dc45b 387 char buffer[30]={0};
YSI 10:246c6f2dc45b 388 n = snprintf(buffer,30,"%d",nb);
YSI 4:38d0fe9c8eb6 389 return putnc(buffer,n);
YSI 1:a805daa83dd0 390 }
YSI 1:a805daa83dd0 391
YSI 1:a805daa83dd0 392 int LCD_I2C::print(unsigned int nb)
YSI 1:a805daa83dd0 393 {
YSI 1:a805daa83dd0 394 int n=0;
YSI 10:246c6f2dc45b 395 char buffer[30]={0};
YSI 10:246c6f2dc45b 396 n = snprintf(buffer,30,"%u",nb);
YSI 4:38d0fe9c8eb6 397 return putnc(buffer,n);
YSI 1:a805daa83dd0 398 }
YSI 1:a805daa83dd0 399
YSI 1:a805daa83dd0 400 int LCD_I2C::print(long long nb)
YSI 1:a805daa83dd0 401 {
YSI 1:a805daa83dd0 402 int n=0;
YSI 10:246c6f2dc45b 403 char buffer[30]={0};
YSI 10:246c6f2dc45b 404 n = snprintf(buffer,30,"%lld",nb);
YSI 4:38d0fe9c8eb6 405 X_move_position(n);
YSI 4:38d0fe9c8eb6 406 return putnc(buffer,n);
YSI 1:a805daa83dd0 407 }
YSI 1:a805daa83dd0 408
YSI 1:a805daa83dd0 409 int LCD_I2C::print(unsigned long long nb)
YSI 1:a805daa83dd0 410 {
YSI 1:a805daa83dd0 411 int n=0;
YSI 10:246c6f2dc45b 412 char buffer[30]={0};
YSI 10:246c6f2dc45b 413 n = snprintf(buffer,30,"%llu",nb);
YSI 4:38d0fe9c8eb6 414 return putnc(buffer,n);
YSI 1:a805daa83dd0 415 }
YSI 1:a805daa83dd0 416
YSI 1:a805daa83dd0 417 int LCD_I2C::print(float nb)
YSI 1:a805daa83dd0 418 {
YSI 1:a805daa83dd0 419 int n=0;
YSI 10:246c6f2dc45b 420 char buffer[30]={0};
YSI 10:246c6f2dc45b 421 n = snprintf(buffer,30,"%f",nb);
YSI 4:38d0fe9c8eb6 422 return putnc(buffer,n);
YSI 1:a805daa83dd0 423 }
YSI 1:a805daa83dd0 424
YSI 1:a805daa83dd0 425 int LCD_I2C::print(double nb)
YSI 1:a805daa83dd0 426 {
YSI 1:a805daa83dd0 427 int n=0;
YSI 10:246c6f2dc45b 428 char buffer[30]={0};
YSI 10:246c6f2dc45b 429 n = snprintf(buffer,30,"%lf",nb);
YSI 4:38d0fe9c8eb6 430 return putnc(buffer,n);
YSI 1:a805daa83dd0 431 }
YSI 1:a805daa83dd0 432
YSI 0:0549f4c4896c 433 int LCD_I2C::print(char *s)
YSI 0:0549f4c4896c 434 {
YSI 4:38d0fe9c8eb6 435 return putnc(s,strlen(s));
YSI 0:0549f4c4896c 436 }
YSI 0:0549f4c4896c 437
YSI 11:86ebe0fc54f9 438 int LCD_I2C::print(const char *format, ... )
YSI 1:a805daa83dd0 439 {
YSI 1:a805daa83dd0 440 int n=0;
YSI 10:246c6f2dc45b 441 char buffer[256]={0};
YSI 4:38d0fe9c8eb6 442 va_list args;
YSI 10:246c6f2dc45b 443 va_start(args, format);
YSI 10:246c6f2dc45b 444 n = vsnprintf(buffer,256,format,args);
YSI 4:38d0fe9c8eb6 445 va_end(args);
YSI 4:38d0fe9c8eb6 446 return putnc(buffer,n);
YSI 4:38d0fe9c8eb6 447 }
YSI 4:38d0fe9c8eb6 448
YSI 10:246c6f2dc45b 449 int LCD_I2C::putnc(char *s,int n)
YSI 1:a805daa83dd0 450 {
YSI 10:246c6f2dc45b 451 if(n > 79) n = 79;
YSI 10:246c6f2dc45b 452 else if(n < 0) n = 0;
YSI 10:246c6f2dc45b 453 int ack=0, i=0;
YSI 10:246c6f2dc45b 454 char *data = (char *)calloc(n+1, sizeof(*data));
YSI 10:246c6f2dc45b 455 data[0]=Register_Select_CByte;
YSI 10:246c6f2dc45b 456 for(i=0; i<n; i++)
YSI 10:246c6f2dc45b 457 {
YSI 10:246c6f2dc45b 458 data[i+1] = s[i];
YSI 10:246c6f2dc45b 459 LCD_Data_Register[X80_position_cursor+i] = s[i];
YSI 10:246c6f2dc45b 460 }
YSI 12:65ab16b1561b 461 //Interrupts_OFF; // Interdit depuis 2018 si I2C utilise en interrupt
YSI 10:246c6f2dc45b 462 ack = I2C::write(m_address, data, n+1);
YSI 12:65ab16b1561b 463 //Interrupts_ON;
YSI 10:246c6f2dc45b 464 X_move_position(n);
YSI 10:246c6f2dc45b 465 free(data);
YSI 10:246c6f2dc45b 466 return ack;
YSI 1:a805daa83dd0 467 }