3 * Text-based LCD driver.
4 * This is designed to drive the parallel interface LCD drivers
5 * based in the Hitachi HD44780U controller and compatables.
7 * This test program assumes the following:
10 * GPIO 0-7 is connected to display data pins 0-7.
11 * GPIO 11 is the RS pin.
12 * GPIO 10 is the Strobe/E pin.
14 * For 4-bit interface:
15 * GPIO 4-7 is connected to display data pins 4-7.
16 * GPIO 11 is the RS pin.
17 * GPIO 10 is the Strobe/E pin.
19 * Copyright (c) 2012-2013 Gordon Henderson.
20 ***********************************************************************
21 * This file is part of wiringPi:
22 * https://projects.drogon.net/raspberry-pi/wiringpi/
24 * wiringPi is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU Lesser General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * wiringPi is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
34 * You should have received a copy of the GNU Lesser General Public License
35 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
36 ***********************************************************************
55 static unsigned char newChar [8] =
70 static int lcdHandle ;
74 *********************************************************************************
77 int usage (const char *progName)
79 fprintf (stderr, "Usage: %s bits cols rows\n", progName) ;
86 *********************************************************************************
89 static const char *message =
91 "Wiring Pi by Gordon Henderson. HTTP://WIRINGPI.COM/"
94 void scrollMessage (int line, int width)
97 static int position = 0 ;
98 static int timer = 0 ;
100 if (millis () < timer)
103 timer = millis () + 200 ;
105 strncpy (buf, &message [position], width) ;
107 lcdPosition (lcdHandle, 0, line) ;
108 lcdPuts (lcdHandle, buf) ;
110 if (++position == (strlen (message) - width))
117 * Bounce a character - only on 4-line displays
118 *********************************************************************************
121 static void pingPong (int lcd, int cols)
123 static int position = 0 ;
126 if (dir == 0) // Setup
129 lcdPosition (lcdHandle, 0, 3) ;
130 lcdPutchar (lcdHandle, '*') ;
134 lcdPosition (lcdHandle, position, 3) ;
135 lcdPutchar (lcdHandle, ' ') ;
138 if (position == cols)
150 lcdPosition (lcdHandle, position, 3) ;
151 lcdPutchar (lcdHandle, '#') ;
157 *********************************************************************************
160 static void waitForEnter (void)
162 printf ("Press ENTER to continue: ") ;
163 (void)fgetc (stdin) ;
169 *********************************************************************************
172 int main (int argc, char *argv[])
176 int bits, rows, cols ;
184 return usage (argv [0]) ;
186 printf ("Raspberry Pi LCD test\n") ;
187 printf ("=====================\n") ;
189 bits = atoi (argv [1]) ;
190 cols = atoi (argv [2]) ;
191 rows = atoi (argv [3]) ;
193 if (!((rows == 1) || (rows == 2) || (rows == 4)))
195 fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
196 return EXIT_FAILURE ;
199 if (!((cols == 16) || (cols == 20)))
201 fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
202 return EXIT_FAILURE ;
208 lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
210 lcdHandle = lcdInit (rows, cols, 8, 11,10, 0,1,2,3,4,5,6,7) ;
214 fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
218 lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
219 lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ;
225 lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ;
229 lcdPosition (lcdHandle, 0, 2) ;
230 for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
231 lcdPuts (lcdHandle, "=-") ;
232 lcdPuts (lcdHandle, "=3") ;
234 lcdPosition (lcdHandle, 0, 3) ;
235 for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
236 lcdPuts (lcdHandle, "-=") ;
237 lcdPuts (lcdHandle, "-4") ;
243 lcdCharDef (lcdHandle, 2, newChar) ;
245 lcdClear (lcdHandle) ;
246 lcdPosition (lcdHandle, 0, 0) ;
247 lcdPuts (lcdHandle, "User Char: ") ;
248 lcdPutchar (lcdHandle, 2) ;
250 lcdCursor (lcdHandle, TRUE) ;
251 lcdCursorBlink (lcdHandle, TRUE) ;
255 lcdCursor (lcdHandle, FALSE) ;
256 lcdCursorBlink (lcdHandle, FALSE) ;
257 lcdClear (lcdHandle) ;
261 scrollMessage (0, cols) ;
267 t = localtime (&tim) ;
269 sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
271 lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
272 lcdPuts (lcdHandle, buf) ;
277 sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
279 lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
280 lcdPuts (lcdHandle, buf) ;
282 pingPong (lcd, cols) ;