1102 |
miho |
1 |
/* --------------------------------------------------------------------------- |
|
|
2 |
* HD 44780 LCD Display Driver Test Application |
|
|
3 |
* www.mlab.cz miho 2008 |
|
|
4 |
* --------------------------------------------------------------------------- |
|
|
5 |
* 00.00 2008/03/28 First Version |
|
|
6 |
* --------------------------------------------------------------------------- |
|
|
7 |
*/ |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
// Required Libraries |
|
|
11 |
// ------------------ |
|
|
12 |
|
|
|
13 |
// Delay |
|
|
14 |
|
|
|
15 |
#define F_CPU 8000000UL // CPU Frequency |
|
|
16 |
#include <util/delay.h> // Delay Routines |
|
|
17 |
|
|
|
18 |
// Standard Output Library |
|
|
19 |
|
|
|
20 |
#include <stdio.h> // For printf |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
// LCD Display Interface |
|
|
24 |
// --------------------- |
|
|
25 |
|
|
|
26 |
// LCD Port Settings |
|
|
27 |
|
|
|
28 |
#define LCD_DATA B // 4 or 8 bits field (lsb port) |
|
|
29 |
#define LCD_DATA_BIT 4 |
|
|
30 |
|
|
|
31 |
#define LCD_RS D // Register Select |
|
|
32 |
#define LCD_RS_BIT 4 |
|
|
33 |
|
|
|
34 |
#define LCD_E D // Enable |
|
|
35 |
#define LCD_E_BIT 3 |
|
|
36 |
|
|
|
37 |
// LCD Display Parameters |
|
|
38 |
|
|
|
39 |
#define LCD_INTERFACE_BITS 4 // 4 or 8 bit interface |
|
|
40 |
#define LCD_LINES 2 // 1 or 2 or 4 lines |
|
|
41 |
#define LCD_CHARS 20 // usualy 16 or 20, important for 4 line display only |
|
|
42 |
|
|
|
43 |
// LCD Library |
|
|
44 |
|
|
|
45 |
#include "lcd_hd44780.h" |
|
|
46 |
|
|
|
47 |
|
|
|
48 |
// Test Application |
|
|
49 |
// ---------------- |
|
|
50 |
|
|
|
51 |
|
|
|
52 |
// Define Output Stream to LCD |
|
|
53 |
static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE); |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
// Main Program |
|
|
57 |
int main () |
|
|
58 |
{ |
|
|
59 |
int i; |
|
|
60 |
|
|
|
61 |
stdout = &lcd_stream; // Connect stdout to LCD Stream |
|
|
62 |
|
|
|
63 |
lcd_init(); // Init LCD (interface and display module) |
|
|
64 |
|
|
|
65 |
// Print Lines |
|
|
66 |
for (i=1; i<=LCD_LINES;i++) |
|
|
67 |
{ |
|
|
68 |
lcd_gotoxy(1,i); |
|
|
69 |
printf("Line %d", i); |
|
|
70 |
_delay_ms(100); |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
// Show User Defined Symbols |
|
|
74 |
printf("\fBat Status \x10 \x11"); |
|
|
75 |
_delay_ms(100); |
|
|
76 |
printf("\v" "\x11" LCD_CHAR_UP "\v"); |
|
|
77 |
printf("\v" "\x10" LCD_CHAR_BAT100 "\v"); |
|
|
78 |
_delay_ms(100); |
|
|
79 |
printf("\v" "\x10" LCD_CHAR_BAT50 "\v"); |
|
|
80 |
_delay_ms(100); |
|
|
81 |
printf("\v" "\x10" LCD_CHAR_BAT0 "\v"); |
|
|
82 |
_delay_ms(100); |
|
|
83 |
|
|
|
84 |
// Show Cursor |
|
|
85 |
lcd_cursor_on(); |
|
|
86 |
_delay_ms(100); |
|
|
87 |
lcd_cursor_right(); |
|
|
88 |
_delay_ms(100); |
|
|
89 |
lcd_cursor_left(); |
|
|
90 |
_delay_ms(100); |
|
|
91 |
lcd_cursor_left(); |
|
|
92 |
_delay_ms(100); |
|
|
93 |
|
|
|
94 |
// Print to the Next Line |
|
|
95 |
printf("\n Hello World"); |
|
|
96 |
_delay_ms(100); |
|
|
97 |
|
|
|
98 |
for(i=20;i>0;i--) |
|
|
99 |
{ |
|
|
100 |
printf("\r%2d", i); |
|
|
101 |
_delay_ms(100); |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
lcd_cursor_off(); |
|
|
105 |
printf("\b\b X"); |
|
|
106 |
} |