--- /dev/null
+/*************************************************************************\r
+Title: testing output to a HD44780 based LCD display.\r
+Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury\r
+File: $Id: test_lcd.c,v 1.6 2004/12/10 13:53:59 peter Exp $\r
+Software: AVR-GCC 3.3\r
+Hardware: HD44780 compatible LCD text display\r
+ ATS90S8515/ATmega if memory-mapped LCD interface is used\r
+ any AVR with 7 free I/O pins if 4-bit IO port mode is used\r
+**************************************************************************/\r
+#include <stdlib.h>\r
+#include <avr/io.h>\r
+#include <avr/pgmspace.h>\r
+#include "lcd.h"\r
+\r
+\r
+/*\r
+** constant definitions\r
+*/\r
+static const PROGMEM unsigned char copyRightChar[] =\r
+{\r
+ 0x07, 0x08, 0x13, 0x14, 0x14, 0x13, 0x08, 0x07,\r
+ 0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00\r
+};\r
+\r
+\r
+/*\r
+** function prototypes\r
+*/ \r
+void wait_until_key_pressed(void);\r
+\r
+\r
+void wait_until_key_pressed(void)\r
+{\r
+ unsigned char temp1, temp2;\r
+ unsigned int i;\r
+ \r
+ do {\r
+ temp1 = PINC; // read input\r
+ for(i=0;i<65535;i++);\r
+ temp2 = PINC; // read input\r
+ temp1 = (temp1 & temp2); // debounce input\r
+ } while ( temp1 & _BV(PINC4) );\r
+ \r
+ loop_until_bit_is_set(PINC,PINC4); /* wait until key is released */\r
+}\r
+\r
+\r
+int main(void)\r
+{\r
+ char buffer[7];\r
+ int num=134;\r
+ unsigned char i;\r
+ \r
+ \r
+ DDRD &=~ (1 << PC4); /* Pin PC4 input */\r
+ PORTD |= (1 << PC4); /* Pin PC4 pull-up enabled */\r
+\r
+\r
+ /* initialize display, cursor off */\r
+ lcd_init(LCD_DISP_ON);\r
+\r
+ for (;;) { /* loop forever */\r
+ /* \r
+ * Test 1: write text to display\r
+ */\r
+\r
+ /* clear display and home cursor */\r
+ lcd_clrscr();\r
+ \r
+ /* put string to display (line 1) with linefeed */\r
+ lcd_puts("LCD Test Line 1\n");\r
+\r
+ /* cursor is now on second line, write second line */\r
+ lcd_puts("Line 2");\r
+ \r
+ /* move cursor to position 8 on line 2 */\r
+ lcd_gotoxy(7,1); \r
+ \r
+ /* write single char to display */\r
+ lcd_putc(':');\r
+ \r
+ /* wait until push button PD2 (INT0) is pressed */\r
+ wait_until_key_pressed();\r
+ \r
+ \r
+ /*\r
+ * Test 2: use lcd_command() to turn on cursor\r
+ */\r
+ \r
+ /* turn on cursor */\r
+ lcd_command(LCD_DISP_ON_CURSOR);\r
+\r
+ /* put string */\r
+ lcd_puts( "CurOn");\r
+ \r
+ /* wait until push button PD2 (INT0) is pressed */\r
+ wait_until_key_pressed();\r
+\r
+\r
+ /*\r
+ * Test 3: display shift\r
+ */\r
+ \r
+ lcd_clrscr(); /* clear display home cursor */\r
+\r
+ /* put string from program memory to display */\r
+ lcd_puts_P( "Line 1 longer than 14 characters\n" );\r
+ lcd_puts_P( "Line 2 longer than 14 characters" );\r
+ \r
+ /* move BOTH lines one position to the left */\r
+ lcd_command(LCD_MOVE_DISP_LEFT);\r
+ \r
+ /* wait until push button PD2 (INT0) is pressed */\r
+ wait_until_key_pressed();\r
+\r
+ /* turn off cursor */\r
+ lcd_command(LCD_DISP_ON);\r
+ \r
+ \r
+ /*\r
+ * Test: Display integer values\r
+ */\r
+ \r
+ lcd_clrscr(); /* clear display home cursor */\r
+ \r
+ /* convert interger into string */\r
+ itoa( num , buffer, 10);\r
+ \r
+ /* put converted string to display */\r
+ lcd_puts(buffer);\r
+ \r
+ /* wait until push button PD2 (INT0) is pressed */\r
+ wait_until_key_pressed();\r
+ \r
+ \r
+ /*\r
+ * Test: Display userdefined characters\r
+ */\r
+\r
+ lcd_clrscr(); /* clear display home cursor */\r
+ \r
+ lcd_puts("Copyright: ");\r
+ \r
+ /*\r
+ * load two userdefined characters from program memory\r
+ * into LCD controller CG RAM location 0 and 1\r
+ */\r
+ lcd_command(_BV(LCD_CGRAM)); /* set CG RAM start address 0 */\r
+ for(i=0; i<16; i++)\r
+ {\r
+ lcd_data(pgm_read_byte_near(©RightChar[i]));\r
+ }\r
+ \r
+ /* move cursor to position 0 on line 2 */\r
+ /* Note: this switched back to DD RAM adresses */\r
+ lcd_gotoxy(0,1);\r
+ \r
+ /* display user defined (c), built using two user defined chars */\r
+ lcd_putc(0);\r
+ lcd_putc(1);\r
+ \r
+\r
+ /* wait until push button PD2 (INT0) is pressed */\r
+ wait_until_key_pressed();\r
+ \r
+ }\r
+}\r