Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TextLCD by
Revision 27:22d5086f6ba6, committed 2014-06-13
- Comitter:
- wim
- Date:
- Fri Jun 13 19:02:26 2014 +0000
- Parent:
- 26:bd897a001012
- Child:
- 28:30fa94f7341c
- Commit message:
- First test of native SPI
Changed in this revision
| TextLCD.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TextLCD.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TextLCD.cpp Fri May 30 15:05:13 2014 +0000
+++ b/TextLCD.cpp Fri Jun 13 19:02:26 2014 +0000
@@ -49,28 +49,25 @@
// Select and configure second LCD controller when needed
if(_type==LCD40x4) {
- _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
+ _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
- _initCtrl(); // Init 2nd controller
+ _initCtrl(); // Init 2nd controller
// Secondary LCD controller Clearscreen
- _writeCommand(0x01); // cls, and set cursor to 0
+ _writeCommand(0x01); // cls, and set cursor to 0
wait_ms(10); // The CLS command takes 1.64 ms.
- // Since we are not using the Busy flag, Lets be safe and take 10 ms
-
+ // Since we are not using the Busy flag, Lets be safe and take 10 ms
}
// Select and configure primary LCD controller
- _ctrl_idx=_LCDCtrl_0; // Select primary controller
+ _ctrl_idx=_LCDCtrl_0; // Select primary controller
_initCtrl(); // Init primary controller
// Primary LCD controller Clearscreen
- _writeCommand(0x01); // cls, and set cursor to 0
-
+ _writeCommand(0x01); // cls, and set cursor to 0
wait_ms(10); // The CLS command takes 1.64 ms.
- // Since we are not using the Busy flag, Lets be safe and take 10 ms
-
+ // Since we are not using the Busy flag, Lets be safe and take 10 ms
}
/** Init the LCD controller
@@ -92,54 +89,68 @@
wait_us(40); // most instructions take 40us
// Display is now in 4-bit mode
+ // Note: 4 bit mode is ignored for native SPI and I2C devices
// Device specific initialisations for DC/DC converter to generate VLCD or VLED
switch (_ctrl) {
case ST7036:
// ST7036 controller: Initialise Voltage booster for VLCD. VDD=5V
// Note: supports 1,2 or 3 lines
- _writeByte( 0x29 ); // 4-bit Databus, 2 Lines, Select Instruction table 1
+ _writeByte( 0x29 ); // 4-bit Databus, 2 Lines, Select Instruction Set = 1
wait_ms(30); // > 26,3ms
_writeByte( 0x14 ); // Bias: 1/5, 2-Lines LCD
wait_ms(30); // > 26,3ms
_writeByte( 0x55 ); // Icon off, Booster on, Set Contrast C5, C4
wait_ms(30); // > 26,3ms
- _writeByte( 0x6d ); // Voltagefollower On, Ampl ratio Rab2, Rab1, Rab0
+ _writeByte( 0x6D ); // Voltagefollower On, Ampl ratio Rab2, Rab1, Rab0
wait_ms(200); // > 200ms!
_writeByte( 0x78 ); // Set Contrast C3, C2, C1, C0
wait_ms(30); // > 26,3ms
- _writeByte( 0x28 ); // Return to Instruction table 0
+ _writeByte( 0x28 ); // Return to Instruction Set = 0
wait_ms(50);
break;
case ST7032_3V3:
// ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3
-
- _writeByte( 0x1c ); //Internal OSC frequency adjustment 183HZ, bias will be 1/4
+
+// _writeByte( 0x39 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot, Select Instruction Set = 1
+ _writeByte( 0x29 ); //FUNCTION SET 4 bit, N=1 2-line display mode, 5*7dot, Select Instruction Set = 1
+ //Note: 4 bit mode is ignored for native SPI and I2C devices
+ wait_us(30);
+ _writeByte( 0x1C ); //Internal OSC frequency adjustment 183HZ, bias will be 1/4
wait_us(30);
_writeByte( 0x73 ); //Contrast control low byte
wait_us(30);
_writeByte( 0x57 ); //booster circuit is turned on. /ICON display off. /Contrast control high byte
wait_us(30);
- _writeByte( 0x6c ); //Follower control
+ _writeByte( 0x6C ); //Follower control
wait_us(50);
- _writeByte( 0x0c ); //DISPLAY ON, not needed
+// _writeByte( 0x0C ); //DISPLAY ON, not needed
+// _writeByte( 0x38 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot, Return to Instruction Set = 0
+ _writeByte( 0x28 ); //FUNCTION SET 4 bit, N=1 2-line display mode, 5*7dot, Return to Instruction Set = 0
+ //Note: 4 bit mode is ignored for native SPI and I2C devices
wait_us(30);
break;
//Check and fix booster disable
case ST7032_5V:
// ST7032 controller: Disable Voltage booster for VLCD. VDD=5V
-
- _writeByte( 0x1c ); //Internal OSC frequency adjustment 183HZ, bias will be 1/4
+// _writeByte( 0x39 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot, Instruction Set = 1
+ _writeByte( 0x29 ); //FUNCTION SET 4 bit, N=1 2-line display mode, 5*7dot, Select Instruction Set = 1
+ //Note: 4 bit mode is ignored for native SPI and I2C devices
+ wait_us(30);
+ _writeByte( 0x1C ); //Internal OSC frequency adjustment 183HZ, bias will be 1/4
wait_us(30);
_writeByte( 0x73 ); //Contrast control low byte
wait_us(30);
_writeByte( 0x57 ); //booster circuit is turned on. /ICON display off. /Contrast control high byte
wait_us(30);
- _writeByte( 0x6c ); //Follower control
+ _writeByte( 0x6C ); //Follower control
wait_us(50);
- _writeByte( 0x0c ); //DISPLAY ON --> remove, done later?
+// _writeByte( 0x0C ); //DISPLAY ON --> remove, done later?
+// _writeByte( 0x38 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot, Instruction Set = 0
+ _writeByte( 0x28 ); //FUNCTION SET 4 bit, N=1 2-line display mode, 5*7dot, Return to Instruction Set = 0
+ //Note: 4 bit mode is ignored for native SPI and I2C devices
wait_us(30);
break;
@@ -208,7 +219,8 @@
// All other LCD types are initialised as 2 Line displays (including LCD40x4)
default:
_writeCommand(0x28); // Function set 001 DL N F - -
- // DL=0 (4 bits bus)
+ // DL=0 (4 bits bus)
+ // Note: 4 bit mode is ignored for native SPI and I2C devices
// N=1 (2 lines)
// F=0 (5x7 dots font, only option for 2 line display)
// - (Don't care)
@@ -240,8 +252,7 @@
_setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
// Second LCD controller Clearscreen
- _writeCommand(0x01); // cls, and set cursor to 0
-
+ _writeCommand(0x01); // cls, and set cursor to 0
wait_ms(10); // The CLS command takes 1.64 ms.
// Since we are not using the Busy flag, Lets be safe and take 10 ms
@@ -250,8 +261,7 @@
}
// Primary LCD controller Clearscreen
- _writeCommand(0x01); // cls, and set cursor to 0
-
+ _writeCommand(0x01); // cls, and set cursor to 0
wait_ms(10); // The CLS command takes 1.64 ms.
// Since we are not using the Busy flag, Lets be safe and take 10 ms
@@ -893,17 +903,17 @@
#if (MCP23008==1)
// MCP23008 portexpander Init
- _write_register(IODIR, 0x00); // All outputs
- _write_register(IPOL, 0x00); // No reverse polarity
- _write_register(GPINTEN, 0x00); // No interrupt
- _write_register(DEFVAL, 0x00); // Default value to compare against for interrupts
- _write_register(INTCON, 0x00); // No interrupt on changes
- _write_register(IOCON, 0x00); // Interrupt polarity
- _write_register(GPPU, 0x00); // No Pullup
- _write_register(INTF, 0x00); //
- _write_register(INTCAP, 0x00); //
- _write_register(GPIO, 0x00); // Output/Input pins
- _write_register(OLAT, 0x00); // Output Latch
+ _write_register(IODIR, 0x00); // All outputs
+ _write_register(IPOL, 0x00); // No reverse polarity
+ _write_register(GPINTEN, 0x00); // No interrupt
+ _write_register(DEFVAL, 0x00); // Default value to compare against for interrupts
+ _write_register(INTCON, 0x00); // No interrupt on changes
+ _write_register(IOCON, 0x00); // Interrupt polarity
+ _write_register(GPPU, 0x00); // No Pullup
+ _write_register(INTF, 0x00); //
+ _write_register(INTCAP, 0x00); //
+ _write_register(GPIO, 0x00); // Output/Input pins
+ _write_register(OLAT, 0x00); // Output Latch
// Init the portexpander bus
_lcd_bus = D_LCD_BUS_DEF;
@@ -1264,8 +1274,6 @@
_bl = NULL; //Construct dummy pin
}
- _writeByte( 0x39 ); //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot IS=1
- wait_us(30);
_init();
}
--- a/TextLCD.h Fri May 30 15:05:13 2014 +0000
+++ b/TextLCD.h Fri Jun 13 19:02:26 2014 +0000
@@ -38,8 +38,8 @@
/** A TextLCD interface for driving 4-bit HD44780-based LCDs
*
* Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
- * Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A, MCP23008) or SPI bus shiftregister (74595)
- * Supports some controllers that provide internal DC/DC converters for VLCD or VLED.
+ * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595).
+ * Supports some controllers with native I2C or SP interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED.
*
* @code
* #include "mbed.h"
@@ -55,7 +55,7 @@
* //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type
* TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
* //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
- * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032
+ * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3
*
* int main() {
* lcd.printf("Hello World!\n");
@@ -68,8 +68,8 @@
//LCD and serial portexpanders should be wired accordingly
//
//Select Hardware module (one option only)
-#define DEFAULT 1
-#define ADAFRUIT 0
+#define DEFAULT 0
+#define ADAFRUIT 1
#define DFROBOT 0
@@ -251,7 +251,7 @@
/** A TextLCD interface for driving 4-bit HD44780-based LCDs
*
* @brief Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
- * Interface options include direct mbed pins, I2C portexpander (PCF8474, PCF8574A) or SPI bus shiftregister (74595) and some native I2C or SPI devices
+ * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595) and some native I2C or SPI devices
*
*/
class TextLCD_Base : public Stream {
