Luis Silvio Cordova Rivadeneira
/
UPSM_TextLCD
Manejo de pantallas de texto con varias interfaces de comunicación
main.cpp@5:2e4e5085d597, 2020-02-12 (annotated)
- Committer:
- lscordovar
- Date:
- Wed Feb 12 21:20:37 2020 +0000
- Revision:
- 5:2e4e5085d597
- Parent:
- 4:a3e4bb2053cb
- Child:
- 6:8b78e3cddd78
Uso de funciones del LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 4:a3e4bb2053cb | 1 | /* Hello World! for the TextLCD Enhanced Library*/ |
wim | 0:a75049de1a82 | 2 | |
wim | 0:a75049de1a82 | 3 | #include "mbed.h" |
wim | 0:a75049de1a82 | 4 | #include "TextLCD.h" |
lscordovar | 5:2e4e5085d597 | 5 | |
wim | 0:a75049de1a82 | 6 | // Host PC Communication channels |
lscordovar | 5:2e4e5085d597 | 7 | Serial pc(PA_2,PA_3); // tx, rx |
lscordovar | 5:2e4e5085d597 | 8 | |
wim | 0:a75049de1a82 | 9 | // I2C Communication |
lscordovar | 5:2e4e5085d597 | 10 | I2C i2c_lcd(PB_9, PB_8); // SDA, SCL |
wim | 4:a3e4bb2053cb | 11 | //I2C i2c_lcd(p28,p27); // SDA, SCL |
lscordovar | 5:2e4e5085d597 | 12 | |
wim | 0:a75049de1a82 | 13 | // SPI Communication |
lscordovar | 5:2e4e5085d597 | 14 | //SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK |
wim | 0:a75049de1a82 | 15 | |
lscordovar | 5:2e4e5085d597 | 16 | // LCD instantiation |
wim | 4:a3e4bb2053cb | 17 | //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // 4bit bus: rs, e, d4-d7 |
lscordovar | 5:2e4e5085d597 | 18 | TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type |
wim | 4:a3e4bb2053cb | 19 | //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type, Ctrl Type |
wim | 4:a3e4bb2053cb | 20 | //TextLCD_I2C lcd(&spi_lcd, p8, TextLCD::LCD24x4D); // I2C exp: SPI bus, CS pin, LCD Type |
wim | 4:a3e4bb2053cb | 21 | //TextLCD_SPI_N lcd(&spi_lcd, p8, p9, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // SPI native: SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032 |
wim | 4:a3e4bb2053cb | 22 | //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032 =Ok |
wim | 4:a3e4bb2053cb | 23 | //TextLCD_I2C_N lcd(&i2c_lcd, SSD1803_SA1, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD20x4D, BL=NC, LCDTCtrl=SSD1803 =Ok |
lscordovar | 5:2e4e5085d597 | 24 | |
lscordovar | 5:2e4e5085d597 | 25 | int main() |
lscordovar | 5:2e4e5085d597 | 26 | { |
lscordovar | 5:2e4e5085d597 | 27 | Timer t; |
lscordovar | 5:2e4e5085d597 | 28 | |
lscordovar | 5:2e4e5085d597 | 29 | pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); |
lscordovar | 5:2e4e5085d597 | 30 | |
lscordovar | 5:2e4e5085d597 | 31 | for (int row=0; row<lcd.rows(); row++) { |
lscordovar | 5:2e4e5085d597 | 32 | int col=0; |
wim | 0:a75049de1a82 | 33 | |
lscordovar | 5:2e4e5085d597 | 34 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
wim | 4:a3e4bb2053cb | 35 | // lcd.putc('-'); |
lscordovar | 5:2e4e5085d597 | 36 | lcd.putc('0' + row); |
lscordovar | 5:2e4e5085d597 | 37 | |
lscordovar | 5:2e4e5085d597 | 38 | for (col=1; col<lcd.columns()-1; col++) { |
lscordovar | 5:2e4e5085d597 | 39 | lcd.putc('*'); |
lscordovar | 5:2e4e5085d597 | 40 | } |
lscordovar | 5:2e4e5085d597 | 41 | |
lscordovar | 5:2e4e5085d597 | 42 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
lscordovar | 5:2e4e5085d597 | 43 | lcd.putc('+'); |
wim | 4:a3e4bb2053cb | 44 | } |
lscordovar | 5:2e4e5085d597 | 45 | wait(1); |
lscordovar | 5:2e4e5085d597 | 46 | // Fill screen again and time it |
lscordovar | 5:2e4e5085d597 | 47 | t.start(); |
wim | 0:a75049de1a82 | 48 | |
lscordovar | 5:2e4e5085d597 | 49 | for (int row=0; row<lcd.rows(); row++) { |
lscordovar | 5:2e4e5085d597 | 50 | int col=0; |
lscordovar | 5:2e4e5085d597 | 51 | |
lscordovar | 5:2e4e5085d597 | 52 | lcd.putc('0' + row); |
wim | 3:f238b4f7874f | 53 | |
lscordovar | 5:2e4e5085d597 | 54 | for (col=1; col<lcd.columns()-1; col++) { |
lscordovar | 5:2e4e5085d597 | 55 | lcd.putc('*'); |
lscordovar | 5:2e4e5085d597 | 56 | } |
lscordovar | 5:2e4e5085d597 | 57 | |
lscordovar | 5:2e4e5085d597 | 58 | lcd.putc('+'); |
wim | 4:a3e4bb2053cb | 59 | } |
lscordovar | 5:2e4e5085d597 | 60 | t.stop(); |
lscordovar | 5:2e4e5085d597 | 61 | pc.printf("All my hard work took %f sec\r\n", t.read()); |
lscordovar | 5:2e4e5085d597 | 62 | wait(1); |
lscordovar | 5:2e4e5085d597 | 63 | |
wim | 1:ef419b21167d | 64 | |
wim | 4:a3e4bb2053cb | 65 | // Show cursor as blinking character |
lscordovar | 5:2e4e5085d597 | 66 | lcd.setCursor(TextLCD::CurOff_BlkOn); |
lscordovar | 5:2e4e5085d597 | 67 | |
wim | 4:a3e4bb2053cb | 68 | // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780. |
lscordovar | 5:2e4e5085d597 | 69 | // They are defined by a 5x7 bitpattern. |
lscordovar | 5:2e4e5085d597 | 70 | lcd.setUDC(0, (char *) udc_0); // Show |> |
lscordovar | 5:2e4e5085d597 | 71 | lcd.putc(0); |
lscordovar | 5:2e4e5085d597 | 72 | lcd.setUDC(1, (char *) udc_1); // Show <| |
lscordovar | 5:2e4e5085d597 | 73 | lcd.putc(1); |
lscordovar | 5:2e4e5085d597 | 74 | |
lscordovar | 5:2e4e5085d597 | 75 | pc.printf("Bye now\r\n"); |
lscordovar | 5:2e4e5085d597 | 76 | |
lscordovar | 5:2e4e5085d597 | 77 | wait(1); |
lscordovar | 5:2e4e5085d597 | 78 | |
lscordovar | 5:2e4e5085d597 | 79 | // Clear the screen and locate to 0,0 |
lscordovar | 5:2e4e5085d597 | 80 | lcd.cls(); |
lscordovar | 5:2e4e5085d597 | 81 | |
lscordovar | 5:2e4e5085d597 | 82 | // LCD Backlight control |
lscordovar | 5:2e4e5085d597 | 83 | lcd.setBacklight(TextLCD::LightOn); |
lscordovar | 5:2e4e5085d597 | 84 | |
lscordovar | 5:2e4e5085d597 | 85 | // LCD Orientation control, supported for some Controllers |
lscordovar | 5:2e4e5085d597 | 86 | //lcd.setOrient(TextLCD::Bottom); |
lscordovar | 5:2e4e5085d597 | 87 | |
lscordovar | 5:2e4e5085d597 | 88 | // LCD BigFont control, supported for some Controllers |
lscordovar | 5:2e4e5085d597 | 89 | //lcd.LCDBigFont(TextLCD::TopBottomLine); |
lscordovar | 5:2e4e5085d597 | 90 | |
lscordovar | 5:2e4e5085d597 | 91 | // Locate cursor to a screen column and row |
lscordovar | 5:2e4e5085d597 | 92 | int col = 0; |
lscordovar | 5:2e4e5085d597 | 93 | int row = 0; |
lscordovar | 5:2e4e5085d597 | 94 | lcd.locate(col,row); |
lscordovar | 5:2e4e5085d597 | 95 | wait(1); |
lscordovar | 5:2e4e5085d597 | 96 | |
lscordovar | 5:2e4e5085d597 | 97 | // Write a character to the LCD "ARROW" |
lscordovar | 5:2e4e5085d597 | 98 | int c = 1; |
lscordovar | 5:2e4e5085d597 | 99 | for (int row=0; row<lcd.rows(); row++) { |
lscordovar | 5:2e4e5085d597 | 100 | lcd.putc(c);wait(0.1); |
lscordovar | 5:2e4e5085d597 | 101 | |
lscordovar | 5:2e4e5085d597 | 102 | for (col=1; col<lcd.columns()-1; col++) { |
lscordovar | 5:2e4e5085d597 | 103 | lcd.putc(c);wait(0.1); |
lscordovar | 5:2e4e5085d597 | 104 | } |
lscordovar | 5:2e4e5085d597 | 105 | } |
lscordovar | 5:2e4e5085d597 | 106 | wait(2); |
lscordovar | 5:2e4e5085d597 | 107 | |
lscordovar | 5:2e4e5085d597 | 108 | // Write a raw string to the LCD |
lscordovar | 5:2e4e5085d597 | 109 | const char* text = "Hola text"; |
lscordovar | 5:2e4e5085d597 | 110 | lcd.cls(); |
lscordovar | 5:2e4e5085d597 | 111 | lcd.locate(1,1); |
lscordovar | 5:2e4e5085d597 | 112 | lcd.printf(text); |
lscordovar | 5:2e4e5085d597 | 113 | wait(1); |
lscordovar | 5:2e4e5085d597 | 114 | |
lscordovar | 5:2e4e5085d597 | 115 | // Write a raw string to the LCD *-> pointer* |
lscordovar | 5:2e4e5085d597 | 116 | const char* msg = "Hello printf"; |
lscordovar | 5:2e4e5085d597 | 117 | int string_size = strlen (msg); |
lscordovar | 5:2e4e5085d597 | 118 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
lscordovar | 5:2e4e5085d597 | 119 | lcd.locate(1,2); |
lscordovar | 5:2e4e5085d597 | 120 | lcd.printf("msg: %.*s", string_size, msg); |
lscordovar | 5:2e4e5085d597 | 121 | wait(1); |
lscordovar | 5:2e4e5085d597 | 122 | |
lscordovar | 5:2e4e5085d597 | 123 | |
lscordovar | 5:2e4e5085d597 | 124 | |
lscordovar | 5:2e4e5085d597 | 125 | // Return the memoryaddress of screen column and row location |
lscordovar | 5:2e4e5085d597 | 126 | lcd.getAddress(col,row); |
lscordovar | 5:2e4e5085d597 | 127 | pc.printf("column %d\trow %d\r\n",col,row); |
lscordovar | 5:2e4e5085d597 | 128 | wait(1); |
lscordovar | 5:2e4e5085d597 | 129 | |
lscordovar | 5:2e4e5085d597 | 130 | |
lscordovar | 5:2e4e5085d597 | 131 | |
lscordovar | 5:2e4e5085d597 | 132 | // Return the number of rows ans columns |
lscordovar | 5:2e4e5085d597 | 133 | pc.printf("column %d\trow %d\r\n",lcd.rows(),lcd.columns()); |
lscordovar | 5:2e4e5085d597 | 134 | wait(1); |
lscordovar | 5:2e4e5085d597 | 135 | |
lscordovar | 5:2e4e5085d597 | 136 | |
lscordovar | 5:2e4e5085d597 | 137 | |
wim | 4:a3e4bb2053cb | 138 | } |
wim | 3:f238b4f7874f | 139 | |
wim | 3:f238b4f7874f | 140 | |
wim | 0:a75049de1a82 | 141 |