lib_LCD_oem http://www.lextronic.fr/P764-afficheur-4-x-20-caracteres-retro-eclaire-vert.html YSI
Dependents: lib_LCD_oem_example libs_YSI_example TP3exo1
lib_LCD_oem_ELCD.cpp@6:02f5e2861a9b, 2017-06-06 (annotated)
- Committer:
- YSI
- Date:
- Tue Jun 06 14:00:30 2017 +0000
- Revision:
- 6:02f5e2861a9b
- Parent:
- 5:291652c14402
LCD_oem_example
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| YSI | 6:02f5e2861a9b | 1 | /** LCD oem ELCD class |
| YSI | 6:02f5e2861a9b | 2 | * |
| YSI | 6:02f5e2861a9b | 3 | * @purpose library for oem ELCD |
| YSI | 6:02f5e2861a9b | 4 | * |
| YSI | 6:02f5e2861a9b | 5 | * Utilisée pour écrire sur l'afficheur oem ELCD 4x20. |
| YSI | 6:02f5e2861a9b | 6 | * |
| YSI | 6:02f5e2861a9b | 7 | * http://www.lextronic.fr/P764-afficheur-4-x-20-caracteres-retro-eclaire-vert.html |
| YSI | 6:02f5e2861a9b | 8 | * |
| YSI | 6:02f5e2861a9b | 9 | * Copyright (c) 2014, cstyles (http://mbed.org) |
| YSI | 6:02f5e2861a9b | 10 | * |
| YSI | 6:02f5e2861a9b | 11 | * Exemple: |
| YSI | 6:02f5e2861a9b | 12 | * @code |
| YSI | 6:02f5e2861a9b | 13 | * #include "mbed.h" |
| YSI | 6:02f5e2861a9b | 14 | * #include "lib_LCD_oem_ELCD.h" |
| YSI | 6:02f5e2861a9b | 15 | * |
| YSI | 6:02f5e2861a9b | 16 | * LCD_OEM LCD; |
| YSI | 6:02f5e2861a9b | 17 | * //LCD_OEM LCD(p13); //Tx |
| YSI | 6:02f5e2861a9b | 18 | * |
| YSI | 6:02f5e2861a9b | 19 | * int main() |
| YSI | 6:02f5e2861a9b | 20 | * { |
| YSI | 6:02f5e2861a9b | 21 | * while(1) |
| YSI | 6:02f5e2861a9b | 22 | * { |
| YSI | 6:02f5e2861a9b | 23 | * for(int i = 0; i < 9999; i++) |
| YSI | 6:02f5e2861a9b | 24 | * { |
| YSI | 6:02f5e2861a9b | 25 | * LCD.clear(); |
| YSI | 6:02f5e2861a9b | 26 | * LCD.print(i); |
| YSI | 6:02f5e2861a9b | 27 | * wait(0.25); |
| YSI | 6:02f5e2861a9b | 28 | * } |
| YSI | 6:02f5e2861a9b | 29 | * } |
| YSI | 6:02f5e2861a9b | 30 | * } |
| YSI | 6:02f5e2861a9b | 31 | * @endcode |
| YSI | 6:02f5e2861a9b | 32 | * @file lib_LCD_oem_ELDC.cpp |
| YSI | 6:02f5e2861a9b | 33 | * @date Jan 2014 |
| YSI | 6:02f5e2861a9b | 34 | * @author Yannic Simon |
| YSI | 6:02f5e2861a9b | 35 | */ |
| YSI | 6:02f5e2861a9b | 36 | |
| YSI | 0:1323ab32b8ca | 37 | #include "lib_LCD_oem_ELCD.h" |
| YSI | 0:1323ab32b8ca | 38 | |
| YSI | 0:1323ab32b8ca | 39 | #define lcd_soft_boot 0xA0 |
| YSI | 0:1323ab32b8ca | 40 | #define lcd_cursor_pos 0xA1 |
| YSI | 0:1323ab32b8ca | 41 | #define lcd_display 0xA2 |
| YSI | 0:1323ab32b8ca | 42 | #define lcd_cursor 0xA3 |
| YSI | 0:1323ab32b8ca | 43 | #define lcd_redef_print 0xA4 |
| YSI | 0:1323ab32b8ca | 44 | #define lcd_redef 0xA5 |
| YSI | 0:1323ab32b8ca | 45 | |
| YSI | 0:1323ab32b8ca | 46 | |
| YSI | 0:1323ab32b8ca | 47 | LCD_OEM::LCD_OEM(PinName pin_tx) : Serial(pin_tx, NC) |
| YSI | 0:1323ab32b8ca | 48 | { |
| YSI | 0:1323ab32b8ca | 49 | init(); |
| YSI | 0:1323ab32b8ca | 50 | clear(); |
| YSI | 0:1323ab32b8ca | 51 | } |
| YSI | 0:1323ab32b8ca | 52 | |
| YSI | 0:1323ab32b8ca | 53 | void LCD_OEM::init(void) |
| YSI | 0:1323ab32b8ca | 54 | { |
| YSI | 0:1323ab32b8ca | 55 | LCD_OEM::baud(19200); |
| YSI | 0:1323ab32b8ca | 56 | LCD_OEM::putc(lcd_soft_boot); |
| YSI | 0:1323ab32b8ca | 57 | wait_ms(50); |
| YSI | 0:1323ab32b8ca | 58 | } |
| YSI | 0:1323ab32b8ca | 59 | |
| YSI | 0:1323ab32b8ca | 60 | void LCD_OEM::clear(void) |
| YSI | 0:1323ab32b8ca | 61 | { |
| YSI | 0:1323ab32b8ca | 62 | LCD_OEM::printf("%c%c", lcd_cursor, 0x01); |
| YSI | 0:1323ab32b8ca | 63 | X_position_cursor = 0; |
| YSI | 0:1323ab32b8ca | 64 | Y_position_cursor = 0; |
| YSI | 0:1323ab32b8ca | 65 | wait_ms(2); |
| YSI | 0:1323ab32b8ca | 66 | } |
| YSI | 0:1323ab32b8ca | 67 | |
| YSI | 0:1323ab32b8ca | 68 | void LCD_OEM::turn_off_cursor(void) |
| YSI | 0:1323ab32b8ca | 69 | { |
| YSI | 0:1323ab32b8ca | 70 | LCD_OEM::printf("%c%c", lcd_cursor, 0x0C); |
| YSI | 0:1323ab32b8ca | 71 | } |
| YSI | 0:1323ab32b8ca | 72 | |
| YSI | 0:1323ab32b8ca | 73 | void LCD_OEM::turn_on_cursor(void) |
| YSI | 0:1323ab32b8ca | 74 | { |
| YSI | 0:1323ab32b8ca | 75 | LCD_OEM::printf("%c%c", lcd_cursor, 0x0E); |
| YSI | 0:1323ab32b8ca | 76 | } |
| YSI | 0:1323ab32b8ca | 77 | |
| YSI | 0:1323ab32b8ca | 78 | void LCD_OEM::shift_line_cursor(void) |
| YSI | 0:1323ab32b8ca | 79 | { |
| YSI | 4:18ab8489365f | 80 | if(Y_position_cursor < 3) Y_position_cursor++; |
| YSI | 4:18ab8489365f | 81 | LCD_OEM::printf("%c%c%c", lcd_cursor_pos, 0, Y_position_cursor); |
| YSI | 0:1323ab32b8ca | 82 | } |
| YSI | 0:1323ab32b8ca | 83 | |
| YSI | 0:1323ab32b8ca | 84 | void LCD_OEM::set_position_cursor(int X) |
| YSI | 0:1323ab32b8ca | 85 | { |
| YSI | 4:18ab8489365f | 86 | if(X < 0) X = 0; |
| YSI | 4:18ab8489365f | 87 | else if(X > 19) X = 19; |
| YSI | 0:1323ab32b8ca | 88 | X_position_cursor = X; |
| YSI | 0:1323ab32b8ca | 89 | LCD_OEM::printf("%c%c%c", lcd_cursor_pos, X_position_cursor, Y_position_cursor); |
| YSI | 0:1323ab32b8ca | 90 | } |
| YSI | 0:1323ab32b8ca | 91 | |
| YSI | 0:1323ab32b8ca | 92 | void LCD_OEM::set_position_cursor(int X, int Y) |
| YSI | 0:1323ab32b8ca | 93 | { |
| YSI | 4:18ab8489365f | 94 | if(X < 0) X = 0; |
| YSI | 4:18ab8489365f | 95 | else if(X > 19) X = 19; |
| YSI | 4:18ab8489365f | 96 | if(Y < 0) Y = 0; |
| YSI | 4:18ab8489365f | 97 | else if(Y > 3) Y = 3; |
| YSI | 0:1323ab32b8ca | 98 | X_position_cursor = X; |
| YSI | 0:1323ab32b8ca | 99 | Y_position_cursor = Y; |
| YSI | 0:1323ab32b8ca | 100 | LCD_OEM::printf("%c%c%c", lcd_cursor_pos, X_position_cursor, Y_position_cursor); |
| YSI | 0:1323ab32b8ca | 101 | } |
| YSI | 0:1323ab32b8ca | 102 | |
| YSI | 0:1323ab32b8ca | 103 | void LCD_OEM::X_move_position(int n) |
| YSI | 0:1323ab32b8ca | 104 | { |
| YSI | 0:1323ab32b8ca | 105 | X_position_cursor += n; |
| YSI | 0:1323ab32b8ca | 106 | while(X_position_cursor > 19) |
| YSI | 0:1323ab32b8ca | 107 | { |
| YSI | 0:1323ab32b8ca | 108 | X_position_cursor -= 20; |
| YSI | 0:1323ab32b8ca | 109 | Y_position_cursor += 2; |
| YSI | 0:1323ab32b8ca | 110 | if(Y_position_cursor > 4) Y_position_cursor -= Y_position_cursor; |
| YSI | 0:1323ab32b8ca | 111 | else if(Y_position_cursor == 4) Y_position_cursor = 1; |
| YSI | 0:1323ab32b8ca | 112 | } |
| YSI | 0:1323ab32b8ca | 113 | } |
| YSI | 0:1323ab32b8ca | 114 | |
| YSI | 0:1323ab32b8ca | 115 | int LCD_OEM::get_X_position_cursor(void) |
| YSI | 0:1323ab32b8ca | 116 | { |
| YSI | 0:1323ab32b8ca | 117 | return X_position_cursor; |
| YSI | 0:1323ab32b8ca | 118 | } |
| YSI | 0:1323ab32b8ca | 119 | |
| YSI | 0:1323ab32b8ca | 120 | int LCD_OEM::get_Y_position_cursor(void) |
| YSI | 0:1323ab32b8ca | 121 | { |
| YSI | 0:1323ab32b8ca | 122 | return Y_position_cursor; |
| YSI | 0:1323ab32b8ca | 123 | } |
| YSI | 0:1323ab32b8ca | 124 | |
| YSI | 0:1323ab32b8ca | 125 | void LCD_OEM::define_and_print_caractere(char c, char l1, char l2, char l3, char l4, char l5, char l6, char l7, char l8) |
| YSI | 0:1323ab32b8ca | 126 | { |
| YSI | 0:1323ab32b8ca | 127 | print((char)c); |
| YSI | 0:1323ab32b8ca | 128 | define_caractere(c, l1, l2, l3, l4, l5, l6, l7, l8); |
| YSI | 0:1323ab32b8ca | 129 | } |
| YSI | 0:1323ab32b8ca | 130 | |
| YSI | 0:1323ab32b8ca | 131 | void LCD_OEM::define_caractere(char c, char l1, char l2, char l3, char l4, char l5, char l6, char l7, char l8) |
| YSI | 0:1323ab32b8ca | 132 | { |
| YSI | 0:1323ab32b8ca | 133 | char data[]={lcd_redef,c,l1,l2,l3,l4,l5,l6,l7,l8}; |
| YSI | 0:1323ab32b8ca | 134 | if(c > 7 && c < 16) |
| YSI | 0:1323ab32b8ca | 135 | { |
| YSI | 0:1323ab32b8ca | 136 | for(int i=0;i<10;i++) |
| YSI | 0:1323ab32b8ca | 137 | { |
| YSI | 0:1323ab32b8ca | 138 | LCD_OEM::putc(data[i]); |
| YSI | 0:1323ab32b8ca | 139 | wait_ms(1); |
| YSI | 0:1323ab32b8ca | 140 | } |
| YSI | 0:1323ab32b8ca | 141 | } |
| YSI | 0:1323ab32b8ca | 142 | set_position_cursor(X_position_cursor, Y_position_cursor); |
| YSI | 0:1323ab32b8ca | 143 | } |
| YSI | 0:1323ab32b8ca | 144 | |
| YSI | 6:02f5e2861a9b | 145 | int LCD_OEM::print(char c) |
| YSI | 6:02f5e2861a9b | 146 | { |
| YSI | 6:02f5e2861a9b | 147 | int n = LCD_OEM::printf("%c%c%c", lcd_display, c, 0) - 2; |
| YSI | 6:02f5e2861a9b | 148 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 149 | return n; |
| YSI | 6:02f5e2861a9b | 150 | } |
| YSI | 6:02f5e2861a9b | 151 | |
| YSI | 6:02f5e2861a9b | 152 | int LCD_OEM::print(short nb) |
| YSI | 6:02f5e2861a9b | 153 | { |
| YSI | 6:02f5e2861a9b | 154 | int n = LCD_OEM::printf("%c%d%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 155 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 156 | return n; |
| YSI | 6:02f5e2861a9b | 157 | } |
| YSI | 6:02f5e2861a9b | 158 | |
| YSI | 6:02f5e2861a9b | 159 | int LCD_OEM::print(unsigned short nb) |
| YSI | 6:02f5e2861a9b | 160 | { |
| YSI | 6:02f5e2861a9b | 161 | int n = LCD_OEM::printf("%c%u%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 162 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 163 | return n; |
| YSI | 6:02f5e2861a9b | 164 | } |
| YSI | 6:02f5e2861a9b | 165 | |
| YSI | 6:02f5e2861a9b | 166 | int LCD_OEM::print(int nb) |
| YSI | 6:02f5e2861a9b | 167 | { |
| YSI | 6:02f5e2861a9b | 168 | int n = LCD_OEM::printf("%c%d%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 169 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 170 | return n; |
| YSI | 6:02f5e2861a9b | 171 | } |
| YSI | 6:02f5e2861a9b | 172 | |
| YSI | 6:02f5e2861a9b | 173 | int LCD_OEM::print(unsigned int nb) |
| YSI | 6:02f5e2861a9b | 174 | { |
| YSI | 6:02f5e2861a9b | 175 | int n = LCD_OEM::printf("%c%u%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 176 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 177 | return n; |
| YSI | 6:02f5e2861a9b | 178 | } |
| YSI | 6:02f5e2861a9b | 179 | |
| YSI | 6:02f5e2861a9b | 180 | int LCD_OEM::print(long long nb) |
| YSI | 6:02f5e2861a9b | 181 | { |
| YSI | 6:02f5e2861a9b | 182 | int n = LCD_OEM::printf("%c%lld%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 183 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 184 | return n; |
| YSI | 6:02f5e2861a9b | 185 | } |
| YSI | 6:02f5e2861a9b | 186 | |
| YSI | 6:02f5e2861a9b | 187 | int LCD_OEM::print(unsigned long long nb) |
| YSI | 6:02f5e2861a9b | 188 | { |
| YSI | 6:02f5e2861a9b | 189 | int n = LCD_OEM::printf("%c%llu%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 190 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 191 | return n; |
| YSI | 6:02f5e2861a9b | 192 | } |
| YSI | 6:02f5e2861a9b | 193 | |
| YSI | 6:02f5e2861a9b | 194 | int LCD_OEM::print(float nb) |
| YSI | 6:02f5e2861a9b | 195 | { |
| YSI | 6:02f5e2861a9b | 196 | int n = LCD_OEM::printf("%c%f%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 197 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 198 | return n; |
| YSI | 6:02f5e2861a9b | 199 | } |
| YSI | 6:02f5e2861a9b | 200 | |
| YSI | 6:02f5e2861a9b | 201 | int LCD_OEM::print(double nb) |
| YSI | 6:02f5e2861a9b | 202 | { |
| YSI | 6:02f5e2861a9b | 203 | int n = LCD_OEM::printf("%c%lf%c", lcd_display, nb, 0) - 2; |
| YSI | 6:02f5e2861a9b | 204 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 205 | return n; |
| YSI | 6:02f5e2861a9b | 206 | } |
| YSI | 6:02f5e2861a9b | 207 | |
| YSI | 6:02f5e2861a9b | 208 | int LCD_OEM::print(char *s) |
| YSI | 6:02f5e2861a9b | 209 | { |
| YSI | 6:02f5e2861a9b | 210 | int n = LCD_OEM::printf("%c%s%c", lcd_display, s, 0) - 2; |
| YSI | 6:02f5e2861a9b | 211 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 212 | return n; |
| YSI | 6:02f5e2861a9b | 213 | } |
| YSI | 6:02f5e2861a9b | 214 | |
| YSI | 6:02f5e2861a9b | 215 | int LCD_OEM::print(const char *format, ... ) |
| YSI | 6:02f5e2861a9b | 216 | { |
| YSI | 6:02f5e2861a9b | 217 | char buffer[256]={0x00}; |
| YSI | 6:02f5e2861a9b | 218 | va_list args; |
| YSI | 6:02f5e2861a9b | 219 | va_start(args, format); |
| YSI | 6:02f5e2861a9b | 220 | vsnprintf(buffer,256,format,args); |
| YSI | 6:02f5e2861a9b | 221 | va_end(args); |
| YSI | 6:02f5e2861a9b | 222 | int n = LCD_OEM::printf("%c%s%c", lcd_display, buffer, 0) - 2; |
| YSI | 6:02f5e2861a9b | 223 | X_move_position(n); |
| YSI | 6:02f5e2861a9b | 224 | return n; |
| YSI | 6:02f5e2861a9b | 225 | } |
| YSI | 6:02f5e2861a9b | 226 | |
| YSI | 4:18ab8489365f | 227 | void LCD_OEM::putnc(char *s, int n) |
| YSI | 4:18ab8489365f | 228 | { |
| YSI | 4:18ab8489365f | 229 | for(int i = 0; i < n; i++) |
| YSI | 4:18ab8489365f | 230 | { |
| YSI | 4:18ab8489365f | 231 | LCD_OEM::putc(s[i]); |
| YSI | 4:18ab8489365f | 232 | } |
| YSI | 4:18ab8489365f | 233 | X_move_position(n); |
| YSI | 4:18ab8489365f | 234 | } |
Y SI