3 * Config & Main routine.
4 * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
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.
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,
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.
34 #include <pic18fregs.h> /* ONLY FOR PIC18x */
42 #include "lcd_acm1602.h"
48 #if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
49 #pragma stack 0x200 256 // Set stack size to 256bytes.
50 #pragma config FOSC=INTIO67,BORV=190,BOREN=ON,PWRTEN=ON
51 #pragma config WDTEN=ON,WDTPS=32768
52 #pragma config PBADEN=OFF,MCLRE=EXTMCLR,STVREN=ON,LVP=OFF,DEBUG=ON//,XINST=ON
53 #pragma config CP0=OFF,CP1=OFF,CPB=OFF,CPD=OFF
54 #pragma config WRT0=OFF,WRT1=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF
55 #pragma config EBTR0=OFF,EBTR1=OFF,EBTRB=OFF
57 // For 4xK20 or 2xK20 Series
58 #if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20) || \
59 defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
60 #pragma stack 0x200 256
61 #pragma config FOSC=INTIO67,FCMEN=ON,PWRT=ON,BOREN=ON,BORV=22
62 #pragma config WDTEN=ON,WDTPS=32768,PBADEN=OFF,LPT1OSC=ON,MCLRE=ON
63 #pragma config STVREN=ON,DEBUG=ON
64 #pragma config CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF
65 #pragma config CPB=OFF,CPD=OFF
66 #pragma config WRT0=OFF,WRT1=OFF,WRT2=OFF,WRT3=OFF
67 #pragma config WRTC=OFF,WRTB=OFF,WRTD=OFF
68 #pragma config EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF
71 //#define _LCD_DEBUG 1
73 SIGHANDLER(TMR0_handler)
86 // Clear interrupt flag
95 DEF_INTLOW(intlow_handler)
96 DEF_HANDLER(SIG_TMR0, TMR0_handler)
102 unsigned char amband;
103 unsigned char fmband;
105 unsigned char am_mode3k;
106 unsigned char am_userbandnum;
107 unsigned char fm_userbandnum;
113 _userband_t am_usrbands[4];
114 _userband_t fm_usrbands[4];
116 unsigned char enter_mode;
117 unsigned char numeric_mode;
118 unsigned char menu_node;
120 unsigned char help_flag;
124 unsigned int ui_idlecount;
127 int backlight_counter;
128 unsigned char backlight_level;
132 void toggle_amfm(void)
138 akc6955_set_amband(amband);
139 akc6955_set_freq(amfreq);
145 akc6955_set_fmband(fmband);
146 akc6955_set_freq(fmfreq);
151 void update_display(void)
155 if(fmband < AKC6955_BAND_TV1) {
157 _PUTCHAR('1' + (fmband & 7));
158 } else if(fmband < AKC6955_BAND_FMUSER){
160 _PUTCHAR('1' + fmband - AKC6955_BAND_TV1);
166 if(amband == AKC6955_BAND_LW) {
168 } else if(amband <AKC6955_BAND_SW1) { //MW
170 _PUTCHAR('1' + amband - AKC6955_BAND_MW1);
171 } else if(amband < AKC6955_BAND_AMUSER) { //MW
173 _PUTCHAR('1' + amband - AKC6955_BAND_SW1);
174 } else if(amband == AKC6955_BAND_MW4){
188 int freq_lo = fmfreq % 100;
189 int freq_hi = fmfreq / 100;
190 print_numeric(freq_hi);
192 print_numeric(freq_lo);
194 print_numeric(amfreq);
199 print_numeric(recv_signal);
203 void setfreq_updown(unsigned char ctlword)
207 case charcode_8: // Change band
210 if(amband > 18) amband = 0;
211 // amfreq = akc6955_setfreq(amfreq)
212 akc6955_set_amband(amband);
213 _AKC6955_WAIT_62_5MS(); // 62.5ms
214 amband = akc6955_get_amband();
215 amfreq = akc6955_get_freq();
218 if(fmband > 7) fmband = 0;
219 // amfreq = akc6955_setfreq(amfreq)
220 akc6955_set_fmband(fmband);
221 _AKC6955_WAIT_62_5MS(); // 62.5ms
222 fmband = akc6955_get_fmband();
223 fmfreq = akc6955_get_freq();
226 case charcode_2: // Change band
229 if(amband == 0) amband = 18;
230 if(amband >= 18) amband = 18;
231 // amfreq = akc6955_setfreq(amfreq)
232 akc6955_set_amband(amband);
233 _AKC6955_WAIT_62_5MS(); // 62.5ms
234 amband = akc6955_get_amband();
235 amfreq = akc6955_get_freq();
238 if(fmband == 0) fmband = 7;
239 if(fmband >= 7) fmband = 7;
240 // amfreq = akc6955_setfreq(amfreq)
241 akc6955_set_fmband(fmband);
242 _AKC6955_WAIT_62_5MS(); // 62.5ms
243 fmband = akc6955_get_fmband();
244 fmfreq = akc6955_get_freq();
247 case charcode_4: // Down Freq;
249 fmfreq = akc6955_down_freq(10); // DOWN 100KHz
251 amfreq = akc6955_down_freq(10); // DOWN 10KHz
254 case charcode_6: // Down Freq;
256 fmfreq = akc6955_up_freq(10); // UP 100KHz
258 amfreq = akc6955_up_freq(10); // UP 10KHz
261 case charcode_7: // Down Fast;
263 fmfreq = akc6955_down_freq(50); // DOWN 500KHz
265 amfreq = akc6955_down_freq(50); // DOWN 50KHz
268 case charcode_9: // Down Fast;
270 fmfreq = akc6955_up_freq(50); // UP 100KHz
272 amfreq = akc6955_up_freq(50); // UP 10KHz
275 case charcode_1: // Down Slow;
277 fmfreq = akc6955_down_freq(5); // DOWN 50KHz
279 amfreq = akc6955_down_freq(5); // DOWN 50KHz
282 case charcode_3: // Down Slow;
284 fmfreq = akc6955_up_freq(5); // UP 50KHz
286 amfreq = akc6955_up_freq(5); // UP 5KHz
289 case charcode_0: // Step
296 amfreq = akc6955_mode3k(am_mode3k);
299 case charcode_a: // Toggle FM
310 case charcode_e: // Backlight ON
311 backlight_counter = backlight_long;
314 // Toggle Numeric/Padkey(NO Numeric is not entered)
327 unsigned char input_flag;
330 unsigned char power_flag;
338 _AKC6955_WAIT_125_0MS(); // Wait 125ms
342 backlight_long = 256;
343 backlight_counter = backlight_long;
344 backlight_level = 255;
345 ui_idlecount = 0xf800;
347 acm1602_init(0xa0, 1); //Init LCD
348 // _AKC6955_WAIT_125_0MS(); // Wait 125ms
350 printstr("Hello;-)");
355 fmfreq = 8000; // 10KHz order.
356 amband = AKC6955_BAND_MW2;
357 fmband = AKC6955_BAND_FM2;
363 for(i = 0; i < 4; i++){
364 am_usrbands[i].start = 0x19;
365 am_usrbands[i].stop = 0x32;
367 for(i = 0; i < 4; i++){
368 fm_usrbands[i].start = 0x19;
369 fm_usrbands[i].stop = 0x32;
373 /* Push default parameters to AKC6955*/
376 akc6955_chg_fm(fm); // Set to AM
377 akc6955_set_amband(amband);
378 akc6955_set_freq(amfreq); // Dummy, TBS (954KHz)
379 akc6955_set_power(0xff); // Power ON
389 input_flag = readkey_compare();
391 readchar = pop_keyinfifo();
393 // Top of input-tree.
400 backlight_counter = backlight_long;
408 case charcode_null: // None
411 // Numeric 0to9, or a to f.
412 setfreq_updown(readchar);
417 recv_signal = akc6955_read_level();
419 fmfreq = akc6955_get_freq();
421 amfreq = akc6955_get_freq();
424 // Check battery (include idle?)
425 // Read AKJC6955's status
429 if(backlight_counter > 0) {
431 set_backlight(0xff, backlight_level); // Turn ON
433 set_backlight(0x00, 0); // Turn OFF
436 if(power_flag != 0x00) {
441 setsignal_tune(power_flag);