AVRly - AVR Development Resources
main.c
Go to the documentation of this file.
1/******************************************************************************
2 @copyright Copyright © 2022 by Jason Duffy.
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21******************************************************************************/
22
23/**
24 * @file main.c
25 * @ingroup hd44780_lcd
26 * @author Jason Duffy
27 * @date 1st March 2022
28 * @brief Example main routine demonstrating the HD44780 based 16x2 liquid
29 * crystal display.
30 * @bug No known bugs.
31 */
32
33#include <util/delay.h>
34#include <avr/power.h>
35
36#include "hd44780_lcd.h"
37
38#define MESSAGE_DELAY 2000
39#define ANIMATION_DELAY 300
40
41
42// Lcd configuration object
43lcd_config_t lcd_config =
44{
45 .eight_bit_mode = false, // true = 8 bit mode, false = 4 bit mode
46 .two_line_display = true, // true = 2 lines, false = 1 line
47 .five_by_ten_font = false, // true = 5x10 dots, false = 5x8 dots
48 .increment_counter = true, // true = increment, false = decrement
49 .display_shift = false, // true = display shift, false = cursor shift
50 .cursor_enable = false, // true = enabled, false = disabled
51 .blink_enable = false, // true = enabled, false = disabled
52};
53
54uint8_t test_number = 34;
55
56int main()
57{
58 // Setup
59 init_lcd(&lcd_config);
60
61 // Loop forever
62 for(;;)
63 {
66 lcd_print_string(" HD44780 LCD ");
67 lcd_set_cursor(0,1);
68 lcd_print_string(" example. ");
69 _delay_ms(MESSAGE_DELAY);
70
73
74 lcd_config.cursor_enable = true;
76 lcd_print_string("Cursor can be:");
77 lcd_set_cursor(0,1);
78 lcd_print_string("enabled:");
79 _delay_ms(MESSAGE_DELAY);
80
81 lcd_set_cursor(0,1);
82 lcd_print_string("shifted left");
83 _delay_ms(ANIMATION_DELAY);
84
85 for (uint8_t count = 0; count < 12; ++count)
86 {
88 _delay_ms(ANIMATION_DELAY);
89 }
90 _delay_ms(MESSAGE_DELAY);
91
92 lcd_set_cursor(0,1);
93 lcd_print_string("shifted right ");
94 lcd_set_cursor(0,1);
95 _delay_ms(ANIMATION_DELAY);
96
97 for (uint8_t count = 0; count < 12; ++count)
98 {
100 _delay_ms(ANIMATION_DELAY);
101 }
102 _delay_ms(MESSAGE_DELAY);
103
104 lcd_config.blink_enable = true;
106 lcd_set_cursor(0,1);
107 lcd_print_string("with blink: ");
108 lcd_set_cursor(11,1);
109 _delay_ms(MESSAGE_DELAY);
110
111 lcd_config.blink_enable = false;
112 lcd_config.cursor_enable = false;
114 lcd_set_cursor(0,1);
115 lcd_print_string(" disabled:");
116 _delay_ms(MESSAGE_DELAY);
117
119 lcd_set_cursor(0,0);
120 lcd_print_string("Print integer:");
121 lcd_set_cursor(0,1);
122 lcd_print_integer(test_number);
123 _delay_ms(MESSAGE_DELAY);
124
126 lcd_set_cursor(0,0);
127 lcd_print_string("Display");
128 lcd_set_cursor(0,1);
129 lcd_print_string("<shift>");
131 lcd_shift_display_left(9, true);
132 _delay_ms(MESSAGE_DELAY);
133 }
134}
void lcd_shift_cursor_left(uint8_t distance)
Moves cursor left without changing DDRAM contents.
Definition: hd44780_lcd.c:319
void lcd_print_string(const char *str)
Prints a string of characters to the display.
Definition: hd44780_lcd.c:205
void lcd_print_integer(int16_t number)
Prints an integer variable.
Definition: hd44780_lcd.c:217
void lcd_shift_display_right(uint8_t distance, bool delay)
Shifts display right without changing DDRAM contents.
Definition: hd44780_lcd.c:370
void init_lcd(lcd_config_t *p_config)
Initialisation routine (run once at startup).
Definition: hd44780_lcd.c:105
void lcd_fast_clear(void)
Writes space characters to all 32 sections of display (or 16 if in 1 line mode).
Definition: hd44780_lcd.c:270
void lcd_shift_display_left(uint8_t distance, bool delay)
Shifts display left without changing DDRAM contents.
Definition: hd44780_lcd.c:350
void lcd_reconfigure(void)
Edits config settings on the display (lcd_config_t members must be changed first).
Definition: hd44780_lcd.c:292
void lcd_return_home(void)
Sets DDRAM address 0 in address counter.
Definition: hd44780_lcd.c:309
void lcd_shift_cursor_right(uint8_t distance)
Moves cursor right without changing DDRAM contents.
Definition: hd44780_lcd.c:334
void lcd_set_cursor(uint8_t column, uint8_t row)
Sets cursor location using x and y coordinates.
Definition: hd44780_lcd.c:247
Driver for the HD44780 based 16x2 liquid crystal display.
int main()
Main routine to be executed on the MCU.
Definition: main.c:45
Configuration struct, to be instantiated and values assigned before passing it's address into and cal...
Definition: hd44780_lcd.h:57
bool cursor_enable
true = enabled, false = disabled.
Definition: hd44780_lcd.h:63
bool eight_bit_mode
true = 8 bit mode, false = 4 bit mode.
Definition: hd44780_lcd.h:58
bool blink_enable
true = enabled, false = disabled.
Definition: hd44780_lcd.h:64