Rodrigo Lino
/
Menu_IHM
Menu para a IHM
Fork of TextLCD_HelloWorld2 by
main.cpp
- Committer:
- wim
- Date:
- 2014-06-28
- Revision:
- 2:c2978a6fa79a
- Parent:
- 1:ef419b21167d
- Child:
- 3:f238b4f7874f
File content as of revision 2:c2978a6fa79a:
// 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: init \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::LCD24x2); // rs, e, d4-d7 =ok //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD24x4D, TextLCD::KS0078); // 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, 0x40, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type =ok //Test Adafruit module, change #define //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::LCD24x4D, TextLCD::KS0078); // 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 lcd2(&spi_lcd, p9, TextLCD::LCD8x2B); // SPI bus, CS pin, LCD Type =ok //TextLCD_SPI lcd2(&spi_lcd, p9, TextLCD::LCD16x1C); // 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 =ok //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032 //Test PCF2113 //TextLCD_I2C_N lcd(&i2c_lcd, PCF21XX_SA0, TextLCD::LCD12x2, NC, TextLCD::PCF2113_3V3); // I2C bus, slaveaddress, LCDType=LCD12x2, BL=NC, LCDTCtrl=PCF2113 //PCF2116 //TextLCD_I2C_N lcd(&i2c_lcd, PCF21XX_SA0, TextLCD::LCD12x3D1, NC, TextLCD::PCF2116_3V3); // I2C bus, slaveaddress, LCDType=LCD12x3D1, BL=NC, LCDTCtrl=PCF2116 //TextLCD_I2C_N lcd(&i2c_lcd, PCF21XX_SA0, TextLCD::LCD12x4D, NC, TextLCD::PCF2116_3V3); // I2C bus, slaveaddress, LCDType=LCD12x4D, BL=NC, LCDTCtrl=PCF2116 //TextLCD_I2C_N lcd(&i2c_lcd, PCF21XX_SA0, TextLCD::LCD24x1, NC, TextLCD::PCF2116_3V3); // I2C bus, slaveaddress, LCDType=LCD24x1, BL=NC, LCDTCtrl=PCF2116 //TextLCD_I2C_N lcd(&i2c_lcd, PCF21XX_SA0, TextLCD::LCD24x2, NC, TextLCD::PCF21116_3V3); // I2C bus, slaveaddress, LCDType=LCD24x2, BL=NC, LCDTCtrl=PCF2116 //AIP31068 TextLCD_I2C_N lcd(&i2c_lcd, AIP31068_SA, TextLCD::LCD16x2, NC, TextLCD::AIP31068); // I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=AIP31068 //TextLCD_SPI_N_3_9 lcd(&spi_lcd, p8, TextLCD::LCD16x2, NC, TextLCD::AIP31068); // I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=AIP31068 //TextLCD_SPI_N_3_10 lcd(&spi_lcd, p8, TextLCD::LCD16x2, NC, TextLCD::WS0010); // I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=WS0010 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); #if(0) 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); #endif #if(1) 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); #endif #if(0) lcd.setUDC(0, (char *) udc_ch_1); lcd.setUDC(1, (char *) udc_ch_2); lcd.setUDC(2, (char *) udc_ch_3); lcd.setUDC(3, (char *) udc_ch_4); lcd.setUDC(4, (char *) udc_ch_yr); lcd.setUDC(5, (char *) udc_ch_mo); lcd.setUDC(6, (char *) udc_ch_dy); lcd.setUDC(7, (char *) udc_ch_mi); #endif 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.locate(0, 0); lcd.printf(" Hello mbed\n"); lcd.printf(" Native I2C\n"); // lcd2.printf("Hello mbed\n"); #if(0) // Needed for PCF2116C and PCF2116K lcd.putc('H' ^ 0x80); lcd.putc('e' ^ 0x80); lcd.putc('l' ^ 0x80); lcd.putc('l' ^ 0x80); lcd.putc('o' ^ 0x80); lcd.putc(' ' ^ 0x80); lcd.putc('m' ^ 0x80); lcd.putc('b' ^ 0x80); lcd.putc('e' ^ 0x80); lcd.putc('d' ^ 0x80); lcd.putc('\n'); lcd.putc('I' ^ 0x80); lcd.putc('2' ^ 0x80); lcd.putc('C' ^ 0x80); lcd.putc(' ' ^ 0x80); lcd.putc('P' ^ 0x80); lcd.putc('C' ^ 0x80); lcd.putc('F' ^ 0x80); lcd.putc('2' ^ 0x80); lcd.putc('1' ^ 0x80); lcd.putc('1' ^ 0x80); lcd.putc('6' ^ 0x80); #endif 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; case 'P' : pc.printf("Init Ctrl test\n\r"); //test // lcd._initCtrl(); break; default : lcd.putc(command); // lcd.putc(command ^ 0x80); // Needed for PCF2116C and PCF2116K // lcd2.putc(command); break; } //switch }//if }//while pc.printf("Bye World!\n\r"); }