AVRly - AVR Development Resources
main.c File Reference

Example main routine demonstrating the HD44780 based 16x2 liquid crystal display. More...

#include <util/delay.h>
#include <avr/power.h>
#include "hd44780_lcd.h"

Go to the source code of this file.

Macros

#define MESSAGE_DELAY   2000
 
#define ANIMATION_DELAY   300
 

Functions

int main ()
 

Variables

lcd_config_t lcd_config
 
uint8_t test_number = 34
 

Detailed Description

Example main routine demonstrating 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.

Author
Jason Duffy
Date
1st March 2022

Definition in file main.c.

Macro Definition Documentation

◆ MESSAGE_DELAY

#define MESSAGE_DELAY   2000

Definition at line 38 of file main.c.

◆ ANIMATION_DELAY

#define ANIMATION_DELAY   300

Definition at line 39 of file main.c.

Function Documentation

◆ main()

int main ( )

Definition at line 56 of file main.c.

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
bool cursor_enable
true = enabled, false = disabled.
Definition: hd44780_lcd.h:63
bool blink_enable
true = enabled, false = disabled.
Definition: hd44780_lcd.h:64

Variable Documentation

◆ lcd_config

lcd_config_t lcd_config
Initial value:
=
{
.eight_bit_mode = false,
.two_line_display = true,
.five_by_ten_font = false,
.increment_counter = true,
.display_shift = false,
.cursor_enable = false,
.blink_enable = false,
}

Definition at line 43 of file main.c.

◆ test_number

uint8_t test_number = 34

Definition at line 54 of file main.c.