Initial setup for FC-113 controller of TextLCD(1602A)
This example is a simple use case for the user of Text LCD with the FC-113 controller, based on Mbed OS 5.
Note that PCF8574T has Mbed base addresses 0x40 ~ 0x4E, while PCF8574AT has base addresses 0x70 ~ 0x7E.
I used 0x4E for Text LCD with the FC-113 controller.
If you need to fine-tune the Text LCD or using another type the TextLCD, please see here.
main.cpp@7:9fcc3c0acd50, 2019-12-24 (annotated)
- Committer:
- Daniel_Lee
- Date:
- Tue Dec 24 05:30:57 2019 +0000
- Revision:
- 7:9fcc3c0acd50
- Parent:
- 2:b60cb847489c
Initialized for FC-113 controller of TextLCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:005629fe3609 | 1 | #include "mbed.h" |
Daniel_Lee | 7:9fcc3c0acd50 | 2 | #include "TextLCD.h" |
Daniel_Lee | 7:9fcc3c0acd50 | 3 | |
Daniel_Lee | 7:9fcc3c0acd50 | 4 | // I2C Communication |
Daniel_Lee | 7:9fcc3c0acd50 | 5 | I2C i2c_lcd(A4,A5); // SDA, SCL - I2C3 |
Daniel_Lee | 7:9fcc3c0acd50 | 6 | |
Daniel_Lee | 7:9fcc3c0acd50 | 7 | // SPI Communication |
Daniel_Lee | 7:9fcc3c0acd50 | 8 | //SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK |
screamer | 0:005629fe3609 | 9 | |
Daniel_Lee | 7:9fcc3c0acd50 | 10 | //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 |
Daniel_Lee | 7:9fcc3c0acd50 | 11 | //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type |
Daniel_Lee | 7:9fcc3c0acd50 | 12 | //TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type |
Daniel_Lee | 7:9fcc3c0acd50 | 13 | TextLCD_I2C lcd(&i2c_lcd, 0x4E); // I2C bus, PCF8574(FC-113) Slaveaddress, LCD Type(1602A) |
Daniel_Lee | 7:9fcc3c0acd50 | 14 | |
Daniel_Lee | 7:9fcc3c0acd50 | 15 | //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type |
Daniel_Lee | 7:9fcc3c0acd50 | 16 | //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 |
Daniel_Lee | 7:9fcc3c0acd50 | 17 | //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 |
screamer | 0:005629fe3609 | 18 | |
Daniel_Lee | 7:9fcc3c0acd50 | 19 | int main() |
Daniel_Lee | 7:9fcc3c0acd50 | 20 | { |
Daniel_Lee | 7:9fcc3c0acd50 | 21 | #if 0 |
Daniel_Lee | 7:9fcc3c0acd50 | 22 | pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); |
Daniel_Lee | 7:9fcc3c0acd50 | 23 | |
Daniel_Lee | 7:9fcc3c0acd50 | 24 | for (int row=0; row<lcd.rows(); row++) { |
Daniel_Lee | 7:9fcc3c0acd50 | 25 | int col=0; |
Daniel_Lee | 7:9fcc3c0acd50 | 26 | |
Daniel_Lee | 7:9fcc3c0acd50 | 27 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
Daniel_Lee | 7:9fcc3c0acd50 | 28 | // lcd.putc('-'); |
Daniel_Lee | 7:9fcc3c0acd50 | 29 | lcd.putc('0' + row); |
Daniel_Lee | 7:9fcc3c0acd50 | 30 | |
Daniel_Lee | 7:9fcc3c0acd50 | 31 | for (col=1; col<lcd.columns()-1; col++) { |
Daniel_Lee | 7:9fcc3c0acd50 | 32 | lcd.putc('*'); |
Daniel_Lee | 7:9fcc3c0acd50 | 33 | } |
Daniel_Lee | 7:9fcc3c0acd50 | 34 | |
Daniel_Lee | 7:9fcc3c0acd50 | 35 | pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); |
Daniel_Lee | 7:9fcc3c0acd50 | 36 | lcd.putc('+'); |
Daniel_Lee | 7:9fcc3c0acd50 | 37 | |
Daniel_Lee | 7:9fcc3c0acd50 | 38 | } |
Daniel_Lee | 7:9fcc3c0acd50 | 39 | |
Daniel_Lee | 7:9fcc3c0acd50 | 40 | // Show cursor as blinking character |
Daniel_Lee | 7:9fcc3c0acd50 | 41 | lcd.setCursor(TextLCD::CurOff_BlkOn); |
Daniel_Lee | 7:9fcc3c0acd50 | 42 | |
Daniel_Lee | 7:9fcc3c0acd50 | 43 | // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780. |
Daniel_Lee | 7:9fcc3c0acd50 | 44 | // They are defined by a 5x7 bitpattern. |
Daniel_Lee | 7:9fcc3c0acd50 | 45 | lcd.setUDC(0, (char *) udc_0); // Show |> |
Daniel_Lee | 7:9fcc3c0acd50 | 46 | lcd.putc(0); |
Daniel_Lee | 7:9fcc3c0acd50 | 47 | lcd.setUDC(1, (char *) udc_1); // Show <| |
Daniel_Lee | 7:9fcc3c0acd50 | 48 | lcd.putc(1); |
Daniel_Lee | 7:9fcc3c0acd50 | 49 | #else |
Daniel_Lee | 7:9fcc3c0acd50 | 50 | lcd.cls (); |
Daniel_Lee | 7:9fcc3c0acd50 | 51 | lcd.setBacklight (TextLCD :: LightOn); |
Daniel_Lee | 7:9fcc3c0acd50 | 52 | lcd.printf ("LCD check - online compile"); |
Daniel_Lee | 7:9fcc3c0acd50 | 53 | lcd.setAddress (0, 1); |
Daniel_Lee | 7:9fcc3c0acd50 | 54 | lcd.printf ("Hello MBED\n"); |
Daniel_Lee | 7:9fcc3c0acd50 | 55 | #endif |
Daniel_Lee | 7:9fcc3c0acd50 | 56 | } |