AVRly - AVR Development Resources
|
Driver for the HD44780 based 16x2 liquid crystal display. More...
Go to the source code of this file.
Macros | |
#define | CLEAR_DISPLAY 0b00000001U |
#define | CURSOR_HOME 0b00000010U |
#define | ENTRY_MODE_SET 0b00000100U |
#define | ON_OFF_CTRL 0b00001000U |
#define | CURSOR_DISPLAY_SHIFT 0b00010000U |
#define | FUNCTION_SET 0b00100000U |
#define | DATA_LENGTH_BIT 4U |
#define | DISPLAY_LINES_BIT 3U |
#define | FONT_SIZE_BIT 2U |
#define | MOVE_DIRECTION_BIT 1U |
#define | DISPLAY_SHIFT_BIT 0U |
#define | CURSOR_ENABLE_BIT 1U |
#define | BLINK_ENABLE_BIT 0U |
#define | ON_OFF_CTRL_BIT 2U |
#define | RIGHT_LEFT_BIT 2U |
#define | SHIFT_OR_CURSOR_BIT 3U |
#define | BUSY_FLAG_BIT 7U |
#define | DISPLAY_ON true |
#define | DISPLAY_OFF false |
#define | POWER_RAMP_DELAY_MS 100 |
#define | SHORT_INSTR_DELAY_MS 2 |
#define | LONG_INSTR_DELAY_MS 10 |
#define | SCROLL_DELAY_MS 400 |
#define | ENABLE_DELAY_US 2 |
Functions | |
void | lcd_command (uint8_t data) |
void | lcd_char (char character) |
void | pulse_enable (void) |
void | init_lcd (lcd_config_t *p_config) |
Initialisation routine (run once at startup). More... | |
void | lcd_display_off (void) |
Turn display off (config settings are retained). More... | |
void | lcd_display_on (void) |
Turn display on. More... | |
void | lcd_print_string (const char *str) |
Prints a string of characters to the display. More... | |
void | lcd_print_integer (int16_t number) |
Prints an integer variable. More... | |
void | lcd_set_cursor (uint8_t column, uint8_t row) |
Sets cursor location using x and y coordinates. More... | |
void | lcd_fast_clear (void) |
Writes space characters to all 32 sections of display (or 16 if in 1 line mode). More... | |
void | lcd_reconfigure (void) |
Edits config settings on the display (lcd_config_t members must be changed first). More... | |
void | lcd_return_home (void) |
Sets DDRAM address 0 in address counter. More... | |
void | lcd_shift_cursor_left (uint8_t distance) |
Moves cursor left without changing DDRAM contents. More... | |
void | lcd_shift_cursor_right (uint8_t distance) |
Moves cursor right without changing DDRAM contents. More... | |
void | lcd_shift_display_left (uint8_t distance, bool delay) |
Shifts display left without changing DDRAM contents. More... | |
void | lcd_shift_display_right (uint8_t distance, bool delay) |
Shifts display right without changing DDRAM contents. More... | |
Driver for the HD44780 based 16x2 liquid crystal display.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file provides the basic low-level functionality for the ubiquitous 16x2 display. Please note that it uses long blocking waits in the initialisation routine (100ms), and short blockign waits in other utility functions (2uS - 2mS). This was done to simplify the code as the busy flag read introduced pitfalls. This driver currently only allows for a single display to be used, but this might be improved on at a later date.
NOTE: Values used in bitwise operations MUST be of unsigned type.
This driver was written using the datasheet for the HITACHI HD44780U LCD driver chip, which can be found here:
Definition in file hd44780_lcd.c.
#define CLEAR_DISPLAY 0b00000001U |
Definition at line 64 of file hd44780_lcd.c.
#define CURSOR_HOME 0b00000010U |
Definition at line 65 of file hd44780_lcd.c.
#define ENTRY_MODE_SET 0b00000100U |
Definition at line 66 of file hd44780_lcd.c.
#define ON_OFF_CTRL 0b00001000U |
Definition at line 67 of file hd44780_lcd.c.
#define CURSOR_DISPLAY_SHIFT 0b00010000U |
Definition at line 68 of file hd44780_lcd.c.
#define FUNCTION_SET 0b00100000U |
Definition at line 69 of file hd44780_lcd.c.
#define DATA_LENGTH_BIT 4U |
Definition at line 72 of file hd44780_lcd.c.
#define DISPLAY_LINES_BIT 3U |
Definition at line 73 of file hd44780_lcd.c.
#define FONT_SIZE_BIT 2U |
Definition at line 74 of file hd44780_lcd.c.
#define MOVE_DIRECTION_BIT 1U |
Definition at line 75 of file hd44780_lcd.c.
#define DISPLAY_SHIFT_BIT 0U |
Definition at line 76 of file hd44780_lcd.c.
#define CURSOR_ENABLE_BIT 1U |
Definition at line 77 of file hd44780_lcd.c.
#define BLINK_ENABLE_BIT 0U |
Definition at line 78 of file hd44780_lcd.c.
#define ON_OFF_CTRL_BIT 2U |
Definition at line 79 of file hd44780_lcd.c.
#define RIGHT_LEFT_BIT 2U |
Definition at line 80 of file hd44780_lcd.c.
#define SHIFT_OR_CURSOR_BIT 3U |
Definition at line 81 of file hd44780_lcd.c.
#define BUSY_FLAG_BIT 7U |
Definition at line 82 of file hd44780_lcd.c.
#define DISPLAY_ON true |
Definition at line 85 of file hd44780_lcd.c.
#define DISPLAY_OFF false |
Definition at line 86 of file hd44780_lcd.c.
#define POWER_RAMP_DELAY_MS 100 |
Definition at line 89 of file hd44780_lcd.c.
#define SHORT_INSTR_DELAY_MS 2 |
Definition at line 90 of file hd44780_lcd.c.
#define LONG_INSTR_DELAY_MS 10 |
Definition at line 91 of file hd44780_lcd.c.
#define SCROLL_DELAY_MS 400 |
Definition at line 92 of file hd44780_lcd.c.
#define ENABLE_DELAY_US 2 |
Definition at line 93 of file hd44780_lcd.c.
void lcd_command | ( | uint8_t | data | ) |
Definition at line 395 of file hd44780_lcd.c.
void lcd_char | ( | char | character | ) |
Definition at line 427 of file hd44780_lcd.c.
void pulse_enable | ( | void | ) |
Definition at line 459 of file hd44780_lcd.c.
void init_lcd | ( | lcd_config_t * | p_config | ) |
Initialisation routine (run once at startup).
This function is to be called immediately after powerup of the display module. Instantiate the lcd_config_t object first then pass it's address into init_lcd() before using any other lcd functions.
p_config | is a pointer to the lcd_config_t object. |
Definition at line 104 of file hd44780_lcd.c.
void lcd_display_off | ( | void | ) |
Turn display off (config settings are retained).
Side effect: cursor_enable and blink_enable variable states are written to the display during this command, so if they have been changed but lcd_reconfigure() was not called afterwards, this function will update those config bits on the display.
Definition at line 177 of file hd44780_lcd.c.
void lcd_display_on | ( | void | ) |
Turn display on.
Side effect: cursor_enable and blink_enable variable states are written to the display during this command, so if they have been changed but lcd_reconfigure() was not called afterwards, this function will update those config bits on the display.
Definition at line 190 of file hd44780_lcd.c.
void lcd_print_string | ( | const char * | str | ) |
Prints a string of characters to the display.
This function takes a string literal (constant) as it's parameter. Be sure to enclose text passed in with "" quotation marks. eg: "Hello, World!".
str | is a string literal. |
Definition at line 204 of file hd44780_lcd.c.
void lcd_print_integer | ( | int16_t | number | ) |
Prints an integer variable.
This function prints a signed integer value to the display, values from -32768 to 32767 are acceptable.
number | is a signed, fixed width integer. |
Definition at line 216 of file hd44780_lcd.c.
void lcd_set_cursor | ( | uint8_t | column, |
uint8_t | row | ||
) |
Sets cursor location using x and y coordinates.
Column is 0 for top row, 1 for bottom row (in 2 row mode). Row can be from 0 - 15, values outside of this range will be written to non visible spaces on the display.
column | is the x coordinate. |
row | is the y coordinate. |
Definition at line 246 of file hd44780_lcd.c.
void lcd_fast_clear | ( | void | ) |
Writes space characters to all 32 sections of display (or 16 if in 1 line mode).
This is much faster than the clear_display command, as that works by writing a space character to every single section of the display, even all the non-visible ones.
Definition at line 269 of file hd44780_lcd.c.
void lcd_reconfigure | ( | void | ) |
Edits config settings on the display (lcd_config_t members must be changed first).
data_length, display_lines, and font_size cannot be changed after init_lcd() is called.
Definition at line 291 of file hd44780_lcd.c.
void lcd_return_home | ( | void | ) |
Sets DDRAM address 0 in address counter.
Also returns display from being shifted to original position. DDRAM contents remain unchanged.
Definition at line 308 of file hd44780_lcd.c.
void lcd_shift_cursor_left | ( | uint8_t | distance | ) |
Moves cursor left without changing DDRAM contents.
distance | is used to specify how many spaces to move. |
Definition at line 318 of file hd44780_lcd.c.
void lcd_shift_cursor_right | ( | uint8_t | distance | ) |
Moves cursor right without changing DDRAM contents.
distance | is used to specify how many spaces to move. |
Definition at line 333 of file hd44780_lcd.c.
void lcd_shift_display_left | ( | uint8_t | distance, |
bool | delay | ||
) |
Shifts display left without changing DDRAM contents.
Optional delay between shifts for scrolling effect.
distance | is used to specify how many spaces to move. |
delay | - pass in true for scrolling effect, false for no delay. |
Definition at line 349 of file hd44780_lcd.c.
void lcd_shift_display_right | ( | uint8_t | distance, |
bool | delay | ||
) |
Shifts display right without changing DDRAM contents.
Optional delay between shifts for scrolling effect.
distance | is used to specify how many spaces to move. |
delay | - pass in true for scrolling effect, false for no delay. |
Definition at line 369 of file hd44780_lcd.c.