![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TESTE
main.cpp@5:be6d331f81c1, 21 months ago (annotated)
- Committer:
- henriquer
- Date:
- Fri Nov 18 12:29:44 2022 +0000
- Revision:
- 5:be6d331f81c1
- Parent:
- 4:a3e4bb2053cb
TESTE 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" |
wim | 4:a3e4bb2053cb | 5 | |
wim | 0:a75049de1a82 | 6 | // Host PC Communication channels |
wim | 0:a75049de1a82 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
wim | 4:a3e4bb2053cb | 8 | |
wim | 0:a75049de1a82 | 9 | // I2C Communication |
henriquer | 5:be6d331f81c1 | 10 | I2C i2c_lcd(D15,D14); // SDA, SCL |
wim | 4:a3e4bb2053cb | 11 | //I2C i2c_lcd(p28,p27); // SDA, SCL |
wim | 4:a3e4bb2053cb | 12 | |
wim | 0:a75049de1a82 | 13 | // SPI Communication |
henriquer | 5:be6d331f81c1 | 14 | //SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK |
wim | 0:a75049de1a82 | 15 | |
wim | 4:a3e4bb2053cb | 16 | // LCD instantiation |
wim | 4:a3e4bb2053cb | 17 | //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // 4bit bus: rs, e, d4-d7 |
henriquer | 5:be6d331f81c1 | 18 | TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type |
henriquer | 5:be6d331f81c1 | 19 | //TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2, TextLCD::HD44780); // 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 |
wim | 4:a3e4bb2053cb | 24 | |
wim | 4:a3e4bb2053cb | 25 | int main() { |
wim | 4:a3e4bb2053cb | 26 | Timer t; |
wim | 0:a75049de1a82 | 27 | |
wim | 4:a3e4bb2053cb | 28 | pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); |
wim | 4:a3e4bb2053cb | 29 | |
wim | 4:a3e4bb2053cb | 30 | for (int row=0; row<lcd.rows(); row++) { |
wim | 4:a3e4bb2053cb | 31 | int col=0; |
wim | 4:a3e4bb2053cb | 32 | |
wim | 4:a3e4bb2053cb | 33 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
wim | 4:a3e4bb2053cb | 34 | // lcd.putc('-'); |
wim | 4:a3e4bb2053cb | 35 | lcd.putc('0' + row); |
wim | 4:a3e4bb2053cb | 36 | |
wim | 4:a3e4bb2053cb | 37 | for (col=1; col<lcd.columns()-1; col++) { |
wim | 4:a3e4bb2053cb | 38 | lcd.putc('*'); |
wim | 4:a3e4bb2053cb | 39 | } |
wim | 4:a3e4bb2053cb | 40 | |
wim | 4:a3e4bb2053cb | 41 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
wim | 4:a3e4bb2053cb | 42 | lcd.putc('+'); |
wim | 4:a3e4bb2053cb | 43 | } |
wim | 0:a75049de1a82 | 44 | |
wim | 4:a3e4bb2053cb | 45 | // Fill screen again and time it |
wim | 4:a3e4bb2053cb | 46 | t.start(); |
wim | 3:f238b4f7874f | 47 | |
wim | 4:a3e4bb2053cb | 48 | for (int row=0; row<lcd.rows(); row++) { |
wim | 4:a3e4bb2053cb | 49 | int col=0; |
wim | 4:a3e4bb2053cb | 50 | |
wim | 4:a3e4bb2053cb | 51 | lcd.putc('0' + row); |
wim | 4:a3e4bb2053cb | 52 | |
wim | 4:a3e4bb2053cb | 53 | for (col=1; col<lcd.columns()-1; col++) { |
wim | 4:a3e4bb2053cb | 54 | lcd.putc('*'); |
wim | 4:a3e4bb2053cb | 55 | } |
wim | 4:a3e4bb2053cb | 56 | |
wim | 4:a3e4bb2053cb | 57 | lcd.putc('+'); |
wim | 4:a3e4bb2053cb | 58 | } |
wim | 4:a3e4bb2053cb | 59 | t.stop(); |
wim | 4:a3e4bb2053cb | 60 | pc.printf("All my hard work took %f sec\r\n", t.read()); |
wim | 1:ef419b21167d | 61 | |
wim | 4:a3e4bb2053cb | 62 | // Show cursor as blinking character |
wim | 4:a3e4bb2053cb | 63 | lcd.setCursor(TextLCD::CurOff_BlkOn); |
wim | 4:a3e4bb2053cb | 64 | |
wim | 4:a3e4bb2053cb | 65 | // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780. |
wim | 4:a3e4bb2053cb | 66 | // They are defined by a 5x7 bitpattern. |
wim | 4:a3e4bb2053cb | 67 | lcd.setUDC(0, (char *) udc_0); // Show |> |
wim | 4:a3e4bb2053cb | 68 | lcd.putc(0); |
wim | 4:a3e4bb2053cb | 69 | lcd.setUDC(1, (char *) udc_1); // Show <| |
wim | 4:a3e4bb2053cb | 70 | lcd.putc(1); |
wim | 4:a3e4bb2053cb | 71 | |
wim | 4:a3e4bb2053cb | 72 | pc.printf("Bye now\r\n"); |
wim | 4:a3e4bb2053cb | 73 | } |
wim | 3:f238b4f7874f | 74 | |
wim | 3:f238b4f7874f | 75 | |
wim | 0:a75049de1a82 | 76 |