| LCD Library 1.2.1 LCD Library - LCD control class hierarchy library. Drop in replacement for the LiquidCrystal Library.

- Main Page
- Classes
- Files

- File List
- File Members

/Users/fmalpartida/development/ardWorkspace/LiquidCrystal_I2C/LiquiCrystal_I2C/LiquidCrystal_SR2W.cpp
Go to the documentation of this file.

    00001 // ---------------------------------------------------------------------------
    00002 // Created/Adapted by Bill Perry 2012-03-16
    00003 // Copyright 2012 - Under creative commons license 3.0:
    00004 //        Attribution-ShareAlike CC BY-SA
    00005 //
    00006 // This software is furnished "as is", without technical support, and with no
    00007 // warranty, express or implied, as to its usefulness for any purpose.
    00008 //
    00009 // Thread Safe: No
    00010 // Extendable: Yes
    00011 //
    00012 // @file LiquidCrystal_SR2W.cpp
    00013 // Connects a hd44780 LCD using 2 pins from the Arduino, via an 8-bit
    00014 // ShiftRegister (SR2W from now on).
    00015 //
    00016 // @brief
    00017 // This is a port of the ShiftRegLCD library from raron and ported to the
    00018 // LCD library.
    00019 //
    00020 //
    00021 // See the corresponding SR2W header file for full details.
    00022 //
    00023 // History
    00024 // 2012.03.29  bperrybap - Fixed incorrect use of 5x10 for default font
    00025 //                         (now matches original LQ library)
    00026 //                         Fixed typo in SR2W mask define names
    00027 //                         changed default backlight state to on
    00028 // 2012.03.16  bperrybap - created/modified from SR sources to create SR2W
    00029 // @author B. Perry - bperrybap@opensource.billsworld.billandterrie.com
    00030 // ---------------------------------------------------------------------------
    00031
    00032 #include "LiquidCrystal_SR2W.h"
    00033
    00034 // CONSTRUCTORS
    00035 // ---------------------------------------------------------------------------
    00036 // Assuming 1 line 8 pixel high font
    00037 LiquidCrystal_SR2W::LiquidCrystal_SR2W (uint8_t srdata, uint8_t srclock, t_backlighPol blpol)
    00038 {
    00039         init ( srdata, srclock, blpol, 1, 0 );
    00040 }
    00041
    00042
    00043 // PRIVATE METHODS
    00044 // ---------------------------------------------------------------------------
    00045
    00046 //
    00047 // init
    00048 void LiquidCrystal_SR2W::init(uint8_t srdata, uint8_t srclock, t_backlighPol blpol, uint8_t lines, uint8_t font)
    00049 {
    00050         _srDataRegister = fio_pinToOutputRegister(srdata);
    00051         _srDataMask = fio_pinToBit(srdata);
    00052         _srClockRegister = fio_pinToOutputRegister(srclock);
    00053         _srClockMask = fio_pinToBit(srclock);
    00054
    00055         _blPolarity = blpol;
    00056
    00057         _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
    00058
    00059         backlight(); // set default backlight state to on
    00060 }
    00061
    00062 //
    00063 // loadSR
    00064 void LiquidCrystal_SR2W::loadSR(uint8_t val)
    00065 {
    00066         // Clear to keep Enable LOW while clocking in new bits
    00067         fio_shiftOut(_srDataRegister, _srDataMask, _srClockRegister, _srClockMask);
    00068
    00069
    00070         // clock out SR data byte
    00071         fio_shiftOut(_srDataRegister, _srDataMask, _srClockRegister, _srClockMask, val, MSBFIRST);
    00072
    00073
    00074         // strobe LCD enable which can now be toggled by the data line
    00075         ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
    00076         {
    00077                 fio_digitalWrite_HIGH(_srDataRegister, _srDataMask);
    00078                 waitUsec (1);         // enable pulse must be >450ns
    00079                 fio_digitalWrite_SWITCHTO(_srDataRegister, _srDataMask, LOW);
    00080         } // end critical section
    00081 }
    00082
    00083 // PUBLIC METHODS
    00084 // ---------------------------------------------------------------------------
    00085
    00086
    00087 /************ low level data pushing commands **********/
    00088 //
    00089 // send
    00090 void LiquidCrystal_SR2W::send(uint8_t value, uint8_t mode)
    00091 {
    00092         uint8_t myMode = ( mode == DATA ) ? SR2W_RS_MASK : 0;
    00093
    00094         myMode = myMode | SR2W_EN_MASK | _blMask;
    00095
    00096         if ( mode != FOUR_BITS )
    00097         {
    00098                 loadSR(myMode | ((value >> 1) & SR2W_DATA_MASK)); // upper nibble
    00099         }
    00100
    00101         loadSR(myMode | ((value << 3) & SR2W_DATA_MASK)); // lower nibble
    00102
    00103         /*
    00104          * Don't call waitUsec()
    00105          * do our own delay optmization since this code is so fast it needs some added delay
    00106          * even on slower AVRs.
    00107          */
    00108 #if (F_CPU <= 16000000)
    00109         delayMicroseconds ( 10 );      // commands & data writes need > 37us to complete
    00110 #else
    00111         delayMicroseconds ( 37 );      // commands & data writes need > 37us to complete
    00112 #endif
    00113 }
    00114
    00115 //
    00116 // setBacklight
    00117 void LiquidCrystal_SR2W::setBacklight ( uint8_t value )
    00118 {
    00119         // Check for polarity to configure mask accordingly
    00120         // ----------------------------------------------------------
    00121         if  ( ((_blPolarity == POSITIVE) && (value > 0)) ||
    00122         ((_blPolarity == NEGATIVE ) && ( value == 0 )) )
    00123         {
    00124                 _blMask = SR2W_BL_MASK;
    00125         }
    00126         else
    00127         {
    00128                 _blMask = 0;
    00129         }
    00130
    00131         // send dummy data of blMask to set BL pin
    00132         // Note: loadSR() will strobe the data line trying to pulse EN
    00133         // but E will not strobe because the EN output bit is not set.
    00134         loadSR(_blMask);
    00135 }

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines