4 * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2,
9 * or (at your option) any later version.
10 * This library / program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this library; see the file COPYING. If not, write to the
17 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 * As a special exception, if you link this(includeed from sdcc) library
21 * with other files, some of which are compiled with SDCC,
22 * to produce an executable, this library does not by itself cause
23 * the resulting executable to be covered by the GNU General Public License.
24 * This exception does not however invalidate any other reasons why
25 * the executable file might be covered by the GNU General Public License.
30 keyin_defs keyin_old[2];
41 for(i = 0; i < 3; i++) {
42 keyin_old[0].byte[i] = 0x00;
43 keyin_old[1].byte[i] = 0x00;
44 keyin_now.byte[i] = 0x00;
46 for(i = 0; i < 16; i++) keyin_fifo[i] = 0x00;
53 #if defined(__18F23K22) || defined(__18F24K22) || defined(__18F25K22) || defined(__18F26K22)
55 void keyin_ioinit(void)
57 /* Initialize IOPORTS*/
73 #elif defined(__18F43K20) || defined(__18F44K20) || defined(__18F45K20) || defined(__18F46K20)
75 void keyin_ioinit(void)
77 /* Initialize IOPORTS*/
80 ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
93 void keyin_ioinit(void)
95 /* Initialize IOPORTS*/
98 // ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
108 TRISC = TRIS_C_VAL_O;
112 * Push to keyin fifo; not used atomic-writing.
114 void push_keyinfifo(char b) __critical
117 if((keyin_nowp > 15) || (keyin_nowp < 0))keyin_nowp = 0;
118 keyin_fifo[keyin_nowp] = b;
120 if(keyin_counter > 16) keyin_counter = 16;
124 * Pop from keyin fifo; not used atomic-reading.
126 char pop_keyinfifo(void) __critical
129 if(keyin_counter <= 0) {
131 return charcode_null ;
133 if(keyin_readp > 15) keyin_readp = 15;
134 c = keyin_fifo[keyin_readp];
136 if(keyin_readp > 15) keyin_readp = 0;
138 if(keyin_counter < 0)keyin_counter = 0;
142 void print_numeric(int i)
152 unsigned char supress = 0;
161 _PUTCHAR((l & 0x0f)+ '0');
167 _PUTCHAR((l & 0x0f)+ '0');
169 _PUTCHAR((l & 0x0f)+ '0');
176 _PUTCHAR((l & 0x0f)+ '0');
178 _PUTCHAR((l & 0x0f)+ '0');
185 _PUTCHAR((l & 0x0f)+ '0');
187 _PUTCHAR((l & 0x0f)+ '0');
191 _PUTCHAR((i & 0x0f) + '0');
197 void printstr(char *s)
201 if(s == NULL) return;
203 if(s[p] == '\0') break;
209 void setsignal_tune(unsigned char flag)
218 void set_backlight(unsigned char flag, unsigned int val)
229 * Read IOPORTS for KEY.
231 void readkey_io(void)
234 unsigned char portvar;
235 unsigned char latchvar;
238 if(keyin_counter > 16) keyin_counter = 0;
239 for(i = 0; i < 3; i++){
240 keyin_old[1].byte[i] = keyin_old[0].byte[i];
241 keyin_old[0].byte[i] = keyin_now.byte[i];
242 keyin_now.byte[i] = 0x00;
245 latchvar = LATA | 0x02;
248 low = (portvar & 0x3c) >>2;
249 latchvar = LATA & 0xfd;
252 latchvar = LATB | 0x02;
255 high = (portvar & 0x3c) >>2;
256 latchvar = LATB & 0xfd;
259 keyin_now.byte[0] = (low << 4) | high;
262 latchvar = LATB | 0x04;
265 low = (portvar & 0x3c) >>2;
266 latchvar = LATB & 0xfb;
269 latchvar = LATB | 0x20;
272 high = (portvar & 0x3c) >>2;
273 latchvar = LATB & 0xdf;
276 keyin_now.byte[1] = (low << 4) | high;
279 keyin_now.BIT0F = PORTBbits.RB1;
280 keyin_now.BIT1F = PORTBbits.RB2;
281 keyin_now.BIT2F = PORTBbits.RB3;
282 keyin_now.BIT3F = 0; // Reserve
285 unsigned char readkey_compare(void)
295 for(d = 0; d < 3; d++) {
297 for(b = 0; b < 8; b++){
299 if((keyin_now.byte[c] & shift) != 0) c++;
300 if((keyin_old[0].byte[c] & shift) != 0) c++;
301 if((keyin_old[1].byte[c] & shift) != 0) c++;
304 * Clear older-inputs on .
307 keyin_old[0].byte[c] &= ~shift;
308 keyin_old[1].byte[c] &= ~shift;
309 keyin_now.byte[c] &= ~shift;
311 push_keyinfifo(charcode_0);
315 push_keyinfifo(e + 1);
328 * Initialize sequence:
333 * In interrupt/unsleep hook(call per Nms):
337 * In application handler:
338 * c = pop_keyinfifo();