// Copyright (c) 2010, Christopher James Huff // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of the copyright holder nor the names of contributors // may be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //************************************************************************************************ // // Driver for 1-3 HD44780/KS0066U-compatible character LCDs through a 74595 shift register. // Low resource usage is a priority: if asynchronous updates are disabled, only one byte of SRAM // is used. The state machine for asynchronous updates uses only 3 more bytes. TODO: if cursor // control is enabled, an additional byte is used. No timers are used. // // Up to 3 identical single-controller LCDs may be driven, or a 4x40 dual-controller // display. Alternatively, a single 4x40 display or 2 smaller displays can be driven // with the third enable line used for backlight control. // // Non-identical LCDs also may be used, but CLCD_MoveTo() and CLCD_Update() will only // work properly for one size. If a 4x40 display is used, these functions will automatically // select its controllers. For a third display, the address must be set manually, and the LCD // written to with CLCD_WriteByte() and CLCD_WriteString(). // // LCD_LINES may be 1, 2, or 4. // 4 line displays with 20 characters or fewer per line are actually 2 line // displays with each line split in half at 0x14. // 4x40 displays are actually two 2x40 displays with separate controllers. Such displays // may be configured as two separate LCDs instead. // // The controller setup only matters for CLCD_MoveTo(), which automatically selects // LCD 1 or LCD 2 for 4x40 displays, and CLCD_Update(), which updates both controllers // on such displays. The rest of the API simply uses whatever controller or controllers // are enabled. // // DDRAM memory map: // 1 line and 2 line displays: // 0x00 to 0x27 for first line // 0x40 to 0x67 for second line if it exists // // 4x16, 4x20 displays: // 0x00 to 0x13 for first line // 0x40 to 0x53 for second line // 0x14 to 0x27 for third line // 0x54 to 0x67 for fourth line // // 4x40 displays: // 0x00 to 0x27 on controller 1 for first line // 0x40 to 0x67 on controller 1 for second line // 0x00 to 0x27 on controller 2 for third line // 0x40 to 0x67 on controller 2 for fourth line // // Custom characters: // 5x7: // Custom character codes start at 0x00 and go to 0x07, addresses are // charcode << 3. // Characters are 8 bytes: 7 lines and cursor position(?). Lowest 5 bits are displayed. // // More information: // http://www.electronic-engineering.ch/microchip/datasheets/lcd/lcd_data_sheets.html // http://ouwehand.net/~peter/lcd/lcd0.shtml // //************************************************************************************************ #ifndef SHIFTLCD_H #define SHIFTLCD_H #include #include "common.h" // Enable asynchronous updates to eliminate long LCD-refreshing delays, // at the expense of code size, SRAM usage, and display speed. #ifndef CLCD_ASYNC #define CLCD_ASYNC 1 #endif // If set, one shift register bit is used for LCD backlight control instead of a third controller #ifndef CLCD_AUX_CONTROL #define CLCD_AUX_CONTROL 1 #endif #ifndef CLCD_LINE_WIDTH //#define CLCD_LINE_WIDTH (16) //#define CLCD_LINE_WIDTH (20) #define CLCD_LINE_WIDTH (40) #endif #ifndef CLCD_LINES //#define CLCD_LINES (2) //#define CLCD_LINES (4) #define CLCD_LINES (4) #endif #define CLCD_DELAY() _delay_us(44) #define CLCD_LONGDELAY() _delay_ms(2) // SPI chip select configuration //#define CLCD_SPI_CFG() SPCR = (1<