AVRly - AVR Development Resources
|
Driver for the HD44780 based 16x2 liquid crystal display. More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Classes | |
struct | lcd_config_t |
Configuration struct, to be instantiated and values assigned before passing it's address into and calling lcd_init(). More... | |
Functions | |
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 blocking 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.
This driver was written using the datasheet for the HITACHI HD44780U LCD driver chip, which can be found at the link below.
Definition in file hd44780_lcd.h.
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 105 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 178 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 191 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 205 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 217 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 247 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 270 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 292 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 309 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 319 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 334 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 350 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 370 of file hd44780_lcd.c.