4 * Copyright (C) 2013-06-20 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.
27 #include "commondef.h"
31 unsigned char statecount;
33 void set_amfmlamp(unsigned char f)
45 void set_examp_mute(unsigned char f)
48 _PORT_MUTE = 0; // Not Mute
54 void set_radiopower(unsigned char f)
57 _PORT_RADIOPOW = 0; // OFF
59 _PORT_RADIOPOW = 1; // ON
63 void set_powerlamp(unsigned char f)
72 void lcd_setbacklight(unsigned char flag, unsigned char level)
77 d.byte = _LCD_BACKLIGHT_TRIS;
78 d._LCD_BACKLIGHT_BIT = 0;
79 _LCD_BACKLIGHT_TRIS = d.byte;
81 b.byte = _LCD_BACKLIGHT;
82 b._LCD_BACKLIGHT_BIT = 0;
84 b._LCD_BACKLIGHT_BIT = 1;
86 _LCD_BACKLIGHT = b.byte;
89 d.byte = _LCD_BACKLIGHT_TRIS;
90 d._LCD_BACKLIGHT_BIT = 1;
91 _LCD_BACKLIGHT_TRIS = d.byte;
102 // level = (level * 25) / 10;
105 if(h == CCPR1L) return;
106 // l = 2 << 4; //(lv & 0x0300) >> 4;
107 d.byte = _LCD_BACKLIGHT_TRIS;
108 d._LCD_BACKLIGHT_BIT = 1;
109 _LCD_BACKLIGHT_TRIS = d.byte;
118 T2CON = 0b01111000; // Pre-scaler=1/1,Post-scaler = 1/16
119 // -> Freq = 2.44KHz * 16 = 39.4KHz.
121 T2CONbits.TMR2ON = 1;
124 } while(PIR1bits.TMR2IF ==0);
125 d.byte = _LCD_BACKLIGHT_TRIS;
126 d._LCD_BACKLIGHT_BIT = 0;
127 _LCD_BACKLIGHT_TRIS = d.byte;
129 // _LCD_PORT |= _LCD_BACKLIGHT;
138 T3CONbits.TMR3ON = 1;
141 void io_intcountinit(void)
144 T3CON = 0b10001100; // TMR3 = 16bit, CCP is not use TMR3, Prescaler=1:2(1uS)
145 // DO-not-use SYNC, Internal clock, TMR3 temporally off.
148 IPR2bits.TMR3IP = 0; // Low priority.
156 void lcd_backlightinit(void)
159 PSTRCON = 0b00000001; // P1A = PWM, P1B~P1D=PORT, Steeling sync to PWM.
160 CCP1CON = 0b00001100; // PWM, Low-Active.
161 ECCP1AS = 0b10000111; // Auto shutdown is disabled
162 // Use TMR2 as source.
163 PIE1 &= ~0b00000010; // TMR2 Interrupt disabled.
164 PIR1 &= ~0b00000010; // TMR2 Interrupt clear.
165 IPR1 &= ~0b00000010; // Priority = LOW
166 T2CON = 0b00000011; // Prescaler/Postscaler = 1:1, Temporally disabled TMR2.
167 TMR2 = 0x00; // Value;
168 PR2 = 0x65; // 19.61KHz
169 CCPR1L = 100; // Duty = 100;
174 #if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
176 * For 28Pin PIC(18F2xK22), I2C lcd using.
179 void keyin_ioinit(void)
181 /* Initialize IOPORTS*/
195 TRISC = TRIS_C_VAL_O;
201 #if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
203 * For 28Pin PIC(18F2xK20), I2C lcd using.
206 void keyin_ioinit(void)
208 /* Initialize IOPORTS*/
211 ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
221 TRISC = TRIS_C_VAL_O;
227 #if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20)
229 * For 40Pin PIC(18F4xK20), paralell or I2C lcd using.
231 void keyin_ioinit(void)
233 /* Initialize IOPORTS*/
236 ANSEL = 0x80; // Use RA7 AS ADC, Another is not used.
246 TRISC = TRIS_C_VAL_O;
249 * You can use PORTD,RE0-RE2 extention, when using I2C lcd.
256 PORTE = 0b00000000; // Mute OK
259 INTCONbits.INT0IE = 0;
260 INTCONbits.INT0IF = 0;
261 INTCON3bits.INT1IF = 0;
262 INTCON3bits.INT2IF = 0;
263 INTCON3bits.INT1IE = 0;
264 INTCON3bits.INT2IE = 0;
270 void keyin_ioinit(void)
272 /* Initialize IOPORTS*/
275 // ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
285 TRISC = TRIS_C_VAL_O;
292 * Read IOPORTS for KEY. You should modify if you modify circuit.
294 void readkey_io(unsigned char state)
301 for(i = 0; i < 2; i++){
302 keyin_old[1].byte[i] = keyin_old[0].byte[i];
303 keyin_old[0].byte[i] = keyin_now.byte[i];
304 keyin_now.byte[i] = 0x00;
306 _KEY_SENDPORT |= _KEY_SENDPORTMASK; // Group1 DOWN.
309 _KEY_SEND_GRP1 = 0; // Group1 DOWN.
312 portvar.byte = _KEY_RECVPORT;
313 if(!_KEY_POS1MASK(portvar)) {
316 if(!_KEY_POS2MASK(portvar)) {
319 if(!_KEY_POS3MASK(portvar)) {
322 if(!_KEY_POS4MASK(portvar)) {
325 _KEY_SENDPORT |= _KEY_SENDPORTMASK; // Group1 DOWN.
328 _KEY_SEND_GRP2 = 0; // Group2 DOWN.
331 portvar.byte = _KEY_RECVPORT;
332 if(!_KEY_POS1MASK(portvar)) {
335 if(!_KEY_POS2MASK(portvar)) {
338 if(!_KEY_POS3MASK(portvar)) {
341 if(!_KEY_POS4MASK(portvar)) {
344 _KEY_SENDPORT |= _KEY_SENDPORTMASK; // Group1 DOWN.
347 _KEY_SEND_GRP3 = 0; // Group1 DOWN.
350 portvar.byte = _KEY_RECVPORT;
351 if(!_KEY_POS1MASK(portvar)) {
354 if(!_KEY_POS2MASK(portvar)) {
357 if(!_KEY_POS3MASK(portvar)) {
360 if(!_KEY_POS4MASK(portvar)) {
363 _KEY_SENDPORT |= _KEY_SENDPORTMASK; // Group1 DOWN.
366 _KEY_SEND_GRP4 = 0; // Group4 up
369 portvar.byte = _KEY_RECVPORT;
370 if(!_KEY_POS1MASK(portvar)) {
373 if(!_KEY_POS2MASK(portvar)) {
376 if(!_KEY_POS3MASK(portvar)) {
379 if(!_KEY_POS4MASK(portvar)) {
382 _KEY_SENDPORT |= _KEY_SENDPORTMASK; // Group1 DOWN.