![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Teste LCD I2C 20X4
main.cpp@4:ac48711f123b, 21 months ago (annotated)
- Committer:
- henriquer
- Date:
- Fri Nov 18 18:00:26 2022 +0000
- Revision:
- 4:ac48711f123b
- Parent:
- 3:e87183be497b
Teste LCD I2C 20X4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silviosz | 0:0c1de053c3b1 | 1 | // projeto: 2018_I2C_LCD_03 |
silviosz | 0:0c1de053c3b1 | 2 | // testado com PCF8574 em 2018-04-27 << Funcionando Ok |
silviosz | 0:0c1de053c3b1 | 3 | // Hello World! for the TextLCD |
silviosz | 0:0c1de053c3b1 | 4 | |
silviosz | 0:0c1de053c3b1 | 5 | #include "mbed.h" |
silviosz | 0:0c1de053c3b1 | 6 | #include "TextLCD.h" |
silviosz | 0:0c1de053c3b1 | 7 | |
silviosz | 0:0c1de053c3b1 | 8 | // Host PC Communication channels |
silviosz | 0:0c1de053c3b1 | 9 | Serial pc(USBTX, USBRX); // tx, rx |
silviosz | 0:0c1de053c3b1 | 10 | |
silviosz | 0:0c1de053c3b1 | 11 | // I2C Communication |
silviosz | 1:13cafaed8cff | 12 | I2C i2c_lcd(I2C_SDA, I2C_SCL); // SDA, SCL >>> NUCLEO: D14,D15 |
silviosz | 0:0c1de053c3b1 | 13 | |
silviosz | 0:0c1de053c3b1 | 14 | // SPI Communication |
silviosz | 0:0c1de053c3b1 | 15 | //SPI spi_lcd(D14, NC, D15); // MOSI, MISO, SCLK |
silviosz | 0:0c1de053c3b1 | 16 | |
silviosz | 0:0c1de053c3b1 | 17 | //4-bit bus |
silviosz | 0:0c1de053c3b1 | 18 | //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD40x2); // RS, E, D4-D7 |
silviosz | 0:0c1de053c3b1 | 19 | //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 |
silviosz | 0:0c1de053c3b1 | 20 | |
silviosz | 0:0c1de053c3b1 | 21 | //I2C Portexpander PCF8574 |
henriquer | 4:ac48711f123b | 22 | TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type Original = 0x42, Usando I2C scanner = 0x3F |
silviosz | 2:74d01fef184a | 23 | //TextLCD_I2C lcd(&i2c_lcd, 0x7e, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 addr, LCD Type, Ctrl Type |
silviosz | 0:0c1de053c3b1 | 24 | |
silviosz | 0:0c1de053c3b1 | 25 | //I2C Portexpander MCP23008 |
silviosz | 0:0c1de053c3b1 | 26 | //TextLCD_I2C lcd(&i2c_lcd, MCP23008_SA0, TextLCD::LCD16x3G, TextLCD::ST7036_3V3); // I2C bus, MCP23008 Slaveaddress, LCD Type, LCDTCtrl=ST7036 |
silviosz | 0:0c1de053c3b1 | 27 | |
silviosz | 0:0c1de053c3b1 | 28 | //SPI Portexpander SN74595 |
silviosz | 0:0c1de053c3b1 | 29 | //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD24x4D; TextLCD::KS0078); // SPI bus, CS pin, LCD Type |
silviosz | 0:0c1de053c3b1 | 30 | //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x2); // SPI bus, CS pin, LCD Type |
silviosz | 0:0c1de053c3b1 | 31 | //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type |
silviosz | 0:0c1de053c3b1 | 32 | |
silviosz | 0:0c1de053c3b1 | 33 | //Native I2C |
silviosz | 0:0c1de053c3b1 | 34 | //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 |
silviosz | 0:0c1de053c3b1 | 35 | //TextLCD_I2C_N lcd(&i2c_lcd, PCF2116_SA0, TextLCD::LCD12x4D, NC, TextLCD::PCF2116_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=PCF2116_3V3 |
silviosz | 0:0c1de053c3b1 | 36 | //TextLCD_I2C_N lcd(&i2c_lcd, PCF2116_SA0, TextLCD::LCD24x2, NC, TextLCD::PCF2116_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=PCF2116_3V3 |
silviosz | 0:0c1de053c3b1 | 37 | //TextLCD_I2C_N lcd(&i2c_lcd, SSD1803_SA1, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=SSD1803A |
silviosz | 0:0c1de053c3b1 | 38 | |
silviosz | 0:0c1de053c3b1 | 39 | //Native SPI 4 wire, 8 bits |
silviosz | 0:0c1de053c3b1 | 40 | //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 |
silviosz | 0:0c1de053c3b1 | 41 | |
silviosz | 0:0c1de053c3b1 | 42 | //Native SPI 3 wire, 10bits |
silviosz | 0:0c1de053c3b1 | 43 | //TextLCD_SPI_N_3_10 lcd(&spi_lcd, p8, TextLCD::LCD16x2, NC, TextLCD::WS0010); // SPI bus, CS, LCDType=LCD16x2, BL=NC, LCDTCtrl=WS0010 |
silviosz | 0:0c1de053c3b1 | 44 | //TextLCD_SPI_N lcd(&spi_lcd, p8, p9, TextLCD::LCD16x3G, NC, TextLCD::ST7036_3V3); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7036 |
silviosz | 0:0c1de053c3b1 | 45 | |
silviosz | 0:0c1de053c3b1 | 46 | //Native SPI 3 wire, 24 bits, SSD1803A |
silviosz | 0:0c1de053c3b1 | 47 | //TextLCD_SPI_N_3_24 lcd(&spi_lcd, p8, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // SPI bus, CS pin, LCDType=LCD20x4, BL=NC, LCDTCtrl=SSD1803A |
silviosz | 0:0c1de053c3b1 | 48 | |
silviosz | 0:0c1de053c3b1 | 49 | int main() { |
silviosz | 0:0c1de053c3b1 | 50 | pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); |
silviosz | 0:0c1de053c3b1 | 51 | |
henriquer | 4:ac48711f123b | 52 | // for (int row=0; row<lcd.rows(); row++) { |
henriquer | 4:ac48711f123b | 53 | // int col=0; |
silviosz | 0:0c1de053c3b1 | 54 | |
henriquer | 4:ac48711f123b | 55 | // pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
silviosz | 0:0c1de053c3b1 | 56 | // lcd.putc('-'); |
henriquer | 4:ac48711f123b | 57 | //lcd.putc('l' + row); |
silviosz | 0:0c1de053c3b1 | 58 | |
henriquer | 4:ac48711f123b | 59 | // for (col=1; col<lcd.columns()-1; col++) { |
henriquer | 4:ac48711f123b | 60 | lcd.locate(2,0); |
henriquer | 4:ac48711f123b | 61 | lcd.printf("TESTE LCD 20X4"); |
henriquer | 4:ac48711f123b | 62 | |
henriquer | 4:ac48711f123b | 63 | lcd.locate(4,2); |
henriquer | 4:ac48711f123b | 64 | lcd.printf("HENRIQUE"); |
henriquer | 4:ac48711f123b | 65 | //} |
silviosz | 0:0c1de053c3b1 | 66 | |
henriquer | 4:ac48711f123b | 67 | /// pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
henriquer | 4:ac48711f123b | 68 | // lcd.putc('+'); |
henriquer | 4:ac48711f123b | 69 | // } |
silviosz | 0:0c1de053c3b1 | 70 | |
silviosz | 0:0c1de053c3b1 | 71 | // Show cursor as blinking character |
henriquer | 4:ac48711f123b | 72 | |
henriquer | 4:ac48711f123b | 73 | |
henriquer | 4:ac48711f123b | 74 | |
silviosz | 0:0c1de053c3b1 | 75 | lcd.setCursor(TextLCD::CurOff_BlkOn); |
silviosz | 2:74d01fef184a | 76 | lcd.setBacklight(TextLCD::LightOn); |
silviosz | 3:e87183be497b | 77 | //lcd.setUDC(0, (char *) udc_AC); // Show |> |
henriquer | 4:ac48711f123b | 78 | //lcd.putc('LTH'); |
silviosz | 2:74d01fef184a | 79 | |
henriquer | 4:ac48711f123b | 80 | |
silviosz | 0:0c1de053c3b1 | 81 | } |