/Library/AVR_MLIB/Examples/lcd_hd44780/lcd_hd44780_test.c
0,0 → 1,113
/* ---------------------------------------------------------------------------
* AVR_MLIB - HD 44780 LCD Display Driver Test Application
* www.mlab.cz miho 2008
* ---------------------------------------------------------------------------
* Simple test application for lcd_hd44780.h LCD library. This code ilustates
* how to use and configure the library functions.
* ---------------------------------------------------------------------------
* 00.00 2008/03/28 First Version
* 00.01 2008/04/19 Improved
* ---------------------------------------------------------------------------
*/
 
 
// Required Libraries
// ------------------
 
// Delay
 
#define F_CPU 1000000UL // CPU Frequency
#include <util/delay.h> // Delay Routines
 
// Standard Output Library
 
#include <stdio.h> // For printf
 
 
// LCD Display Interface
// ---------------------
 
// LCD Port Settings
 
#define LCD_DATA B // 4 or 8 bits field (lsb port)
#define LCD_DATA_BIT 4
 
#define LCD_RS D // Register Select
#define LCD_RS_BIT 4
 
#define LCD_E D // Enable
#define LCD_E_BIT 3
 
// LCD Display Parameters
 
#define LCD_INTERFACE_BITS 4 // 4 or 8 bit interface
#define LCD_LINES 2 // 1 or 2 or 4 lines
#define LCD_CHARS 20 // usualy 16 or 20, important for 4 line display only
 
// LCD Library
 
#include "lcd_hd44780.h"
 
 
// Test Application
// ----------------
 
 
// Define Output Stream to LCD
static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE);
 
 
// Main Program
int main ()
{
int i;
 
stdout = &lcd_stream; // Connect stdout to LCD Stream
 
lcd_init(); // Init LCD (interface and display module)
 
// Print Lines
for (i=1; i<=LCD_LINES;i++)
{
lcd_gotoxy(1,i);
printf("Line %d", i);
_delay_ms(1000);
}
 
// Show User Defined Symbols
printf("\v" "\x10" LCD_CHAR_SPACE LCD_CHAR_SPACE "\v"); // You shold know that dispaly
printf("\fBat Status \x10 \x11"); // does clear user defined chars
_delay_ms(1000); // on Power Up only
printf("\v" "\x11" LCD_CHAR_UP "\v");
printf("\v" "\x10" LCD_CHAR_BAT100 "\v");
_delay_ms(1000);
printf("\v" "\x10" LCD_CHAR_BAT50 "\v");
_delay_ms(1000);
printf("\v" "\x10" LCD_CHAR_BAT0 "\v");
_delay_ms(1000);
 
// Show Cursor
lcd_cursor_on();
_delay_ms(1000);
lcd_cursor_right();
_delay_ms(1000);
lcd_cursor_left();
_delay_ms(1000);
lcd_cursor_left();
_delay_ms(1000);
 
// Print to the Next Line
printf("\n Hello World");
_delay_ms(1000);
 
// Count Down
for(i=20;i>0;i--)
{
printf("\r%2d", i);
_delay_ms(1000);
}
 
// End
lcd_cursor_off();
printf("\b\b X");
}