Menu para a IHM

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
wim
Date:
Fri Jun 13 19:02:38 2014 +0000
Revision:
0:a75049de1a82
Child:
1:ef419b21167d
First test of native SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:a75049de1a82 1 // Hello World! for the TextLCD
wim 0:a75049de1a82 2
wim 0:a75049de1a82 3 #include "mbed.h"
wim 0:a75049de1a82 4 #include "TextLCD.h"
wim 0:a75049de1a82 5
wim 0:a75049de1a82 6 // Host PC Communication channels
wim 0:a75049de1a82 7 Serial pc(USBTX, USBRX); // tx, rx
wim 0:a75049de1a82 8
wim 0:a75049de1a82 9 void show_menu() {
wim 0:a75049de1a82 10 pc.printf("0: Exit\n\r");
wim 0:a75049de1a82 11 pc.printf("1: Show Menu\n\r");
wim 0:a75049de1a82 12 pc.printf("2: Goto 0,0\n\r");
wim 0:a75049de1a82 13 pc.printf("3: Goto columns(),rows()\n\r");
wim 0:a75049de1a82 14 pc.printf("4: cls()\n\r");
wim 0:a75049de1a82 15 pc.printf("5: UDCs \n\r");
wim 0:a75049de1a82 16 pc.printf("6: Fill\n\r");
wim 0:a75049de1a82 17 pc.printf("7: Cursor On\n\r");
wim 0:a75049de1a82 18 pc.printf("8: Cursor Off\n\r");
wim 0:a75049de1a82 19 pc.printf("9: Text\n\r");
wim 0:a75049de1a82 20 pc.printf("A: Display On\n\r");
wim 0:a75049de1a82 21 pc.printf("B: Display Off\n\r");
wim 0:a75049de1a82 22 pc.printf("C: Backlight On\n\r");
wim 0:a75049de1a82 23 pc.printf("D: Backlight Off\n\r");
wim 0:a75049de1a82 24 pc.printf("P: \n\r");
wim 0:a75049de1a82 25 pc.printf("\n\r");
wim 0:a75049de1a82 26 }
wim 0:a75049de1a82 27
wim 0:a75049de1a82 28
wim 0:a75049de1a82 29 // I2C Communication
wim 0:a75049de1a82 30 I2C i2c_lcd(p28,p27); // SDA, SCL
wim 0:a75049de1a82 31 //I2C i2c_lcd(p9,p10); // SDA, SCL
wim 0:a75049de1a82 32
wim 0:a75049de1a82 33 // SPI Communication
wim 0:a75049de1a82 34 SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 0:a75049de1a82 35 //DigitalOut cs(p8);
wim 0:a75049de1a82 36 //DigitalOut cs2(p9);
wim 0:a75049de1a82 37
wim 0:a75049de1a82 38 //TextLCD lcd2(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x4); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 39 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 40 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 41 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x4); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 42 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x2); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 43 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD40x2); // rs, e, d4-d7 =ok
wim 0:a75049de1a82 44
wim 0:a75049de1a82 45 //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok
wim 0:a75049de1a82 46 //TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok
wim 0:a75049de1a82 47
wim 0:a75049de1a82 48 //Test Adafruit module
wim 0:a75049de1a82 49 //TextLCD_I2C lcd(&i2c_lcd, MCP23008_SA0, TextLCD::LCD20x4); // I2C bus, MCP23008 Slaveaddress, LCD Type =OK
wim 0:a75049de1a82 50
wim 0:a75049de1a82 51 //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, LCD Ctrl
wim 0:a75049de1a82 52
wim 0:a75049de1a82 53 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD24x4); // SPI bus, CS pin, LCD Type =ok
wim 0:a75049de1a82 54 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x2); // SPI bus, CS pin, LCD Type =ok
wim 0:a75049de1a82 55 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type =ok
wim 0:a75049de1a82 56
wim 0:a75049de1a82 57 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4, TextLCD::HD44780); // SPI bus, CS pin, LCD Type, LCD Ctrl =ok
wim 0:a75049de1a82 58 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4, TextLCD::WS0010); // SPI bus, CS pin, LCD Type, LCD Ctrl
wim 0:a75049de1a82 59
wim 0:a75049de1a82 60 //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD8x2B); // SPI bus, CS pin, LCD Type =ok
wim 0:a75049de1a82 61 //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD16x1); // SPI bus, CS pin, LCD Type =ok
wim 0:a75049de1a82 62 //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD16x2); // SPI bus, CS pin, LCD Type (VFD) =ok
wim 0:a75049de1a82 63
wim 0:a75049de1a82 64
wim 0:a75049de1a82 65 TextLCD_SPI_N lcd(&spi_lcd, p8, p9, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032
wim 0:a75049de1a82 66
wim 0:a75049de1a82 67 int main() {
wim 0:a75049de1a82 68 // int i=0;
wim 0:a75049de1a82 69 int count=0;
wim 0:a75049de1a82 70 bool running=true;
wim 0:a75049de1a82 71 char command;
wim 0:a75049de1a82 72
wim 0:a75049de1a82 73 pc.printf("LCD Test. Colums=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
wim 0:a75049de1a82 74
wim 0:a75049de1a82 75 //while (1) {
wim 0:a75049de1a82 76 for (int row=0; row<lcd.rows(); row++) {
wim 0:a75049de1a82 77 int col=0;
wim 0:a75049de1a82 78
wim 0:a75049de1a82 79 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 0:a75049de1a82 80 // lcd.putc('-');
wim 0:a75049de1a82 81 lcd.putc('0' + row);
wim 0:a75049de1a82 82
wim 0:a75049de1a82 83 for (col=1; col<lcd.columns()-1; col++) {
wim 0:a75049de1a82 84 lcd.putc('*');
wim 0:a75049de1a82 85 }
wim 0:a75049de1a82 86
wim 0:a75049de1a82 87 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 0:a75049de1a82 88 lcd.putc('+');
wim 0:a75049de1a82 89
wim 0:a75049de1a82 90 }
wim 0:a75049de1a82 91
wim 0:a75049de1a82 92 // wait_ms(500);
wim 0:a75049de1a82 93 // lcd.cls(); // Test timing
wim 0:a75049de1a82 94 //}
wim 0:a75049de1a82 95
wim 0:a75049de1a82 96
wim 0:a75049de1a82 97 lcd.setCursor(TextLCD::CurOff_BlkOn);
wim 0:a75049de1a82 98
wim 0:a75049de1a82 99 // lcd.setUDC(0, (char *) udc_AA);
wim 0:a75049de1a82 100 // lcd.putc(0);
wim 0:a75049de1a82 101
wim 0:a75049de1a82 102 // lcd.setUDC(1, (char *) udc_0E);
wim 0:a75049de1a82 103 // lcd.putc(1);
wim 0:a75049de1a82 104
wim 0:a75049de1a82 105 // lcd.setUDC(0, (char *) udc_0);
wim 0:a75049de1a82 106 // lcd.putc(0);
wim 0:a75049de1a82 107 // lcd.setUDC(1, (char *) udc_1);
wim 0:a75049de1a82 108 // lcd.putc(1);
wim 0:a75049de1a82 109 // lcd.setUDC(2, (char *) udc_2);
wim 0:a75049de1a82 110 // lcd.putc(2);
wim 0:a75049de1a82 111
wim 0:a75049de1a82 112 lcd.setUDC(0, (char *) udc_Bat_Hi);
wim 0:a75049de1a82 113 lcd.setUDC(1, (char *) udc_Bat_Ha);
wim 0:a75049de1a82 114 lcd.setUDC(2, (char *) udc_Bat_Lo);
wim 0:a75049de1a82 115 lcd.setUDC(3, (char *) udc_AC);
wim 0:a75049de1a82 116 lcd.setUDC(4, (char *) udc_4);
wim 0:a75049de1a82 117 lcd.setUDC(5, (char *) udc_5);
wim 0:a75049de1a82 118 lcd.setUDC(6, (char *) udc_6);
wim 0:a75049de1a82 119 lcd.setUDC(7, (char *) udc_7);
wim 0:a75049de1a82 120
wim 0:a75049de1a82 121 lcd.putc(0);
wim 0:a75049de1a82 122 lcd.putc(1);
wim 0:a75049de1a82 123 lcd.putc(2);
wim 0:a75049de1a82 124 lcd.putc(3);
wim 0:a75049de1a82 125 lcd.putc(4);
wim 0:a75049de1a82 126 lcd.putc(5);
wim 0:a75049de1a82 127 lcd.putc(6);
wim 0:a75049de1a82 128 lcd.putc(7);
wim 0:a75049de1a82 129
wim 0:a75049de1a82 130 #if(0)
wim 0:a75049de1a82 131 lcd2.setUDC(0, (char *) udc_Bat_Hi);
wim 0:a75049de1a82 132 lcd2.setUDC(1, (char *) udc_Bat_Ha);
wim 0:a75049de1a82 133 lcd2.setUDC(2, (char *) udc_Bat_Lo);
wim 0:a75049de1a82 134 lcd2.setUDC(3, (char *) udc_AC);
wim 0:a75049de1a82 135 lcd2.putc(0);
wim 0:a75049de1a82 136 lcd2.putc(1);
wim 0:a75049de1a82 137 lcd2.putc(2);
wim 0:a75049de1a82 138 lcd2.putc(3);
wim 0:a75049de1a82 139 #endif
wim 0:a75049de1a82 140
wim 0:a75049de1a82 141 #if(0)
wim 0:a75049de1a82 142 while (1) {
wim 0:a75049de1a82 143 lcd.locate(4, 2);
wim 0:a75049de1a82 144 lcd.printf("Count=%3d", i);
wim 0:a75049de1a82 145 i++;
wim 0:a75049de1a82 146 if (i==100) i=0;
wim 0:a75049de1a82 147
wim 0:a75049de1a82 148 wait(1);
wim 0:a75049de1a82 149 }
wim 0:a75049de1a82 150 #endif
wim 0:a75049de1a82 151
wim 0:a75049de1a82 152 pc.printf("Hello World!\n\r");
wim 0:a75049de1a82 153 show_menu();
wim 0:a75049de1a82 154
wim 0:a75049de1a82 155 while(running) {
wim 0:a75049de1a82 156
wim 0:a75049de1a82 157 count++;
wim 0:a75049de1a82 158
wim 0:a75049de1a82 159 if(pc.readable()) {
wim 0:a75049de1a82 160 command = pc.getc();
wim 0:a75049de1a82 161 pc.printf("command= %c \n\r", command);
wim 0:a75049de1a82 162
wim 0:a75049de1a82 163 switch (command) {
wim 0:a75049de1a82 164 case '0' :
wim 0:a75049de1a82 165 pc.printf("Done\n\r");
wim 0:a75049de1a82 166 running = false;
wim 0:a75049de1a82 167 break;
wim 0:a75049de1a82 168
wim 0:a75049de1a82 169 case '1' :
wim 0:a75049de1a82 170 show_menu();
wim 0:a75049de1a82 171 break;
wim 0:a75049de1a82 172
wim 0:a75049de1a82 173 case '2' :
wim 0:a75049de1a82 174 pc.printf("Goto 0,0\n\r");
wim 0:a75049de1a82 175 lcd.locate(0, 0);
wim 0:a75049de1a82 176 // lcd2.locate(0, 0);
wim 0:a75049de1a82 177 break;
wim 0:a75049de1a82 178
wim 0:a75049de1a82 179 case '3' :
wim 0:a75049de1a82 180 pc.printf("Goto Col,Row\n\r");
wim 0:a75049de1a82 181 lcd.locate( (lcd.columns() - 1), (lcd.rows() - 1));
wim 0:a75049de1a82 182 // lcd2.locate( (lcd.columns() - 1), (lcd.rows() - 1));
wim 0:a75049de1a82 183 break;
wim 0:a75049de1a82 184
wim 0:a75049de1a82 185 case '4' :
wim 0:a75049de1a82 186 pc.printf("cls()\n\r");
wim 0:a75049de1a82 187 lcd.cls();
wim 0:a75049de1a82 188 // lcd2.cls();
wim 0:a75049de1a82 189 break;
wim 0:a75049de1a82 190
wim 0:a75049de1a82 191 case '5' :
wim 0:a75049de1a82 192 pc.printf("UDCs\n\r");
wim 0:a75049de1a82 193 lcd.locate(2, 0);
wim 0:a75049de1a82 194 lcd.putc(0);
wim 0:a75049de1a82 195 lcd.putc(1);
wim 0:a75049de1a82 196 lcd.putc(2);
wim 0:a75049de1a82 197 lcd.putc(3);
wim 0:a75049de1a82 198 lcd.putc(4);
wim 0:a75049de1a82 199 lcd.putc(5);
wim 0:a75049de1a82 200 lcd.putc(6);
wim 0:a75049de1a82 201 lcd.putc(7);
wim 0:a75049de1a82 202
wim 0:a75049de1a82 203 lcd.locate(4, lcd.rows()-1);
wim 0:a75049de1a82 204 lcd.putc(0);
wim 0:a75049de1a82 205 lcd.putc(1);
wim 0:a75049de1a82 206 lcd.putc(2);
wim 0:a75049de1a82 207 lcd.putc(3);
wim 0:a75049de1a82 208
wim 0:a75049de1a82 209
wim 0:a75049de1a82 210 // lcd2.locate(4, lcd.rows()-1);
wim 0:a75049de1a82 211 // lcd2.putc(0);
wim 0:a75049de1a82 212 // lcd2.putc(1);
wim 0:a75049de1a82 213 // lcd2.putc(2);
wim 0:a75049de1a82 214 // lcd2.putc(3);
wim 0:a75049de1a82 215
wim 0:a75049de1a82 216 break;
wim 0:a75049de1a82 217 case '6' :
wim 0:a75049de1a82 218 pc.printf("Fill\n\r");
wim 0:a75049de1a82 219 lcd.locate(0, 0);
wim 0:a75049de1a82 220 for (int row=0; row<lcd.rows(); row++) {
wim 0:a75049de1a82 221 int col=0;
wim 0:a75049de1a82 222
wim 0:a75049de1a82 223 // pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 0:a75049de1a82 224 // lcd.putc('-');
wim 0:a75049de1a82 225 lcd.putc('0' + row);
wim 0:a75049de1a82 226
wim 0:a75049de1a82 227 for (col=1; col<lcd.columns()-1; col++) {
wim 0:a75049de1a82 228 lcd.putc('*');
wim 0:a75049de1a82 229 }
wim 0:a75049de1a82 230
wim 0:a75049de1a82 231 // pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 0:a75049de1a82 232 lcd.putc('+');
wim 0:a75049de1a82 233 }
wim 0:a75049de1a82 234
wim 0:a75049de1a82 235 break;
wim 0:a75049de1a82 236
wim 0:a75049de1a82 237 case '7' :
wim 0:a75049de1a82 238 pc.printf("Cursor 0n\n\r");
wim 0:a75049de1a82 239 lcd.setCursor(TextLCD::CurOff_BlkOn);
wim 0:a75049de1a82 240 // lcd2.setCursor(TextLCD::CurOff_BlkOn);
wim 0:a75049de1a82 241 break;
wim 0:a75049de1a82 242
wim 0:a75049de1a82 243 case '8' :
wim 0:a75049de1a82 244 pc.printf("Cursor 0ff\n\r");
wim 0:a75049de1a82 245 lcd.setCursor(TextLCD::CurOff_BlkOff);
wim 0:a75049de1a82 246 // lcd2.setCursor(TextLCD::CurOff_BlkOff);
wim 0:a75049de1a82 247 break;
wim 0:a75049de1a82 248
wim 0:a75049de1a82 249 case '9' :
wim 0:a75049de1a82 250 pc.printf("Text\n\r");
wim 0:a75049de1a82 251 lcd.printf("Hello mbed\n");
wim 0:a75049de1a82 252 // lcd2.printf("Hello mbed\n");
wim 0:a75049de1a82 253
wim 0:a75049de1a82 254 break;
wim 0:a75049de1a82 255
wim 0:a75049de1a82 256 case 'A' :
wim 0:a75049de1a82 257 pc.printf("Display On\n\r");
wim 0:a75049de1a82 258 lcd.setMode(TextLCD::DispOn);
wim 0:a75049de1a82 259 // lcd2.setMode(TextLCD::DispOn);
wim 0:a75049de1a82 260 break;
wim 0:a75049de1a82 261
wim 0:a75049de1a82 262 case 'B' :
wim 0:a75049de1a82 263 pc.printf("Display Off\n\r");
wim 0:a75049de1a82 264 lcd.setMode(TextLCD::DispOff);
wim 0:a75049de1a82 265 // lcd2.setMode(TextLCD::DispOff);
wim 0:a75049de1a82 266 break;
wim 0:a75049de1a82 267
wim 0:a75049de1a82 268 case 'C' :
wim 0:a75049de1a82 269 pc.printf("Backlight On\n\r");
wim 0:a75049de1a82 270 lcd.setBacklight(TextLCD::LightOn);
wim 0:a75049de1a82 271 // lcd2.setBacklight(TextLCD::LightOn);
wim 0:a75049de1a82 272 break;
wim 0:a75049de1a82 273
wim 0:a75049de1a82 274 case 'D' :
wim 0:a75049de1a82 275 pc.printf("Backlight Off\n\r");
wim 0:a75049de1a82 276 lcd.setBacklight(TextLCD::LightOff);
wim 0:a75049de1a82 277 // lcd2.setBacklight(TextLCD::LightOff);
wim 0:a75049de1a82 278 break;
wim 0:a75049de1a82 279
wim 0:a75049de1a82 280
wim 0:a75049de1a82 281 // case 'E' :
wim 0:a75049de1a82 282 // pc.printf("Test nibble\n\r");
wim 0:a75049de1a82 283 // for (int i=0; i<16; i++) {
wim 0:a75049de1a82 284 // lcd._writeNibble(i);
wim 0:a75049de1a82 285 // wait(1);
wim 0:a75049de1a82 286 // }
wim 0:a75049de1a82 287 // break;
wim 0:a75049de1a82 288
wim 0:a75049de1a82 289
wim 0:a75049de1a82 290
wim 0:a75049de1a82 291 default :
wim 0:a75049de1a82 292 lcd.putc(command);
wim 0:a75049de1a82 293 // lcd2.putc(command);
wim 0:a75049de1a82 294 break;
wim 0:a75049de1a82 295
wim 0:a75049de1a82 296 } //switch
wim 0:a75049de1a82 297 }//if
wim 0:a75049de1a82 298 }//while
wim 0:a75049de1a82 299
wim 0:a75049de1a82 300 pc.printf("Bye World!\n\r");
wim 0:a75049de1a82 301 }