brewco/lcd-pcf8574.c

changeset 487
d5bc44183aa4
parent 486
5a237a99a793
child 488
bee1f70fb42b
equal deleted inserted replaced
486:5a237a99a793 487:d5bc44183aa4
1 /*
2 * lcd-pcf8574.c:
3 * Text-based LCD driver library code
4 * This is designed to drive the HD44780U LCD display connected via
5 * a "LCM1602 IIC A0 A1 A2" board with a PCF8574 I2C controller.
6 *
7 * Copyright (c) 2012-2013 Gordon Henderson.
8 * Copyright (c) 2014 Michiel Broek.
9 ***********************************************************************
10 *
11 * mbsePi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * mbsePi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************
24 */
25
26 #include "brewco.h"
27 #include "lcd-pcf8574.h"
28 #include "slcd.h"
29
30
31 int lcdHandle;
32 int slcdHandle;
33
34
35 #ifdef HAVE_WIRINGPI_H
36 struct lcdDataStruct
37 {
38 int bits, rows, cols ;
39 int rsPin, strbPin ;
40 int dataPins [8] ;
41 int cx, cy ;
42 };
43
44 extern struct lcdDataStruct *lcds [MAX_LCDS];
45 #endif
46 extern sys_config Config;
47 extern uint16_t leds;
48
49
50 /*
51 * setBacklight:
52 *********************************************************************************
53 */
54 void setBacklight(int value)
55 {
56 #ifdef HAVE_WIRINGPI_H
57 pinMode (AF_BACKLIGHT, OUTPUT) ;
58 digitalWrite (AF_BACKLIGHT, (value & 1)) ;
59 #endif
60 if (value) {
61 leds |= SLED_LCD;
62 } else {
63 leds &= ~SLED_LCD;
64 }
65 slcdLEDs(slcdHandle);
66 }
67
68
69 /*
70 * initLCD:
71 *********************************************************************************
72 */
73
74 int initLCD(int cols, int rows)
75 {
76 if (!((rows == 1) || (rows == 2) || (rows == 4))) {
77 fprintf (stderr, "rows must be 1, 2 or 4\n") ;
78 return EXIT_FAILURE ;
79 }
80
81 if (!((cols == 16) || (cols == 20))) {
82 fprintf (stderr, "cols must be 16 or 20\n") ;
83 return EXIT_FAILURE ;
84 }
85
86 #ifdef HAVE_WIRINGPI_H
87 pcf8574Setup(AF_BASE, 0x27) ;
88 pinMode (AF_RW, OUTPUT) ;
89 digitalWrite (AF_RW, LOW) ; // Not used with wiringPi - always in write mode
90
91 /*
92 * The other control pins are initialised with lcdInit ()
93 */
94 lcdHandle = lcdInit (rows, cols, 4, AF_RS, AF_E, AF_DB4, AF_DB5, AF_DB6, AF_DB7, 0, 0, 0, 0) ;
95 if (lcdHandle < 0) {
96 fprintf (stderr, "lcdInit failed\n") ;
97 return -1 ;
98 }
99
100 lcdClear (lcdHandle) ;
101 #endif
102
103 slcdHandle = slcdInit(0, rows, cols);
104 if (slcdHandle < 0) {
105 fprintf (stderr, "slcdInit failed\n") ;
106 return -1;
107 }
108 slcdClear(slcdHandle);
109 setBacklight(1);
110
111 return 0 ;
112 }
113
114

mercurial