/* ---------------------------------------------------------------------------
* HD 44780 LCD Display Driver Test Application
* www.mlab.cz miho 2008
* ---------------------------------------------------------------------------
* 00.00 2008/03/28 First Version
* ---------------------------------------------------------------------------
*/
// Required Libraries
// ------------------
// Delay
#define F_CPU 8000000UL // 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(100);
}
// Show User Defined Symbols
printf("\fBat Status \x10 \x11");
_delay_ms(100);
printf("\v" "\x11" LCD_CHAR_UP "\v");
printf("\v" "\x10" LCD_CHAR_BAT100 "\v");
_delay_ms(100);
printf("\v" "\x10" LCD_CHAR_BAT50 "\v");
_delay_ms(100);
printf("\v" "\x10" LCD_CHAR_BAT0 "\v");
_delay_ms(100);
// Show Cursor
lcd_cursor_on();
_delay_ms(100);
lcd_cursor_right();
_delay_ms(100);
lcd_cursor_left();
_delay_ms(100);
lcd_cursor_left();
_delay_ms(100);
// Print to the Next Line
printf("\n Hello World");
_delay_ms(100);
for(i=20;i>0;i--)
{
printf("\r%2d", i);
_delay_ms(100);
}
lcd_cursor_off();
printf("\b\b X");
}