Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
main.cpp
- Committer:
- wim
- Date:
- 2014-06-13
- Revision:
- 0:a75049de1a82
- Child:
- 1:ef419b21167d
File content as of revision 0:a75049de1a82:
// Hello World! for the TextLCD #include "mbed.h" #include "TextLCD.h" // Host PC Communication channels Serial pc(USBTX, USBRX); // tx, rx void show_menu() { pc.printf("0: Exit\n\r"); pc.printf("1: Show Menu\n\r"); pc.printf("2: Goto 0,0\n\r"); pc.printf("3: Goto columns(),rows()\n\r"); pc.printf("4: cls()\n\r"); pc.printf("5: UDCs \n\r"); pc.printf("6: Fill\n\r"); pc.printf("7: Cursor On\n\r"); pc.printf("8: Cursor Off\n\r"); pc.printf("9: Text\n\r"); pc.printf("A: Display On\n\r"); pc.printf("B: Display Off\n\r"); pc.printf("C: Backlight On\n\r"); pc.printf("D: Backlight Off\n\r"); pc.printf("P: \n\r"); pc.printf("\n\r"); } // I2C Communication I2C i2c_lcd(p28,p27); // SDA, SCL //I2C i2c_lcd(p9,p10); // SDA, SCL // SPI Communication SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK //DigitalOut cs(p8); //DigitalOut cs2(p9); //TextLCD lcd2(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x4); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x4); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x2); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD40x2); // rs, e, d4-d7 =ok //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok //TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok //Test Adafruit module //TextLCD_I2C lcd(&i2c_lcd, MCP23008_SA0, TextLCD::LCD20x4); // I2C bus, MCP23008 Slaveaddress, LCD Type =OK //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, LCD Ctrl //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD24x4); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x2); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4, TextLCD::HD44780); // SPI bus, CS pin, LCD Type, LCD Ctrl =ok //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4, TextLCD::WS0010); // SPI bus, CS pin, LCD Type, LCD Ctrl //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD8x2B); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD16x1); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD16x2); // SPI bus, CS pin, LCD Type (VFD) =ok 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 int main() { // int i=0; int count=0; bool running=true; char command; pc.printf("LCD Test. Colums=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); //while (1) { for (int row=0; row<lcd.rows(); row++) { int col=0; pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); // lcd.putc('-'); lcd.putc('0' + row); for (col=1; col<lcd.columns()-1; col++) { lcd.putc('*'); } pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); lcd.putc('+'); } // wait_ms(500); // lcd.cls(); // Test timing //} lcd.setCursor(TextLCD::CurOff_BlkOn); // lcd.setUDC(0, (char *) udc_AA); // lcd.putc(0); // lcd.setUDC(1, (char *) udc_0E); // lcd.putc(1); // lcd.setUDC(0, (char *) udc_0); // lcd.putc(0); // lcd.setUDC(1, (char *) udc_1); // lcd.putc(1); // lcd.setUDC(2, (char *) udc_2); // lcd.putc(2); lcd.setUDC(0, (char *) udc_Bat_Hi); lcd.setUDC(1, (char *) udc_Bat_Ha); lcd.setUDC(2, (char *) udc_Bat_Lo); lcd.setUDC(3, (char *) udc_AC); lcd.setUDC(4, (char *) udc_4); lcd.setUDC(5, (char *) udc_5); lcd.setUDC(6, (char *) udc_6); lcd.setUDC(7, (char *) udc_7); lcd.putc(0); lcd.putc(1); lcd.putc(2); lcd.putc(3); lcd.putc(4); lcd.putc(5); lcd.putc(6); lcd.putc(7); #if(0) lcd2.setUDC(0, (char *) udc_Bat_Hi); lcd2.setUDC(1, (char *) udc_Bat_Ha); lcd2.setUDC(2, (char *) udc_Bat_Lo); lcd2.setUDC(3, (char *) udc_AC); lcd2.putc(0); lcd2.putc(1); lcd2.putc(2); lcd2.putc(3); #endif #if(0) while (1) { lcd.locate(4, 2); lcd.printf("Count=%3d", i); i++; if (i==100) i=0; wait(1); } #endif pc.printf("Hello World!\n\r"); show_menu(); while(running) { count++; if(pc.readable()) { command = pc.getc(); pc.printf("command= %c \n\r", command); switch (command) { case '0' : pc.printf("Done\n\r"); running = false; break; case '1' : show_menu(); break; case '2' : pc.printf("Goto 0,0\n\r"); lcd.locate(0, 0); // lcd2.locate(0, 0); break; case '3' : pc.printf("Goto Col,Row\n\r"); lcd.locate( (lcd.columns() - 1), (lcd.rows() - 1)); // lcd2.locate( (lcd.columns() - 1), (lcd.rows() - 1)); break; case '4' : pc.printf("cls()\n\r"); lcd.cls(); // lcd2.cls(); break; case '5' : pc.printf("UDCs\n\r"); lcd.locate(2, 0); lcd.putc(0); lcd.putc(1); lcd.putc(2); lcd.putc(3); lcd.putc(4); lcd.putc(5); lcd.putc(6); lcd.putc(7); lcd.locate(4, lcd.rows()-1); lcd.putc(0); lcd.putc(1); lcd.putc(2); lcd.putc(3); // lcd2.locate(4, lcd.rows()-1); // lcd2.putc(0); // lcd2.putc(1); // lcd2.putc(2); // lcd2.putc(3); break; case '6' : pc.printf("Fill\n\r"); lcd.locate(0, 0); for (int row=0; row<lcd.rows(); row++) { int col=0; // pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); // lcd.putc('-'); lcd.putc('0' + row); for (col=1; col<lcd.columns()-1; col++) { lcd.putc('*'); } // pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); lcd.putc('+'); } break; case '7' : pc.printf("Cursor 0n\n\r"); lcd.setCursor(TextLCD::CurOff_BlkOn); // lcd2.setCursor(TextLCD::CurOff_BlkOn); break; case '8' : pc.printf("Cursor 0ff\n\r"); lcd.setCursor(TextLCD::CurOff_BlkOff); // lcd2.setCursor(TextLCD::CurOff_BlkOff); break; case '9' : pc.printf("Text\n\r"); lcd.printf("Hello mbed\n"); // lcd2.printf("Hello mbed\n"); break; case 'A' : pc.printf("Display On\n\r"); lcd.setMode(TextLCD::DispOn); // lcd2.setMode(TextLCD::DispOn); break; case 'B' : pc.printf("Display Off\n\r"); lcd.setMode(TextLCD::DispOff); // lcd2.setMode(TextLCD::DispOff); break; case 'C' : pc.printf("Backlight On\n\r"); lcd.setBacklight(TextLCD::LightOn); // lcd2.setBacklight(TextLCD::LightOn); break; case 'D' : pc.printf("Backlight Off\n\r"); lcd.setBacklight(TextLCD::LightOff); // lcd2.setBacklight(TextLCD::LightOff); break; // case 'E' : // pc.printf("Test nibble\n\r"); // for (int i=0; i<16; i++) { // lcd._writeNibble(i); // wait(1); // } // break; default : lcd.putc(command); // lcd2.putc(command); break; } //switch }//if }//while pc.printf("Bye World!\n\r"); }