MHVLib  20111011
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_Display_HD44780_Shift_Register.cpp
Go to the documentation of this file.
00001 /* Copyright (c) 2011, Make, Hack, Void Inc
00002  * All rights reserved.
00003  *
00004  * Contributed by Armel
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *  * Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  *  * Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *  * Neither the name of the Make, Hack, Void nor the
00014  *    names of its contributors may be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include <util/delay.h>
00030 
00031 #include <MHV_Display_HD44780_Shift_Register.h>
00032 
00033 #define MHV_SHIFT_ORDER_MSB
00034 #define MHV_SHIFT_WRITECLOCK NULL,_clockOut,NULL,_clockPin,-1
00035 #define MHV_SHIFT_WRITEDATA NULL,_dataOut,NULL,_dataPin,-1
00036 #include <MHV_Shifter.h>
00037 
00038 #define HD44780_TSU1    (60 * 1000000 / F_CPU / 3 + 1)
00039 #define HD44780_TW              (450 * 1000000 / F_CPU / 3 + 1)
00040 
00041 
00064 MHV_Display_HD44780_Shift_Register::MHV_Display_HD44780_Shift_Register(
00065                 volatile uint8_t *dataDir, volatile uint8_t *dataOut, volatile uint8_t *dataIn,
00066                 uint8_t dataPin, int8_t dataPinchangeInterrupt,
00067                 volatile uint8_t *enableDir, volatile uint8_t *enableOut, volatile uint8_t *enableIn,
00068                 uint8_t enablePin, int8_t enablePinchangeInterrupt,
00069                 volatile uint8_t *clockDir, volatile uint8_t *clockOut, volatile uint8_t *clockIn,
00070                 uint8_t clockPin, int8_t clockPinchangeInterrupt, uint8_t colCount,
00071                 uint16_t rowCount, MHV_RingBuffer *txBuffers) :
00072         MHV_Display_HD44780(colCount, rowCount, txBuffers) {
00073         _dataOut = dataOut;
00074         _dataPin = dataPin;
00075         mhv_setOutput(dataDir, dataOut, dataIn, dataPin, -1);
00076 
00077         _enableOut = enableOut;
00078         _enablePin = enablePin;
00079         mhv_setOutput(enableDir, enableOut, enableIn, enablePin, -1);
00080 
00081         _clockOut = clockOut;
00082         _clockPin = clockPin;
00083         mhv_setOutput(clockDir, clockOut, clockIn, clockPin, -1);
00084 
00085 }
00086 
00092 void MHV_Display_HD44780_Shift_Register::pushBits(uint8_t byte, bool rs) {
00093 // setup RS
00094         byte |= (rs ? 0x01 : 0x00);
00095 
00096 // Load the byte into the shift register
00097         MHV_SHIFTOUT_BYTE(byte);
00098 
00099 // strobe Enable pin
00100         _delay_loop_1(HD44780_TSU1);
00101         mhv_pinOn(0, _enableOut, 0, _enablePin, -1);
00102         _delay_loop_1(HD44780_TW);
00103         mhv_pinOff(0, _enableOut, 0, _enablePin, -1);
00104         _delay_loop_1(HD44780_TW);
00105 }
00106 
00112 void MHV_Display_HD44780_Shift_Register::writeByte(uint8_t byte, bool rs) {
00113         if (_byteMode) {
00114 // 8 bits interface mode
00115                 pushBits(byte, rs);
00116         } else {
00117 // 4 bits interface mode
00118 // Write high order nibble
00119                 pushBits(byte & 0xF0, rs);
00120 // Write low order nibble
00121                 pushBits(byte << 4, rs);
00122         }
00123 }
00124 
00129 uint8_t MHV_Display_HD44780_Shift_Register::readByte(bool rs) {
00130         return 0;
00131 }
00132 
00137 bool MHV_Display_HD44780_Shift_Register::isBusy() {
00138         return false;
00139 }
00140 
00144 void MHV_Display_HD44780_Shift_Register::delay(MHV_HD44780_COMMAND command) {
00145         switch (command) {
00146         case MHV_44780_CMD_CLEAR:
00147         case MHV_44780_CMD_RETURN_HOME:
00148                 _delay_ms(2);
00149                 break;
00150         case MHV_44780_CMD_SET_ENTRY_MODE:
00151         case MHV_44780_CMD_SET_DISPLAY_MODE:
00152         case MHV_44780_CMD_SET_CURSOR_MODE:
00153         case MHV_44780_CMD_SET_CG_ADDR:
00154         case MHV_44780_CMD_SET_DD_ADDR:
00155         case MHV_44780_WRITE_CHAR:
00156         case MHV_44780_CMD_SET_FUNCTION:
00157                 _delay_us(39);
00158                 break;
00159         }
00160 }
00161 
00171 void MHV_Display_HD44780_Shift_Register::init(bool multiLine, bool bigFont, bool cursorOn, bool cursorBlink,
00172                                 bool left2right, bool scroll) {
00173         MHV_Display_HD44780::init(false, multiLine, bigFont, cursorOn, cursorBlink, left2right, scroll);
00174 }
00175