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