OSDN Git Service

[POWER] Wait correct time on idle(), idle_time_ms().
[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
67 #if defined(_18F23K22) || defined(_18F24K22) || defined(_18F25K22) || defined(_18F26K22)
68 #define _I2C_IO_TWO_MSSPS
69 #define _PIO_HAS_THREE
70 #endif
71
72 #if defined(_18F23K20) || defined(_18F24K20) || defined(_18F25K20) || defined(_18F26K20)
73 #define _I2C_IO_ONE_MSSP
74 #define _PIO_HAS_THREE
75 #endif
76
77 #if defined(_18F43K20) || defined(_18F44K20) || defined(_18F45K20) || defined(_18F46K20)
78 #define _I2C_IO_ONE_MSSP
79 #define _PIO_HAS_FIVE
80 #endif
81 #endif
82
83 /*
84  * MAP OF IOPORT
85  *
86  * RE3: VPP (ICSP Programming Voltage) / MCLR, Dont use for I/O.
87  *
88  * PORTA/B/C USED basic.
89  *
90  * PORTA:
91  *        RA0 : KO0
92  *        RA1 : KO1
93  *        RA2 : KO2
94  *        RA3 : KO7
95  *        RA2-RA5 : READ
96  *        RA6-RA7 : Used for CLOCK, connect to 8MHz resonator.
97  *
98  * PORTB:
99  *        RB0 : KI0
100  *        RB1 : KI1
101  *        RB2 : KI2
102  *        RB3 : KI3
103  *        RB4 : Power Key
104  *        RB5-RB7 : FOR ICSP
105  *
106  * PORTC: 
107  *        RC0 : RF AMP SEL bit0
108  *        RC1 : LCD-Backlight
109  *        RC2 : RF AMP SEL bit1
110  *        RC3-RC4 : SCL/SDA
111  *        RC5 : Reserved
112  *        RC6-RC7 : USART
113  *
114  * In addition, usage of PARALLEL-LCD,You should use 40Pin(or greater) PIC.
115  * ON 4BIT LCD I/F:
116  *
117  * PORTD: 
118  *        RD0: LCD RS
119  *        RD1: LCD RW
120  *        RD2: LCD EN
121  *        RD3: POWER LAMP
122  *        RD4-RD7: LCD DB4-DB7
123  *
124  * PORTE:
125  *        RE0:
126  *        RE1:
127  *        RE2: ADC(IN) to measure battery
128  *        RE3: VPP (ICSP Programming Voltage) / MCLR
129  */
130
131 #define TRIS_A_VAL   0b11000000
132 #define AN_A_VAL     0b00000000
133 #define TRIS_B_VAL   0b11111111 /* PORTB as INPUT.*/
134 #define AN_B_VAL     0b00000000
135 #define TRIS_C_VAL_O 0b00011000 /* FOR I2C-WRITE */
136 #define TRIS_C_VAL_I  0b00011000 /* FOR I2C-WRITE */
137 #define AN_C_VAL     0b00000000
138 #define TRIS_D_VAL   0b00000000 /* FOR OUTPUT, LCD(Optional) */
139 #ifdef _LCD_IF_4BIT
140  #define TRIS_D_RVAL 0xf0 /* FOR INPUT*/
141 #else
142  #define TRIS_D_RVAL 0b11111111 /* FOR INPUT*/
143 #endif
144 #define TRIS_E_VAL   0b00000100 /* FOR OUTPUT, ADC, PSP=OFF */
145 #define _BATT_ADC AN7
146 #define _ADC_INITF ANS7
147 #define _ADCH_INITF 0x00
148 #define _PORT_MUTE LATEbits.LATE0
149 #define _PORT_RADIOPOW LATEbits.LATE1
150 //#ifdef __SDCC
151 #define _LCD_BACKLIGHT LATC
152 #define _LCD_BACKLIGHT_BIT b1
153 #define _LCD_BACKLIGHT_TRIS TRISC
154 //#else
155 //#define _LCD_BACKLIGHT _PORTC_RC2_MASK
156 //#endif // __SDCC
157
158 #define _LCD_PORT LATC
159
160 /*
161  * RF Preamp
162  */
163     enum {
164         RFAMP_FM = 1,
165         RFAMP_MWLW = 2,
166         RFAMP_SW = 1
167         /* 3 = Reserve*/
168     };
169 #define _RFAMP_SEL_B0 LATCbits.LATC0
170 #define _RFAMP_SEL_B1 LATCbits.LATC2
171
172 #define _AM_STATLAMP  LATAbits.LATA4
173 #define _FM_STATLAMP  LATAbits.LATA5
174 #define _POW_STATLAMP LATDbits.LATD3
175
176
177 #define _KEY_SENDPORT LATA
178 #define _KEY_RECVPORT PORTB
179 #define _KEY_GRP1MASK 0x01
180 #define _KEY_GRP2MASK 0x02
181 #define _KEY_GRP3MASK 0x04
182 #define _KEY_GRP4MASK 0x08
183 #define _KEY_SENDPORTMASK (_KEY_GRP1MASK | _KEY_GRP2MASK | _KEY_GRP3MASK | _KEY_GRP4MASK)
184 #define _KEY_SEND_GRP1 LATAbits.LATA0
185 #define _KEY_SEND_GRP2 LATAbits.LATA1
186 #define _KEY_SEND_GRP3 LATAbits.LATA2
187 #define _KEY_SEND_GRP4 LATAbits.LATA3
188 #define _KEY_POS1MASK(p) p.b0
189 #define _KEY_POS2MASK(p) p.b1
190 #define _KEY_POS3MASK(p) p.b2
191 #define _KEY_POS4MASK(p) p.b3
192
193 typedef  union {
194     struct {
195     unsigned BIT0A:1;
196     unsigned BIT1A:1;
197     unsigned BIT2A:1;
198     unsigned BIT3A:1;
199
200     unsigned BIT0B:1;
201     unsigned BIT1B:1;
202     unsigned BIT2B:1;
203     unsigned BIT3B:1;
204
205     unsigned BIT0C:1;
206     unsigned BIT1C:1;
207     unsigned BIT2C:1;
208     unsigned BIT3C:1;
209
210     unsigned BIT0D:1;
211     unsigned BIT1D:1;
212     unsigned BIT2D:1;
213     unsigned BIT3D:1;
214
215     };
216     unsigned char byte[2];
217 } keyin_defs;
218
219 enum {
220     charcode_null = 0,
221     charcode_1,
222     charcode_2,
223     charcode_3,
224     charcode_4,
225     charcode_5,
226     charcode_6,
227     charcode_7,
228     charcode_8,
229     charcode_9,
230     charcode_a,
231     charcode_b,
232     charcode_c,
233     charcode_d,
234     charcode_e,
235     charcode_f,
236     charcode_0,
237     // Special keys was removed.
238 };
239
240 /*
241  * LCD Control: Default register values, You should re-define in iodef.h if you need.
242  */
243
244
245 #ifdef _LCD_IF_4BIT
246 /*
247  * 4bit Interface, Used Below:
248  * PORTD: RD0 : RS
249  *        RD1 : RW
250  *        RD2 : EN
251  *        RD4-RD7: DATA(4-7).
252  */
253 #ifndef _LCDPORT_DATA
254 #define _LCDPORT_DATA PORTD
255 #define _LCDPORT_TRIS_DATA TRISD
256 #define _LCDPORT_LATCH_DATA LATD
257 #define _LCDPORT_BUSYMASK 0b10000000
258 #define _LCDPORT_READMASK TRIS_D_RVAL
259 #define _LCDPORT_DATA_SHIFT 4
260 #endif
261
262 #ifndef _LCDPORT_CONT
263 #define _LCDPORT_CONT PORTD
264 #define _LCDPORT_TRIS_CONT TRISD
265 #define _LCDPORT_CONT_LATCH LATD
266 #define _LCDPORT_CONT_RSbit b0
267 #define _LCDPORT_CONT_RWbit b1
268 #define _LCDPORT_CONT_ENbit b2
269 #define _LCDPORT_CONT_BLbit b3
270 #define _LCDPORT_CONT_RS LATDbits.LATD0
271 #define _LCDPORT_CONT_RW LATDbits.LATD1
272 #define _LCDPORT_CONT_EN LATDbits.LATD2
273 #endif
274
275 #else
276 /*
277  * 8bit Interface, Used Below:
278  * PORTE: RE0 : RS
279  *        RE1 : RW
280  *        RE2 : EN
281  * PORTD: RD0-RD7: DATA(0-7).
282  */
283 // 8bit I/F
284  #ifndef _LCDPORT_DATA
285 #define _LCDPORT_DATA PORTD
286 #define _LCDPORT_TRIS_DATA TRISD
287 #define _LCDPORT_LATCH_DATA LATD
288 #define _LCDPORT_BUSYMASK 0b10000000
289 #define _LCDPORT_READMASK TRIS_D_RVAL
290  #endif
291
292  #ifndef _LCDPORT_CONT
293 #define _LCDPORT_CONT PORTE
294 #define _LCDPORT_TRIS_CONT TRISE
295 #define _LCDPORT_CONT_RSbit 0
296 #define _LCDPORT_CONT_RWbit 1
297 #define _LCDPORT_CONT_ENbit 2
298 #define _LCDPORT_CONT_RS _PORTE_RE0
299 #define _LCDPORT_CONT_RW _PORTE_RE1
300 #define _LCDPORT_CONT_EN _PORTE_RE2
301 #define _LCDPORT_CONT_LATCH LATE
302  #endif
303 #endif
304
305 #ifdef  __cplusplus
306 }
307 #endif
308
309 #endif  /* IODEF_H */
310