|
/**
|
|
* @mainpage
|
|
* @section Project
|
|
* <b> LCD functions based on the HD4470 / KS0066u chips </b>
|
|
* @author Patrice Nadeau
|
|
* @n email : patricen@telwarwick.net
|
|
* @n www : http://nadeaup.homeip.net:8080/
|
|
* @section Specifications
|
|
* @subsection Language
|
|
* - C
|
|
* @subsection Target
|
|
* - ATmega48
|
|
* - ATmega88
|
|
* - ATmega168
|
|
* - ATmega328
|
|
* @subsection Tested
|
|
* - ATmega168
|
|
* @section Dependency
|
|
* - utils.h
|
|
* @section information More informations
|
|
* Datasheet Datasheet Newhaven Display (NHD-0216BZ-RN-YBW) March 6, 2008
|
|
@section Disclaimer
|
|
Disclaimer
|
|
Copyright (c) 2010, 2011 Patrice Nadeau
|
|
@n 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 Patrice Nadeau nor the
|
|
names of its 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 Patrice Nadeau 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.
|
|
*/
|
|
|
|
#ifndef LCD_H_
|
|
#define LCD_H_
|
|
|
|
|
|
/**
|
|
* @file lcd.h
|
|
* @brief LCD on AVR
|
|
* @details LCD functions based on the HD4470 / KS0066u chips (Datasheet Newhaven Display (NHD-0216BZ-RN-YBW) March 6, 2008)
|
|
* @n It take for granted that the Data pins on the LCD and on the AVR are in the same order and all on the same port
|
|
* @author Patrice Nadeau
|
|
* @note For ATmega48PA/88PA/168PA/328P
|
|
* @todo utils.h, delay.h should be replaced
|
|
*/
|
|
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#include <stdbool.h>
|
|
#include "utils/utils.h"
|
|
|
|
/**
|
|
* @name Default #define forATmega48PA/88PA/168PA/328P, can be overrided
|
|
* - lcd_RS_PORT B
|
|
* - lcd_RS_PIN 0
|
|
* - lcd_RW_PORT B
|
|
* - lcd_RW_PIN 1
|
|
* - lcd_E_PORT D
|
|
* - lcd_E_PIN 2
|
|
* - lcd_DATA_PORT D (PIN 7-4 for 4 bits mode)
|
|
* - lcd_DATA_LENGHT 4
|
|
* @{
|
|
*/
|
|
#if defined (__AVR_ATmega48__) || defined (__AVR_ATmega48P__) || \
|
|
defined (__AVR_ATmega88P__) || defined (__AVR_ATmega88__) || \
|
|
defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__) || \
|
|
defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
|
|
/* Register Select port */
|
|
#ifndef lcd_RS_PORT
|
|
#define lcd_RS_PORT B
|
|
#endif
|
|
/* Register Select pin */
|
|
#ifndef lcd_RS_PIN
|
|
#define lcd_RS_PIN 0
|
|
#endif
|
|
/* Read/Write port */
|
|
#ifndef lcd_RW_PORT
|
|
#define lcd_RW_PORT B
|
|
#endif
|
|
/* Read/Write pin */
|
|
#ifndef lcd_RW_PIN
|
|
#define lcd_RW_PIN 1
|
|
#endif
|
|
/* Enable port */
|
|
#ifndef lcd_E_PORT
|
|
#define lcd_E_PORT D
|
|
#endif
|
|
/* Enable pin */
|
|
#ifndef lcd_E_PIN
|
|
#define lcd_E_PIN 2
|
|
#endif
|
|
/* Pinx uC -> DBx LCD, high nibble for 4 bit mode */
|
|
#ifndef lcd_DATA_PORT
|
|
#define lcd_DATA_PORT D
|
|
#endif
|
|
/* 4 or 8 bits mode (high nibble 4 mode) */
|
|
#ifndef lcd_DATA_LENGHT
|
|
#define lcd_DATA_LENGHT 4
|
|
#endif
|
|
#else
|
|
/* stop the compiler */
|
|
#error "lcd.h not supported on this AVR !"
|
|
#endif
|
|
|
|
|
|
/**
|
|
* @name For the dusplay functions
|
|
* @{
|
|
*/
|
|
/** @brief 1 line */
|
|
#define lcd_LINES_1 1
|
|
/** @brief 2 lines */
|
|
#define lcd_LINES_2 2
|
|
/** @brief Not implemented yet */
|
|
#define lcd_LINES_4 4
|
|
/** @brief 5 x 8 font */
|
|
#define lcd_FONT_8 8
|
|
/** @brief 8 x 11 */
|
|
#define lcd_FONT_11 11
|
|
/** @brief Shift the whole display */
|
|
#define lcd_SHIFT_DISPLAY_OFF 0
|
|
/** @brief Direction to shift the display if enable */
|
|
#define lcd_SHIFT_DISPLAY_RIGHTLEFT 0
|
|
#define lcd_DISPLAY_OFF 0
|
|
/** @brief Use @a !lcd_CURSOR_OFF to enable */
|
|
#define lcd_CURSOR_OFF 0
|
|
/** @brief Use @a !lcd_CURSOR_BLINK_OFF to enable */
|
|
#define lcd_CURSOR_BLINK_OFF 0
|
|
/** @} */
|
|
|
|
|
|
/**
|
|
* @brief Initialize the data and command register for output
|
|
* @return
|
|
* @note Maybe should provide software reset
|
|
*/
|
|
void lcd_InitPort(void);
|
|
|
|
|
|
/**
|
|
* @brief Set the number of @a lines and @a font
|
|
* @param[in] line Number of lines
|
|
* - lcd_LINES_x
|
|
* @param[in] font Font to use
|
|
* - lcd_FONT_x
|
|
*/
|
|
void lcd_FunctionSet(uint8_t line, uint8_t font);
|
|
|
|
/**
|
|
* @brief Clear the display and set DDRA to 20H and DDRAM to 00h
|
|
*/
|
|
void lcd_ClearDisplay(void);
|
|
|
|
/**
|
|
* @brief lcd_EnterMode
|
|
* @param[in] rightleft Direction to shift the display
|
|
* - lcd_SHIFT_DISPLAY_RIGHTLEFT
|
|
* - !lcd_SHIFT_DISPLAY_RIGHTLEFT
|
|
* @param[in] shift Show the dispplay
|
|
* - lcd_SHIFT_DISPLAY_OFF
|
|
* - !lcd_SHIFT_DISPLAY_OFF
|
|
*/
|
|
void lcd_EnterMode(uint8_t rightleft, uint8_t shift);
|
|
|
|
/**
|
|
* @brief Turn on/off the display, cursor and blink of the LCD
|
|
* @param[in] display Show the display
|
|
* - lcd_DISPLAY_OFF
|
|
* - !lcd_DISPLAY_OFF
|
|
* @param[in] cursor Show the cursor
|
|
* - lcd_CURSOR_OFF
|
|
* - !lcd_CURSOR_OFF
|
|
* @param[in] blink Blink the cursor
|
|
* - lcd_CURSOR_BLINK_OFF
|
|
* - !lcd_CURSOR_BLINK_OFF
|
|
*/
|
|
void lcd_DisplayOnOff(uint8_t display, uint8_t cursor, uint8_t blink);
|
|
|
|
/**
|
|
* @brief Place the cursor at @a position in display memory
|
|
* @param[in] position Position in memory
|
|
* @note First line 00H to 27H, second line 40H to 67H
|
|
*/
|
|
void lcd_DDRAM(uint8_t position);
|
|
|
|
/**
|
|
* @brief Display @a character on the lcd
|
|
* @param[in] character Character to display
|
|
* @note Works for the first 127 ASCII codes
|
|
*/
|
|
void lcd_WriteData (uint8_t character);
|
|
|
|
/**
|
|
* @brief Set the GCRAM address
|
|
* @param[in] address (last 6 bits)
|
|
*/
|
|
void lcd_CGRAM(uint8_t address);
|
|
|
|
/**
|
|
* @brief Select which display or cursor move and to the right or left
|
|
* @param[in] wich Cursor or dislplay
|
|
* @param[in] direction Direction to shift
|
|
* @return Error code
|
|
* @retval 0 successful
|
|
* @retval 1 wrong cursor/display option
|
|
* @retval 2 wrong direction
|
|
*/
|
|
uint8_t lcd_Shift (uint8_t wich, uint8_t direction);
|
|
|
|
/**
|
|
* @brief Write a string to the LCD
|
|
* @param[in] *string Pointer to a string
|
|
* @note Do not check the length
|
|
*/
|
|
void lcd_WriteString (char *string);
|
|
|
|
/**
|
|
* @brief Return cursor at 00H, return display original status if shifted
|
|
* @note Does not erase DDRAM
|
|
* @note Unshift if shifted
|
|
*/
|
|
void lcd_ReturnHome(void);
|
|
|
|
/**
|
|
* @brief Return the busy flag and the address counter
|
|
* @return Busy flag, address counter
|
|
* - bit @b XXXXX is busy flag () 1 busy, 0 rdy to accept command
|
|
* - bit 6-0 is the address counter
|
|
* @bug Can't work, _Send alway return 0
|
|
* @bug need to be modified for 4 bits
|
|
*/
|
|
uint8_t lcd_BusyFlag(void);
|
|
|
|
/**
|
|
* @brief Read the 8 bit data from position set earlier by lcdCGRAM or lcdDDRAM.
|
|
* @return uint8_t Data
|
|
* @note Address counter will also be affected (like a write)
|
|
* @bug Can't work, _Send alway return 0
|
|
*/
|
|
uint8_t lcd_ReadData(void);
|
|
|
|
/**
|
|
* @brief Clear every character on line and place cursor at beginning of line
|
|
* @param[in] line The line numer to clear
|
|
* - lcd_LINE_x
|
|
*/
|
|
void lcd_ClearLine(uint8_t line);
|
|
|
|
/**
|
|
* @brief Display the binary version of a byte.
|
|
* @param[in] data Byte to display
|
|
* @note Mostly for debugging
|
|
*/
|
|
void lcd_Byte(uint8_t data);
|
|
|
|
/**
|
|
* @brief Display the binary version of 16 bits.
|
|
* @param[in] data Double byte to display
|
|
* @note Mostly for debugging
|
|
*/
|
|
void lcd_DoubleByte(uint16_t data);
|
|
|
|
#endif /* LCD_H_ */
|
|
|
|
/* Change log
|
|
* 2009-07-19 Patrice Nadeau
|
|
* Initial release
|
|
* 2010-09-18 by Patrice Nadeau
|
|
* Renamed the #define and functions to standardize the names
|
|
* Moved the define for the port from the .c file
|
|
* lcd_FunctionSet now return nothing
|
|
* lcd_EnterMode now return nothing and is simplified
|
|
* 2010-09-30 Patrice Nadeau
|
|
* changed lcd_DATA_PIN for lcd_COMMAND_PIN
|
|
* 2010-10-02 Patrice Nadeau
|
|
* Added util.h to use only the letter of the port for DDRx, PORTx, PINx
|
|
* Changed the pins and port for the command pins (E, RW, RS) see the above
|
|
section for the I/O define.
|
|
* Added compiler directives for supported AVR
|
|
* 2011-01-12 Patrice Nadeau
|
|
* Modified comments for Doxygen
|
|
* 2011-02-20 Patrice Nadeau
|
|
* Added more Doxygen comments
|
|
*/
|