-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd_test.c
121 lines (104 loc) · 3.9 KB
/
lcd_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Test/demo for the lcd.h interface.
//
// NOTE: all the testing I've done has been done with the DFRobot DFR0009
// LCD Shield for Arduino. This is a very convenient LCD to connect and
// also features some pushbuttons (not used in this module).
//
// This test program requires an Hitachi HD44780 LCD display to be connected
// using the pin connections defined in the Makefile, and a couple of other
// LCD pins to be connected in particular ways to make the LCD usable.
//
// Unless something has changed in the Makefile, the LCD pin connections
// should be:
//
// * LCD RS pin to digital pin 8
// * LCD Enable pin to digital pin 9
// * LCD D4 pin to digital pin 11
// * LCD D5 pin to digital pin 12
// * LCD D6 pin to digital pin 13
// * LCD D7 pin to digital pin 14
// * LCD R/W pin to ground
// * 10K potentiometer:
// * Ends to +5V and ground
// * Wiper to LCD VO pin (pin 3).
//
// Note that the results just sort of print things on top of each other.
// The final screen after the tests are done doesn't look particularly
// organized. You have to match what you see going on with this test code
// to verify correct LCD operation.
//
// This example code is in the public domain. It was created by
// David A. Mellis. It was subsequently modified by Limor Fried
// (http://www.ladyada.net), then by Tom Igoe, and finally by Britton Kerin.
#include <avr/pgmspace.h>
#include <string.h>
#include <util/delay.h>
// include the library code:
#include "lcd.h"
int
main (void)
{
lcd_init ();
// Print a message to the LCD.
lcd_write_string ("hello, world!");
double magic_number = 42.65; // Something to output.
double time_per_test_ms = 1000.0; // Time we spend on most tests, in ms.
// Set the cursor to column 0, line 1. Note: line 1 is the second row,
// since counting begins with 0.
lcd_set_cursor_position (0, 1);
// Test lcd_printf().
lcd_printf ("%.2f ", magic_number);
_delay_ms (time_per_test_ms);
// Test lcd_printf_P().
lcd_printf_P (PSTR ("%.2f "), magic_number);
_delay_ms (time_per_test_ms);
// Test the underline cursor on/off routines.
lcd_underline_cursor_on ();
_delay_ms (time_per_test_ms);
lcd_underline_cursor_off ();
// Test blinking cursor on/off routines.
lcd_blinking_cursor_on ();
_delay_ms (time_per_test_ms);
lcd_blinking_cursor_off ();
// Test turning display off and on again.
lcd_display_off ();
_delay_ms (time_per_test_ms);
lcd_display_on ();
// Test setting the cursor somewhere exotic.
uint8_t test_start_col = 12, test_start_row = 1;
const char test_char = 'X';
lcd_set_cursor_position (test_start_col, test_start_row);
lcd_write (test_char);
_delay_ms (time_per_test_ms);
lcd_clear ();
// Test display scrolling.
test_start_col = 0, test_start_row = 0;
lcd_set_cursor_position(test_start_col, test_start_row);
lcd_printf ("hello, big world!");
const int chars_to_scroll = 3;
const float ms_per_scroll_step = 500.0;
for ( int ii = 0 ; ii < chars_to_scroll ; ii++ ) {
lcd_scroll_left ();
_delay_ms (ms_per_scroll_step);
}
for ( int ii = 0 ; ii < chars_to_scroll ; ii++ ) {
lcd_scroll_right ();
_delay_ms (ms_per_scroll_step);
}
// Test setting cursor position and writing while scrolled. This test
// illustrated the fact that the cursor position refers to a location in
// the underlying text area, not a current physical screen coordinate.
// When the screen is scrolled, the lcd_set_cursor_position() function
// behavior changes accordingly.
lcd_scroll_left ();
lcd_scroll_left ();
test_start_col = 4, test_start_row = 0;
lcd_set_cursor_position(test_start_col, test_start_row);
lcd_printf ("Foo!");
_delay_ms (time_per_test_ms);
// Test output of a couple of useful non-ASCII characters. These may fail
// depending on LCD model; see notes in the header file.
lcd_home ();
lcd_write (LCD_CHARACTER_RIGHT_ARROW);
lcd_write (LCD_CHARACTER_LEFT_ARROW);
}