Modified the send method to initialize correctly the LCD. Send method now has three modes: COMMAND, DATA, FOUR_BITS.

setBacklight method check if a particular pin is mapped to a PMW.
This commit is contained in:
FMC
2012-03-05 23:32:51 +01:00
parent ee74a0a484
commit 7a0a2f948c
7 changed files with 68 additions and 29 deletions
+4 -4
View File
@@ -103,19 +103,19 @@ void LCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
command ( 0x03 );
send(0x03, FOUR_BITS);
delayMicroseconds(4500); // wait min 4.1ms
// second try
command ( 0x03 );
send ( 0x03, FOUR_BITS );
delayMicroseconds(4500); // wait min 4.1ms
// third go!
command ( 0x03 );
send( 0x03, FOUR_BITS );
delayMicroseconds(150);
// finally, set to 4-bit interface
command ( 0x02 );
send ( 0x02, FOUR_BITS );
}
else
{
+1
View File
@@ -131,6 +131,7 @@ inline static void waitUsec ( uint16_t uSec )
// ---------------------------------------------------------------------------
#define COMMAND 0
#define DATA 1
#define FOUR_BITS 2
/*!
@defined
+26 -7
View File
@@ -79,11 +79,12 @@ LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
// ---------------------------------------------------------------------------
/************ low level data pushing commands **********/
//
// send
void LiquidCrystal::send(uint8_t value, uint8_t mode)
{
digitalWrite( _rs_pin, mode );
// Only interested in COMMAND or DATA
digitalWrite( _rs_pin, ( mode == DATA ) );
// if there is a RW pin indicated, set it low to Write
// ---------------------------------------------------
@@ -92,13 +93,20 @@ void LiquidCrystal::send(uint8_t value, uint8_t mode)
digitalWrite(_rw_pin, LOW);
}
if (_displayfunction & LCD_8BITMODE)
{
writeNbits(value, 8);
if ( mode != FOUR_BITS )
{
if ( (_displayfunction & LCD_8BITMODE ) )
{
writeNbits(value, 8);
}
else
{
writeNbits ( value >> 4, 4 );
writeNbits ( value, 4 );
}
}
else
{
writeNbits ( value >> 4, 4 );
writeNbits ( value, 4 );
}
waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
@@ -118,7 +126,18 @@ void LiquidCrystal::setBacklight ( uint8_t value )
{
if ( _backlightPin != LCD_NOBACKLIGHT )
{
analogWrite ( _backlightPin, value );
if(digitalPinToTimer(_backlightPin) != NOT_ON_TIMER)
{
analogWrite ( _backlightPin, value );
}
else if(value)
{
digitalWrite( _backlightPin, HIGH);
}
else
{
digitalWrite( _backlightPin, LOW);
}
}
}
+1 -2
View File
@@ -100,11 +100,10 @@ public:
backlight, the configuration pin must be a PWM output pin. Dim control
is achieved by passing a value from 1 to 255 as a parameter. If the
pin configured when calling the setBacklightPin does not support PWM,
then: (0..127) backlight off, (128..255) backlight on.
then: (0) backlight off, (1..255) backlight on.
@param value: backlight value. 0: off, 1..255: dim control of the
backlight. For negative logic 255: off, 254..0: dim control.
For non PWM pins: 0..127 - backligh off, 128..255 - backlight on.
*/
void setBacklight ( uint8_t value );
+10 -2
View File
@@ -176,8 +176,16 @@ void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode)
// No need to use the delay routines since the time taken to write takes
// longer that what is needed both for toggling and enable pin an to execute
// the command.
write4bits( (value >> 4), mode );
write4bits( (value & 0x0F), mode);
if ( mode == FOUR_BITS )
{
write4bits( (value & 0x0F), COMMAND );
}
else
{
write4bits( (value >> 4), mode );
write4bits( (value & 0x0F), mode);
}
}
//
+13 -3
View File
@@ -168,9 +168,19 @@ void LiquidCrystal_SR::send(uint8_t value, uint8_t mode)
{
// Divide byte in two nibbles include the RS signal
// and format it for shiftregister output wiring to the LCD
mode = mode ? SR_RS_BIT : 0; // RS bit; LOW: command. HIGH: character.
shiftIt(mode | SR_EN_BIT | ((value >> 1) & 0x78)); // upper nibble
shiftIt(mode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
// We are only interested in my COMMAND or DATA for myMode
uint8_t myMode = ( mode == DATA ) ? SR_RS_BIT : 0; // RS bit; LOW: command. HIGH: character.
if ( mode != FOUR_BITS )
{
shiftIt(myMode | SR_EN_BIT | ((value >> 1) & 0x78)); // upper nibble
shiftIt(myMode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
}
else
{
shiftIt(myMode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
}
}
//
+13 -11
View File
@@ -169,18 +169,20 @@ void LiquidCrystal_SR_LCD3::init( uint8_t srdata, uint8_t srclock, uint8_t strob
#define SR_RS_BIT B01000000 // LOW: command. HIGH: character.
void LiquidCrystal_SR_LCD3::send(uint8_t value, uint8_t mode)
{
uint8_t nibble;
{
// only interested on COMMAND or DATA
uint8_t myMode = ( mode == DATA ) ? SR_RS_BIT : 0; // RS bit; LOW: command. HIGH: character.
mode = mode ? SR_RS_BIT : 0; // RS bit; LOW: command. HIGH: character.
nibble = value >> 4; // Get high nibble.
write4bits(nibble | mode);
//delay(1); // This was in the LCD3 code but does not seem needed -- merlin
nibble = value & 15; // Get low nibble
write4bits(nibble | mode);
if ( mode != FOUR_BITS )
{
write4bits( ( value >> 4 ) | myMode);
write4bits( ( value & 0x0F ) | myMode);
}
else
{
write4bits( ( value & 0x0F ) | myMode);
}
}
void LiquidCrystal_SR_LCD3::write4bits(uint8_t nibble)