diff --git a/LiquidCrystal_SR.h b/LiquidCrystal_SR.h index 57dd048..bced38b 100644 --- a/LiquidCrystal_SR.h +++ b/LiquidCrystal_SR.h @@ -116,16 +116,6 @@ public: */ virtual void send(uint8_t value, uint8_t mode); - /*! - @function - @abstract Switch-on/off the LCD backlight. - @discussion Switch-on/off the LCD backlight. - The setBacklightPin has to be called before setting the backlight for - this method to work. @see setBacklightPin. - - @param mode: backlight mode (HIGH|LOW) - */ - void setBacklight ( uint8_t mode ); /*! @function @@ -136,7 +126,16 @@ public: */ void setBacklightPin ( uint8_t pin ); - + /*! + @function + @abstract Switch-on/off the LCD backlight. + @discussion Switch-on/off the LCD backlight. + The setBacklightPin has to be called before setting the backlight for + this method to work. @see setBacklightPin. + + @param mode: backlight mode (HIGH|LOW) + */ + void setBacklight ( uint8_t mode ); private: @@ -153,17 +152,17 @@ private: * @abstract takes care of shifting and the enable pulse */ void shiftIt (uint8_t val); - + uint8_t _enable_pin; // Enable Pin uint8_t _two_wire; // two wire mode - + fio_register _srDataRegister; // Serial Data pin fio_bit _srDataBit; fio_register _srClockRegister; // Clock Pin fio_bit _srClockBit; fio_register _srEnableRegister; // Enable Pin fio_bit _srEnableBit; - + }; #endif diff --git a/LiquidCrystal_SR_LCD3.cpp b/LiquidCrystal_SR_LCD3.cpp index ed61461..2f1542a 100755 --- a/LiquidCrystal_SR_LCD3.cpp +++ b/LiquidCrystal_SR_LCD3.cpp @@ -103,6 +103,7 @@ #include #include #include +#include // for critical section management #if (ARDUINO < 100) #include @@ -120,7 +121,7 @@ // --------------------------------------------------------------------------- // Assuming 1 line 8 pixel high font LiquidCrystal_SR_LCD3::LiquidCrystal_SR_LCD3 ( uint8_t srdata, uint8_t srclock, - uint8_t strobe ) + uint8_t strobe ) { init ( srdata, srclock, strobe, 1, 0 ); } @@ -132,12 +133,12 @@ LiquidCrystal_SR_LCD3::LiquidCrystal_SR_LCD3 ( uint8_t srdata, uint8_t srclock, // // init void LiquidCrystal_SR_LCD3::init( uint8_t srdata, uint8_t srclock, uint8_t strobe, - uint8_t lines, uint8_t font ) + uint8_t lines, uint8_t font ) { // Initialise private variables // translate all pins to bits and registers // pinMode to OUTPUT, Output LOW - + _srdata_bit = fio_pinToBit(srdata); _srdata_register = fio_pinToOutputRegister(srdata); _srclock_bit = fio_pinToBit(srclock); @@ -147,7 +148,7 @@ void LiquidCrystal_SR_LCD3::init( uint8_t srdata, uint8_t srclock, uint8_t strob // Little trick to force a pulse of the LCD enable bit and make sure it is // low before we start further writes since this is assumed. - + write4bits(0); _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x10DOTS; @@ -200,8 +201,11 @@ void LiquidCrystal_SR_LCD3::_pushOut(uint8_t nibble) fio_shiftOut(_srdata_register, _srdata_bit, _srclock_register, _srclock_bit, nibble, LSBFIRST); // Make new data active. - fio_digitalWrite_HIGH(_strobe_register, _strobe_bit); - waitUsec( 1 ); // strobe pulse must be >450ns (old code had 10ms) - fio_digitalWrite_SWITCHTO(_strobe_register, _strobe_bit,LOW); + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + fio_digitalWrite_HIGH(_strobe_register, _strobe_bit); + waitUsec( 1 ); // strobe pulse must be >450ns (old code had 10ms) + fio_digitalWrite_SWITCHTO(_strobe_register, _strobe_bit,LOW); + } waitUsec( 40 ); // commands need > 37us to settle } diff --git a/LiquidCrystal_SR_LCD3.h b/LiquidCrystal_SR_LCD3.h index 049bec4..8b895e3 100755 --- a/LiquidCrystal_SR_LCD3.h +++ b/LiquidCrystal_SR_LCD3.h @@ -61,11 +61,11 @@ private: */ void write4bits ( uint8_t ); void _pushOut ( uint8_t ); - + // Serial Data pin fio_bit _srdata_bit; fio_register _srdata_register; - + // Clock Pin fio_bit _srclock_bit; fio_register _srclock_register;