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] =
68 int usage (const char *progName)
70 fprintf (stderr, "Usage: %s bits cols rows\n", progName) ;
74 static const char *message =
76 "Wiring Pi by Gordon Henderson. HTTP://WIRINGPI.COM/"
79 void scrollMessage (int lcd, int line, int width)
82 static int position = 0 ;
84 strncpy (buf, &message [position], width) ;
86 lcdPosition (lcd, 0, line) ;
89 if (++position == (strlen (message) - width))
93 static void pingPong (int lcd, int cols)
95 static int position = 0 ;
98 if (dir == 0) // Setup
101 lcdPosition (lcd, 0, 3) ;
102 lcdPutchar (lcd, '*') ;
106 lcdPosition (lcd, position, 3) ;
107 lcdPutchar (lcd, ' ') ;
110 if (position == cols)
122 lcdPosition (lcd, position, 3) ;
123 lcdPutchar (lcd, '#') ;
128 static void waitForEnter (void)
130 printf ("Press ENTER to continue: ") ;
131 (void)fgetc (stdin) ;
134 int main (int argc, char *argv[])
138 int bits, rows, cols ;
146 return usage (argv [0]) ;
148 printf ("Raspberry Pi LCD test\n") ;
149 printf ("=====================\n") ;
151 bits = atoi (argv [1]) ;
152 cols = atoi (argv [2]) ;
153 rows = atoi (argv [3]) ;
155 if (!((rows == 1) || (rows == 2) || (rows == 4)))
157 fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
158 return EXIT_FAILURE ;
161 if (!((cols == 16) || (cols == 20)))
163 fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
164 return EXIT_FAILURE ;
170 lcd = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
172 lcd = lcdInit (rows, cols, 8, 11,10, 0,1,2,3,4,5,6,7) ;
176 fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
180 lcdPosition (lcd, 0, 0) ; lcdPuts (lcd, "Gordon Henderson") ;
184 lcdPosition (lcd, 0, 1) ;
185 for (i = 0 ; i < (cols - 1) ; ++i)
186 lcdPutchar (lcd, '*') ;
187 lcdPutchar (lcd, '2') ;
191 lcdPosition (lcd, 0, 2) ;
192 for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
193 lcdPuts (lcd, "=-") ;
194 lcdPuts (lcd, "=3") ;
196 lcdPosition (lcd, 0, 3) ;
197 for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
198 lcdPuts (lcd, "-=") ;
199 lcdPuts (lcd, "-4") ;
205 lcdPosition (lcd, 0, 0) ; lcdPuts (lcd, " wiringpi.com ") ;
210 lcdCharDef (lcd, 2, newChar) ;
213 lcdPosition (lcd, 0, 0) ;
214 lcdPuts (lcd, "User Char: ") ;
215 lcdPutchar (lcd, 2) ;
217 lcdCursor (lcd, TRUE) ;
218 lcdCursorBlink (lcd, TRUE) ;
222 lcdCursor (lcd, FALSE) ;
223 lcdCursorBlink (lcd, FALSE) ;
230 scrollMessage (lcd, 0, cols) ;
236 t = localtime (&tim) ;
238 sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
240 lcdPosition (lcd, (cols - 8) / 2, 1) ;
246 sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
248 lcdPosition (lcd, (cols - 10) / 2, 2) ;
251 pingPong (lcd, cols) ;