OSDN Git Service

[LCD][4bit] Using bit-manipulation to communicate LCD.
[openi2cradio/OpenI2CRadio.git] / iodef.h
1 /*
2  * OpenI2CRADIO
3  * I/O Port defines.
4  * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
5  * License: GPL2+LE
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2,
10  *  or (at your option) any later version.
11  *  This library / program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  *  See the GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this library; see the file COPYING. If not, write to the
18  *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19  *  MA 02110-1301, USA.
20  *
21  *  As a special exception, if you link this(includeed from sdcc) library
22  *  with other files, some of which are compiled with SDCC,
23  *  to produce an executable, this library does not by itself cause
24  *  the resulting executable to be covered by the GNU General Public License.
25  *  This exception does not however invalidate any other reasons why
26  *  the executable file might be covered by the GNU General Public License.
27  */
28
29 #ifndef IODEF_H
30 #define IODEF_H
31
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37  * LCD(ACM1602 Type)
38  */
39 // If you use I2C-Type ACM1602, You should define, otherwise #undef.
40 #undef _USE_I2C_1602
41 #define _LCD_IF_4BIT
42
43 /*
44  * Machine depended flags
45  */
46 #if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
47 #define _I2C_IO_TWO_MSSPS
48 #define _PIO_HAS_THREE
49 #endif
50
51 #if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
52 #define _I2C_IO_ONE_MSSP
53 #define _PIO_HAS_THREE
54 #endif
55
56 #if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20)
57 #define _I2C_IO_ONE_MSSP
58 #define _PIO_HAS_FIVE
59 #endif
60
61
62 /*
63  * MAP OF IOPORT
64  *
65  * RE3: VPP (ICSP Programming Voltage) / MCLR, Dont use for I/O.
66  *
67  * PORTA/B/C USED basic.
68  *
69  * PORTA: RA0 : ADC(IN) to measure battery .
70  *        RA1 : SLOT D(OUT)
71  *        RA2-RA5 : READ
72  *        RA6-RA7 : Used for CLOCK, connect to 8MHz resonator.
73  *
74  * PORTB: RB0 : Light Out
75  *        RB1 : Light
76  *        RB2 : FUNC
77  *        RB3 : DEL / BAND
78  *        RB4-RB5 : RESERVED
79  *        RB6-RB7 : FOR ICSP
80  *
81  * PORTC: RC0 : LED
82  *        RC1 : SLOT A
83  *        RC2 : SLOT B
84  *        RC3-RC4 : SCL/SDA
85  *        RC5 : SLOT C
86  *        RC6-RC7 : USART
87  *
88  * In addition, usage of PARALLEL-LCD,You should use 40Pin(or greater) PIC.
89  * ON 4BIT LCD I/F:
90  *
91  * PORTD: RD0: LCD RS
92  *        RD1: LCD RW
93  *        RD2: LCD EN
94  *        RD3: RESERVED.
95  *        RD4-RD7 : LCD DATA(DB4-DB7)
96  *
97  * PORTD: RE0: FM AMP SW(OUT)
98  *        RE1: MW AMP SW(OUT)
99  *        RE2: SW AMP SW(OUT)
100  *        RE3: VPP (ICSP Programming Voltage) / MCLR
101  *
102  * ON 8BIT LCD I/F:
103  * PORTD: RD0-RD7 : LCD DATA(DB0-DB7)
104  * PORTE: RE0: LCD RS
105  *        RE1: LCD RW
106  *        RE2: LCD EN
107  *        RE3: VPP (ICSP Programming Voltage) / MCLR
108  */
109
110 #define TRIS_A_VAL   0b11111101
111 #define AN_A_VAL     0b00000001
112 #define TRIS_B_VAL   0b11111110
113 #define AN_B_VAL     0b00000000
114 #define TRIS_C_VAL_O 0b11000000 /* FOR I2C-WRITE */
115 #define TRIS_C_VAL_I 0b11011000 /* FOR I2C-WRITE */
116 #define AN_C_VAL     0b00000000
117
118 #define TRIS_D_VAL   0b00000000 /* FOR OUTPUT, LCD(Optional) */
119 #ifdef _LCD_IF_4BIT
120  #define TRIS_D_RVAL 0b11110000 /* FOR INPUT*/
121 #else
122  #define TRIS_D_RVAL 0b11111111 /* FOR INPUT*/
123 #endif
124 #define TRIS_E_VAL   0b00000000 /* FOR OUTPUT, LCD(Optional), PSP=OFF */
125
126
127 typedef  union {
128     struct {
129     unsigned BIT0A:1;
130     unsigned BIT1A:1;
131     unsigned BIT2A:1;
132     unsigned BIT3A:1;
133
134     unsigned BIT0B:1;
135     unsigned BIT1B:1;
136     unsigned BIT2B:1;
137     unsigned BIT3B:1;
138
139     unsigned BIT0C:1;
140     unsigned BIT1C:1;
141     unsigned BIT2C:1;
142     unsigned BIT3C:1;
143
144     unsigned BIT0D:1;
145     unsigned BIT1D:1;
146     unsigned BIT2D:1;
147     unsigned BIT3D:1;
148
149     /*
150      * special keys
151      */
152     unsigned BIT0F:1;
153     unsigned BIT1F:1;
154     unsigned BIT2F:1;
155     unsigned BIT3F:1;
156     unsigned :1;
157     unsigned :1;
158     unsigned :1;
159     unsigned :1;
160     };
161     unsigned char byte[3];
162 } keyin_defs;
163
164 enum {
165     charcode_null = 0,
166     charcode_1,
167     charcode_2,
168     charcode_3,
169     charcode_4,
170     charcode_5,
171     charcode_6,
172     charcode_7,
173     charcode_8,
174     charcode_9,
175     charcode_a,
176     charcode_b,
177     charcode_c,
178     charcode_d,
179     charcode_e,
180     charcode_f,
181     charcode_0,
182     charcode_s0, // RB1
183     charcode_s1, // RB2
184     charcode_s2, // RB3
185     charcode_s3, // Reserve
186 };
187
188 /*
189  * LCD Control: Default register values, You should re-define in iodef.h if you need.
190  */
191 typedef union {
192         unsigned char byte;
193         struct {
194             unsigned b0:1;
195             unsigned b1:1;
196             unsigned b2:1;
197             unsigned b3:1;
198             unsigned b4:1;
199             unsigned b5:1;
200             unsigned b6:1;
201             unsigned b7:1;
202         };
203     } Bitdefs_t;
204
205 #ifdef _LCD_IF_4BIT
206 /*
207  * 4bit Interface, Used Below:
208  * PORTD: RD0 : RS
209  *        RD1 : RW
210  *        RD2 : EN
211  *        RD4-RD7: DATA(4-7).
212  */
213  #ifndef _LCDPORT_DATA
214 #define _LCDPORT_DATA PORTD
215 #define _LCDPORT_TRIS_DATA TRISD
216 #define _LCDPORT_LATCH_DATA LATD
217 #define _LCDPORT_BUSYMASK 0b10000000
218 #define _LCDPORT_READMASK TRIS_D_RVAL
219 #define _LCDPORT_DATA_SHIFT 4
220  #endif
221
222  #ifndef _LCDPORT_CONT
223 #define _LCDPORT_CONT PORTD
224 #define _LCDPORT_TRIS_CONT TRISD
225 #define _LCDPORT_CONT_LATCH LATD
226 #define _LCDPORT_CONT_RSbit b0
227 #define _LCDPORT_CONT_RWbit b1
228 #define _LCDPORT_CONT_ENbit b2
229 #define _LCDPORT_CONT_RS _PORTD_RD0
230 #define _LCDPORT_CONT_RW _PORTD_RD1
231 #define _LCDPORT_CONT_EN _PORTD_RD2
232  #endif
233
234 #else
235 /*
236  * 8bit Interface, Used Below:
237  * PORTE: RE0 : RS
238  *        RE1 : RW
239  *        RE2 : EN
240  * PORTD: RD0-RD7: DATA(0-7).
241  */
242 // 8bit I/F
243  #ifndef _LCDPORT_DATA
244 #define _LCDPORT_DATA PORTD
245 #define _LCDPORT_TRIS_DATA TRISD
246 #define _LCDPORT_LATCH_DATA LATD
247 #define _LCDPORT_BUSYMASK 0b10000000
248 #define _LCDPORT_READMASK TRIS_D_RVAL
249  #endif
250
251  #ifndef _LCDPORT_CONT
252 #define _LCDPORT_CONT PORTE
253 #define _LCDPORT_TRIS_CONT TRISE
254 #define _LCDPORT_CONT_RSbit 0
255 #define _LCDPORT_CONT_RWbit 1
256 #define _LCDPORT_CONT_ENbit 2
257 #define _LCDPORT_CONT_RS _PORTE_RE0
258 #define _LCDPORT_CONT_RW _PORTE_RE1
259 #define _LCDPORT_CONT_EN _PORTE_RE2
260 #define _LCDPORT_CONT_LATCH LATE
261  #endif
262 #endif
263
264 #ifdef  __cplusplus
265 }
266 #endif
267
268 #endif  /* IODEF_H */
269