lib/lcd-pcf8574.c

changeset 16
f4cbe008da72
child 18
3f4823083b9d
equal deleted inserted replaced
15:01fec4ddad17 16:f4cbe008da72
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 "../config.h"
27 #include "mbselib.h"
28
29 //#include <stdio.h>
30 //#include <stdlib.h>
31 //#include <unistd.h>
32 //#include <stdint.h>
33
34 //#include <string.h>
35 //#include <time.h>
36
37 //#include <wiringPi.h>
38 //#include <pcf8574.h>
39 //#include <lcd.h>
40
41 //#ifndef TRUE
42 //# define TRUE (1==1)
43 //# define FALSE (1==2)
44 //#endif
45
46
47 // Defines for the pcf8574 Pi LCD interface board
48
49 //#define AF_BASE 100
50
51 //#define AF_RS (AF_BASE + 0)
52 //#define AF_RW (AF_BASE + 1)
53 //#define AF_E (AF_BASE + 2)
54 //#define AF_BACKLIGHT (AF_BASE + 3)
55
56 //#define AF_DB4 (AF_BASE + 4)
57 //#define AF_DB5 (AF_BASE + 5)
58 //#define AF_DB6 (AF_BASE + 6)
59 //#define AF_DB7 (AF_BASE + 7)
60
61
62 // User-Defined character test
63
64 // Global lcd handle:
65
66 int lcdHandle;
67
68
69 /*
70 * setBacklight:
71 *********************************************************************************
72 */
73
74 void setBacklight (int value)
75 {
76 pinMode (AF_BACKLIGHT, OUTPUT) ;
77 digitalWrite (AF_BACKLIGHT, (value & 1)) ;
78 }
79
80
81
82 /*
83 * initLCD:
84 *********************************************************************************
85 */
86
87 int initLCD (int cols, int rows)
88 {
89 if (!((rows == 1) || (rows == 2) || (rows == 4)))
90 {
91 fprintf (stderr, "rows must be 1, 2 or 4\n") ;
92 return EXIT_FAILURE ;
93 }
94
95 if (!((cols == 16) || (cols == 20)))
96 {
97 fprintf (stderr, "cols must be 16 or 20\n") ;
98 return EXIT_FAILURE ;
99 }
100
101 wiringPiSetupSys () ;
102 pcf8574Setup (AF_BASE, 0x27) ;
103
104 setBacklight (1) ;
105
106 pinMode (AF_RW, OUTPUT) ;
107 digitalWrite (AF_RW, LOW) ; // Not used with wiringPi - always in write mode
108
109 // The other control pins are initialised with lcdInit ()
110
111 lcdHandle = lcdInit (rows, cols, 4, AF_RS, AF_E, AF_DB4, AF_DB5, AF_DB6, AF_DB7, 0, 0, 0, 0) ;
112
113 if (lcdHandle < 0)
114 {
115 fprintf (stderr, "lcdInit failed\n") ;
116 return -1 ;
117 }
118
119 lcdClear (lcdHandle) ;
120 return 0 ;
121 }

mercurial