1 /*************************************************************************
\r
2 Title: testing output to a HD44780 based LCD display.
\r
3 Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
\r
4 File: $Id: test_lcd.c,v 1.6 2004/12/10 13:53:59 peter Exp $
\r
5 Software: AVR-GCC 3.3
\r
6 Hardware: HD44780 compatible LCD text display
\r
7 ATS90S8515/ATmega if memory-mapped LCD interface is used
\r
8 any AVR with 7 free I/O pins if 4-bit IO port mode is used
\r
9 **************************************************************************/
\r
12 #include <avr/pgmspace.h>
\r
17 ** constant definitions
\r
19 static const PROGMEM unsigned char copyRightChar[] =
\r
21 0x07, 0x08, 0x13, 0x14, 0x14, 0x13, 0x08, 0x07,
\r
22 0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00
\r
27 ** function prototypes
\r
29 void wait_until_key_pressed(void);
\r
32 void wait_until_key_pressed(void)
\r
34 unsigned char temp1, temp2;
\r
38 temp1 = PINC; // read input
\r
39 for(i=0;i<65535;i++);
\r
40 temp2 = PINC; // read input
\r
41 temp1 = (temp1 & temp2); // debounce input
\r
42 } while ( temp1 & _BV(PINC4) );
\r
44 loop_until_bit_is_set(PINC,PINC4); /* wait until key is released */
\r
55 DDRD &=~ (1 << PC4); /* Pin PC4 input */
\r
56 PORTD |= (1 << PC4); /* Pin PC4 pull-up enabled */
\r
59 /* initialize display, cursor off */
\r
60 lcd_init(LCD_DISP_ON);
\r
62 for (;;) { /* loop forever */
\r
64 * Test 1: write text to display
\r
67 /* clear display and home cursor */
\r
70 /* put string to display (line 1) with linefeed */
\r
71 lcd_puts("LCD Test Line 1\n");
\r
73 /* cursor is now on second line, write second line */
\r
76 /* move cursor to position 8 on line 2 */
\r
79 /* write single char to display */
\r
82 /* wait until push button PD2 (INT0) is pressed */
\r
83 wait_until_key_pressed();
\r
87 * Test 2: use lcd_command() to turn on cursor
\r
90 /* turn on cursor */
\r
91 lcd_command(LCD_DISP_ON_CURSOR);
\r
96 /* wait until push button PD2 (INT0) is pressed */
\r
97 wait_until_key_pressed();
\r
101 * Test 3: display shift
\r
104 lcd_clrscr(); /* clear display home cursor */
\r
106 /* put string from program memory to display */
\r
107 lcd_puts_P( "Line 1 longer than 14 characters\n" );
\r
108 lcd_puts_P( "Line 2 longer than 14 characters" );
\r
110 /* move BOTH lines one position to the left */
\r
111 lcd_command(LCD_MOVE_DISP_LEFT);
\r
113 /* wait until push button PD2 (INT0) is pressed */
\r
114 wait_until_key_pressed();
\r
116 /* turn off cursor */
\r
117 lcd_command(LCD_DISP_ON);
\r
121 * Test: Display integer values
\r
124 lcd_clrscr(); /* clear display home cursor */
\r
126 /* convert interger into string */
\r
127 itoa( num , buffer, 10);
\r
129 /* put converted string to display */
\r
132 /* wait until push button PD2 (INT0) is pressed */
\r
133 wait_until_key_pressed();
\r
137 * Test: Display userdefined characters
\r
140 lcd_clrscr(); /* clear display home cursor */
\r
142 lcd_puts("Copyright: ");
\r
145 * load two userdefined characters from program memory
\r
146 * into LCD controller CG RAM location 0 and 1
\r
148 lcd_command(_BV(LCD_CGRAM)); /* set CG RAM start address 0 */
\r
149 for(i=0; i<16; i++)
\r
151 lcd_data(pgm_read_byte_near(©RightChar[i]));
\r
154 /* move cursor to position 0 on line 2 */
\r
155 /* Note: this switched back to DD RAM adresses */
\r
158 /* display user defined (c), built using two user defined chars */
\r
163 /* wait until push button PD2 (INT0) is pressed */
\r
164 wait_until_key_pressed();
\r