-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_lcd.c
167 lines (118 loc) · 4.41 KB
/
test_lcd.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*************************************************************************
Title: Testing output to a HD44780 based LCD display.
Author: Peter Fleury <[email protected]> http://tinyurl.com/peterfleury
File: $Id: test_lcd.c,v 1.8 2015/01/31 18:04:08 peter Exp $
Software: AVR-GCC 4.x
Hardware: HD44780 compatible LCD text display
AVR with external SRAM interface if memory-mapped LCD interface is used
any AVR with 7 free I/O pins if 4-bit IO port mode is used
**************************************************************************/
#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd.h"
/*
** constant definitions
*/
static const PROGMEM unsigned char copyRightChar[] =
{
0x07, 0x08, 0x13, 0x14, 0x14, 0x13, 0x08, 0x07,
0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00
};
/*
** function prototypes
*/
void wait_until_key_pressed(void);
void wait_until_key_pressed(void)
{
unsigned char temp1, temp2;
do {
temp1 = PIND; // read input
_delay_ms(5); // delay for key debounce
temp2 = PIND; // read input
temp1 = (temp1 & temp2); // debounce input
} while ( temp1 & _BV(PIND2) );
loop_until_bit_is_set(PIND,PIND2); /* wait until key is released */
}
int main(void)
{
char buffer[7];
int num=134;
unsigned char i;
DDRD &=~ (1 << PD2); /* Pin PD2 input */
PORTD |= (1 << PD2); /* Pin PD2 pull-up enabled */
/* initialize display, cursor off */
lcd_init(LCD_DISP_ON);
for (;;) { /* loop forever */
/*
* Test 1: write text to display
*/
/* clear display and home cursor */
lcd_clrscr();
/* put string to display (line 1) with linefeed */
lcd_puts("LCD Test Line 1\n");
/* cursor is now on second line, write second line */
lcd_puts("Line 2");
/* move cursor to position 8 on line 2 */
lcd_gotoxy(7,1);
/* write single char to display */
lcd_putc(':');
/* wait until push button PD2 (INT0) is pressed */
wait_until_key_pressed();
/*
* Test 2: use lcd_command() to turn on cursor
*/
/* turn on cursor */
lcd_command(LCD_DISP_ON_CURSOR);
/* put string */
lcd_puts( "CurOn");
/* wait until push button PD2 (INT0) is pressed */
wait_until_key_pressed();
/*
* Test 3: display shift
*/
lcd_clrscr(); /* clear display home cursor */
/* put string from program memory to display */
lcd_puts_P( "Line 1 longer than 14 characters\n" );
lcd_puts_P( "Line 2 longer than 14 characters" );
/* move BOTH lines one position to the left */
lcd_command(LCD_MOVE_DISP_LEFT);
/* wait until push button PD2 (INT0) is pressed */
wait_until_key_pressed();
/* turn off cursor */
lcd_command(LCD_DISP_ON);
/*
* Test: Display integer values
*/
lcd_clrscr(); /* clear display home cursor */
/* convert interger into string */
itoa( num , buffer, 10);
/* put converted string to display */
lcd_puts(buffer);
/* wait until push button PD2 (INT0) is pressed */
wait_until_key_pressed();
/*
* Test: Display userdefined characters
*/
lcd_clrscr(); /* clear display home cursor */
lcd_puts("Copyright: ");
/*
* load two userdefined characters from program memory
* into LCD controller CG RAM location 0 and 1
*/
lcd_command(_BV(LCD_CGRAM)); /* set CG RAM start address 0 */
for(i=0; i<16; i++)
{
lcd_data(pgm_read_byte_near(©RightChar[i]));
}
/* move cursor to position 0 on line 2 */
/* Note: this switched back to DD RAM adresses */
lcd_gotoxy(0,1);
/* display user defined (c), built using two user defined chars */
lcd_putc(0);
lcd_putc(1);
/* wait until push button PD2 (INT0) is pressed */
wait_until_key_pressed();
}
}