OSDN Git Service

[Build] Prepare to build with Microchip's XC8.
[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 #ifdef __SDCC
32 #else
33 #include <xc.h>
34 #define _XTAL_FREQ 8000000
35 #endif
36 #ifdef  __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41  * LCD(ACM1602 Type)
42  */
43 // If you use I2C-Type ACM1602, You should define, otherwise #undef.
44 #undef _USE_I2C_1602
45 #define _LCD_IF_4BIT
46
47 /*
48  * Machine depended flags
49  */
50 #if defined(__SDCC)
51 #if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
52 #define _I2C_IO_TWO_MSSPS
53 #define _PIO_HAS_THREE
54 #endif
55
56 #if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
57 #define _I2C_IO_ONE_MSSP
58 #define _PIO_HAS_THREE
59 #endif
60
61 #if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20)
62 #define _I2C_IO_ONE_MSSP
63 #define _PIO_HAS_FIVE
64 #endif
65 #else // __XC
66 #if defined(__18F23K22) || defined(__18F24k22) || defined(__18F25K22) || defined(__18F26K22)
67 #define _I2C_IO_TWO_MSSPS
68 #define _PIO_HAS_THREE
69 #endif
70
71 #if defined(__18F23K20) || defined(__18F24K20) || defined(__18F25K20) || defined(__18F26K20)
72 #define _I2C_IO_ONE_MSSP
73 #define _PIO_HAS_THREE
74 #endif
75
76 #if defined(__18F43K20) || defined(__18F44K20) || defined(__18F45K20) || defined(__18F46K20)
77 #define _I2C_IO_ONE_MSSP
78 #define _PIO_HAS_FIVE
79 #endif
80 #endif
81
82 /*
83  * MAP OF IOPORT
84  *
85  * RE3: VPP (ICSP Programming Voltage) / MCLR, Dont use for I/O.
86  *
87  * PORTA/B/C USED basic.
88  *
89  * PORTA: RA0 : ADC(IN) to measure battery .
90  *        RA1 : SLOT D(OUT)
91  *        RA2-RA5 : READ
92  *        RA6-RA7 : Used for CLOCK, connect to 8MHz resonator.
93  *
94  * PORTB: RB0 : Light Out
95  *        RB1 : Light
96  *        RB2 : FUNC
97  *        RB3 : DEL / BAND
98  *        RB4-RB5 : RESERVED
99  *        RB6-RB7 : FOR ICSP
100  *
101  * PORTC: RC0 : LED
102  *        RC1 : SLOT A
103  *        RC2 : SLOT B
104  *        RC3-RC4 : SCL/SDA
105  *        RC5 : SLOT C
106  *        RC6-RC7 : USART
107  *
108  * In addition, usage of PARALLEL-LCD,You should use 40Pin(or greater) PIC.
109  * ON 4BIT LCD I/F:
110  *
111  * PORTD: RD0: LCD RS
112  *        RD1: LCD RW
113  *        RD2: LCD EN
114  *        RD3: RESERVED.
115  *        RD4-RD7 : LCD DATA(DB4-DB7)
116  *
117  * PORTD: RE0: FM AMP SW(OUT)
118  *        RE1: MW AMP SW(OUT)
119  *        RE2: SW AMP SW(OUT)
120  *        RE3: VPP (ICSP Programming Voltage) / MCLR
121  *
122  * ON 8BIT LCD I/F:
123  * PORTD: RD0-RD7 : LCD DATA(DB0-DB7)
124  * PORTE: RE0: LCD RS
125  *        RE1: LCD RW
126  *        RE2: LCD EN
127  *        RE3: VPP (ICSP Programming Voltage) / MCLR
128  */
129
130 #define TRIS_A_VAL   0b11000000
131 #define AN_A_VAL     0b00000000
132 #define TRIS_B_VAL   0b11111111 /* PORTB as INPUT.*/
133 #define AN_B_VAL     0b00000000
134 #define TRIS_C_VAL_O 0b11011000 /* FOR I2C-WRITE */
135 #define TRIS_C_VAL_I 0b11011000 /* FOR I2C-WRITE */
136 #define AN_C_VAL     0b00000000
137 #define TRIS_D_VAL   0b00000000 /* FOR OUTPUT, LCD(Optional) */
138 #ifdef _LCD_IF_4BIT
139  #define TRIS_D_RVAL 0xf0 /* FOR INPUT*/
140 #else
141  #define TRIS_D_RVAL 0b11111111 /* FOR INPUT*/
142 #endif
143 #define TRIS_E_VAL   0b00000100 /* FOR OUTPUT, ADC, PSP=OFF */
144 #define _BATT_ADC AN7
145 #define _ADC_INITF _ANS7
146 #define _ADCH_INITF 0x00
147 #define _PORT_MUTE LATEbits.LATE0
148 #define _PORT_RADIOPOW LATEbits.LATE1
149 #ifdef __SDCC
150 #define _LCD_BACKLIGHT _PORTC_RC2
151 #else
152 #define _LCD_BACKLIGHT _PORTC_RC2_MASK
153 #endif
154 #define _LCD_PORT LATC
155 #define _AM_STATLAMP  LATAbits.LATA4
156 #define _FM_STATLAMP  LATAbits.LATA5
157 #define _POW_STATLAMP LATDbits.LATD3
158
159 #define _KEY_SENDPORT LATA
160 #define _KEY_RECVPORT PORTB
161 #define _KEY_GRP1MASK 0x01
162 #define _KEY_GRP2MASK 0x02
163 #define _KEY_GRP3MASK 0x04
164 #define _KEY_GRP4MASK 0x08
165 #define _KEY_SENDPORTMASK (_KEY_GRP1MASK | _KEY_GRP2MASK | _KEY_GRP3MASK | _KEY_GRP4MASK)
166 #define _KEY_SEND_GRP1 LATAbits.LATA0
167 #define _KEY_SEND_GRP2 LATAbits.LATA1
168 #define _KEY_SEND_GRP3 LATAbits.LATA2
169 #define _KEY_SEND_GRP4 LATAbits.LATA3
170 #define _KEY_POS1MASK(p) p.b0
171 #define _KEY_POS2MASK(p) p.b1
172 #define _KEY_POS3MASK(p) p.b2
173 #define _KEY_POS4MASK(p) p.b3
174
175 typedef  union {
176     struct {
177     unsigned BIT0A:1;
178     unsigned BIT1A:1;
179     unsigned BIT2A:1;
180     unsigned BIT3A:1;
181
182     unsigned BIT0B:1;
183     unsigned BIT1B:1;
184     unsigned BIT2B:1;
185     unsigned BIT3B:1;
186
187     unsigned BIT0C:1;
188     unsigned BIT1C:1;
189     unsigned BIT2C:1;
190     unsigned BIT3C:1;
191
192     unsigned BIT0D:1;
193     unsigned BIT1D:1;
194     unsigned BIT2D:1;
195     unsigned BIT3D:1;
196
197     };
198     unsigned char byte[2];
199 } keyin_defs;
200
201 enum {
202     charcode_null = 0,
203     charcode_1,
204     charcode_2,
205     charcode_3,
206     charcode_4,
207     charcode_5,
208     charcode_6,
209     charcode_7,
210     charcode_8,
211     charcode_9,
212     charcode_a,
213     charcode_b,
214     charcode_c,
215     charcode_d,
216     charcode_e,
217     charcode_f,
218     charcode_0,
219     // Special keys was removed.
220 };
221
222 /*
223  * LCD Control: Default register values, You should re-define in iodef.h if you need.
224  */
225
226
227 #ifdef _LCD_IF_4BIT
228 /*
229  * 4bit Interface, Used Below:
230  * PORTD: RD0 : RS
231  *        RD1 : RW
232  *        RD2 : EN
233  *        RD4-RD7: DATA(4-7).
234  */
235  #ifndef _LCDPORT_DATA
236 #define _LCDPORT_DATA PORTD
237 #define _LCDPORT_TRIS_DATA TRISD
238 #define _LCDPORT_LATCH_DATA LATD
239 #define _LCDPORT_BUSYMASK 0b10000000
240 #define _LCDPORT_READMASK TRIS_D_RVAL
241 #define _LCDPORT_DATA_SHIFT 4
242  #endif
243
244  #ifndef _LCDPORT_CONT
245 #define _LCDPORT_CONT PORTD
246 #define _LCDPORT_TRIS_CONT TRISD
247 #define _LCDPORT_CONT_LATCH LATD
248 #define _LCDPORT_CONT_RSbit b0
249 #define _LCDPORT_CONT_RWbit b1
250 #define _LCDPORT_CONT_ENbit b2
251 #define _LCDPORT_CONT_BLbit b3
252 #ifdef __SDCC
253 #define _LCDPORT_CONT_RS _PORTD_RD0
254 #define _LCDPORT_CONT_RW _PORTD_RD1
255 #define _LCDPORT_CONT_EN _PORTD_RD2
256 #else
257 #define _LCDPORT_CONT_RS _PORTD_RD0_MASK
258 #define _LCDPORT_CONT_RW _PORTD_RD1_MASK
259 #define _LCDPORT_CONT_EN _PORTD_RD2_MASK
260 #endif
261 #endif
262
263 #else
264 /*
265  * 8bit Interface, Used Below:
266  * PORTE: RE0 : RS
267  *        RE1 : RW
268  *        RE2 : EN
269  * PORTD: RD0-RD7: DATA(0-7).
270  */
271 // 8bit I/F
272  #ifndef _LCDPORT_DATA
273 #define _LCDPORT_DATA PORTD
274 #define _LCDPORT_TRIS_DATA TRISD
275 #define _LCDPORT_LATCH_DATA LATD
276 #define _LCDPORT_BUSYMASK 0b10000000
277 #define _LCDPORT_READMASK TRIS_D_RVAL
278  #endif
279
280  #ifndef _LCDPORT_CONT
281 #define _LCDPORT_CONT PORTE
282 #define _LCDPORT_TRIS_CONT TRISE
283 #define _LCDPORT_CONT_RSbit 0
284 #define _LCDPORT_CONT_RWbit 1
285 #define _LCDPORT_CONT_ENbit 2
286 #define _LCDPORT_CONT_RS _PORTE_RE0
287 #define _LCDPORT_CONT_RW _PORTE_RE1
288 #define _LCDPORT_CONT_EN _PORTE_RE2
289 #define _LCDPORT_CONT_LATCH LATE
290  #endif
291 #endif
292
293 #ifdef  __cplusplus
294 }
295 #endif
296
297 #endif  /* IODEF_H */
298