Hello World demo for Enhanced TextLCD lib.

Dependencies:   TextLCD mbed

Dependents:   Opener-6

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Hello World! for the TextLCD Enhanced Library*/
00002 
00003 #include "mbed.h"
00004 #include "TextLCD.h"
00005  
00006 // Host PC Communication channels
00007 Serial pc(USBTX, USBRX); // tx, rx
00008  
00009 // I2C Communication
00010 I2C i2c_lcd(p9,p10); // SDA, SCL
00011 //I2C i2c_lcd(p28,p27); // SDA, SCL
00012  
00013 // SPI Communication
00014 SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
00015 
00016 // LCD instantiation 
00017 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2);        // 4bit bus: rs, e, d4-d7
00018 TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD20x4);                  // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
00019 //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type, Ctrl Type
00020 //TextLCD_I2C lcd(&spi_lcd, p8, TextLCD::LCD24x4D);                   // I2C exp: SPI bus, CS pin, LCD Type
00021 //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
00022 //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
00023 //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
00024  
00025 int main() {   
00026   Timer t;
00027 
00028   pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
00029     
00030   for (int row=0; row<lcd.rows(); row++) {
00031     int col=0;
00032       
00033     pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
00034 //    lcd.putc('-');
00035     lcd.putc('0' + row);      
00036       
00037     for (col=1; col<lcd.columns()-1; col++) {    
00038       lcd.putc('*');
00039     }
00040  
00041     pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
00042     lcd.putc('+');       
00043   }    
00044 
00045 // Fill screen again and time it
00046   t.start();
00047 
00048   for (int row=0; row<lcd.rows(); row++) {
00049     int col=0;
00050       
00051     lcd.putc('0' + row);      
00052       
00053     for (col=1; col<lcd.columns()-1; col++) {    
00054       lcd.putc('*');
00055     }
00056  
00057     lcd.putc('+');       
00058   }    
00059   t.stop();    
00060   pc.printf("All my hard work took %f sec\r\n", t.read());          
00061 
00062 // Show cursor as blinking character
00063    lcd.setCursor(TextLCD::CurOff_BlkOn);
00064  
00065 // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
00066 // They are defined by a 5x7 bitpattern. 
00067   lcd.setUDC(0, (char *) udc_0);  // Show |>
00068   lcd.putc(0);    
00069   lcd.setUDC(1, (char *) udc_1);  // Show <|
00070   lcd.putc(1);    
00071     
00072   pc.printf("Bye now\r\n");          
00073 }
00074 
00075 
00076