OSDN Git Service

[UI] Split ui-depend routines from main.c.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 28 Jun 2013 08:29:05 +0000 (17:29 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 28 Jun 2013 08:29:05 +0000 (17:29 +0900)
eepromutil.c [new file with mode: 0644]
i2c_io.c
main.c
menu.h
menu_defs.c [new file with mode: 0644]
nbproject/Makefile-default.mk
nbproject/Makefile-genesis.properties
nbproject/configurations.xml
radio_getstat.c [new file with mode: 0644]
ui_display.c [new file with mode: 0644]
ui_updown.c [new file with mode: 0644]

diff --git a/eepromutil.c b/eepromutil.c
new file mode 100644 (file)
index 0000000..f8ba144
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * OpenI2CRADIO
+ * EEPROM utils
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <signal.h>
+#include <delay.h>
+
+#include "commondef.h"
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+#include "menu.h"
+#include "power.h"
+#include "adc_int.h"
+
+void save_eeprom(void)
+{
+    unsigned int p = 0;
+    unsigned int sum = 0x0000;
+    unsigned char i;
+
+    // Magic word
+    writeword_eeprom(p, &sum, 0x1298);
+    p+= 2;
+    // amfreq
+    writeword_eeprom(p, &sum, amfreq);
+    p+= 2;
+    // amfreq
+    writeword_eeprom(p, &sum, fmfreq);
+    p+= 2;
+
+    writebyte_eeprom(p, &sum, amband);
+    p++;
+    writebyte_eeprom(p, &sum, fmband);
+    p++;
+    writebyte_eeprom(p, &sum, fm);
+    p++;
+    writebyte_eeprom(p, &sum, am_mode3k);
+    p++;
+    writebyte_eeprom(p, &sum, am_userbandnum);
+    p++;
+    writebyte_eeprom(p, &sum, fm_userbandnum);
+    p++;
+
+    for(i = 0 ; i < USER_BAND_NUM; i++){
+        writebyte_eeprom(p, &sum, am_usrbands[i].mode3k);
+        writebyte_eeprom(p + 1, &sum, am_usrbands[i].start);
+        writebyte_eeprom(p + 2, &sum, am_usrbands[i].stop);
+        writeword_eeprom(p + 3, &sum, am_usrbands[i].freq);
+        p += 5;
+    }
+    for(i = 0 ; i < USER_BAND_NUM; i++){
+        writebyte_eeprom(p, &sum, fm_usrbands[i].mode3k);
+        writebyte_eeprom(p + 1, &sum, fm_usrbands[i].start);
+        writebyte_eeprom(p + 2, &sum, fm_usrbands[i].stop);
+        writeword_eeprom(p + 3, &sum, fm_usrbands[i].freq);
+        p += 5;
+    }
+    for(i = 0; i < 19; i++){
+        writeword_eeprom(p    , &sum, amfreq_bank[i]);
+        p += 2;
+    }
+    for(i = 0; i < 8; i++){
+        writeword_eeprom(p    , &sum, fmfreq_bank[i]);
+        p += 2;
+    }
+    writebyte_eeprom(p, &sum, threshold);
+    p++;
+    writebyte_eeprom(p, &sum, lowboost);
+    p++;
+    writebyte_eeprom(p, &sum, stereo);
+    p++;
+    // Write checksum
+    eeprom_writebyte(p, sum >> 8);
+    eeprom_writebyte(p + 1, sum & 0xff);
+}
+
+unsigned char load_eeprom(void)
+{
+    unsigned int p = 0;
+    unsigned int sum = 0x0000;
+    unsigned char i;
+    unsigned int magic;
+
+    // Magic word
+    magic = readword_eeprom(p, &sum);
+    if(magic != 0x1298) return 0x01; // NO MAGICWORD
+    p+= 2;
+    // amfreq
+    amfreq = readword_eeprom(p, &sum);
+    p+= 2;
+    // fmfreq
+    fmfreq = readword_eeprom(p, &sum);
+    p+= 2;
+
+    amband = readbyte_eeprom(p, &sum);
+    p++;
+    fmband = readbyte_eeprom(p, &sum);
+    p++;
+    fm = readbyte_eeprom(p, &sum);
+    p++;
+    am_mode3k = readbyte_eeprom(p, &sum);
+    p++;
+    am_userbandnum = readbyte_eeprom(p, &sum);
+    p++;
+    fm_userbandnum = readbyte_eeprom(p, &sum);
+    p++;
+
+    for(i = 0 ; i < USER_BAND_NUM; i++){
+        am_usrbands[i].mode3k = readbyte_eeprom(p, &sum);
+        am_usrbands[i].start  = readbyte_eeprom(p + 1, &sum);
+        am_usrbands[i].stop   = readbyte_eeprom(p + 2, &sum);
+        am_usrbands[i].freq   = readword_eeprom(p + 3, &sum);
+        p += 5;
+    }
+    for(i = 0 ; i < USER_BAND_NUM; i++){
+        fm_usrbands[i].mode3k = readbyte_eeprom(p, &sum);
+        fm_usrbands[i].start  = readbyte_eeprom(p + 1, &sum);
+        fm_usrbands[i].stop   = readbyte_eeprom(p + 2, &sum);
+        fm_usrbands[i].freq   = readword_eeprom(p + 3, &sum);
+        p += 5;
+    }
+    for(i = 0; i < 19; i++){
+        amfreq_bank[i] = readword_eeprom(p    , &sum);
+        p += 2;
+    }
+    for(i = 0; i < 8; i++){
+        fmfreq_bank[i] = readword_eeprom(p    , &sum);
+        p += 2;
+    }
+    threshold = readbyte_eeprom(p    , &sum);
+    p++;
+    lowboost = readbyte_eeprom(p    , &sum);
+    p++;
+    stereo = readbyte_eeprom(p    , &sum);
+    p++;
+    // Write checksum
+    magic = (eeprom_readbyte(p) << 8) + eeprom_readbyte(p+1);
+
+    p+= 2;
+    if(sum != magic) return 0x00;
+    return 0xff;
+}
+
+/*
+ * Check eeprom, and format/restore.
+ */
+void check_eeprom(void)
+{
+    unsigned char c;
+        switch(load_eeprom()) {
+        case 0x01: // No magic-word
+            idle_time_ms(2000);
+            c = printhelp_2lines("EEPROM FORMAT", "Press any key");
+            _CLS();
+            _LOCATE(0,0);
+            printstr("Formatting...  ");
+            format_eeprom(2,250);
+            _LOCATE(0,0);
+            printstr("Save defaults  ");
+            setdefault();
+            save_eeprom();
+            break;
+        case 0x00: // Checksum error
+           idle_time_ms(2000);
+            c = printhelp_2lines("X-) Sum error", "Press any key");
+            c = pollkey_single();
+            _CLS();
+            _LOCATE(0,0);
+            printstr("Formatting...");
+            format_eeprom(2,250);
+//            writeword_eeprom(0, &sum, 0x1298);
+            _LOCATE(0,0);
+            printstr("Save defaults");
+            setdefault();
+            save_eeprom();
+            break;
+        case 0xff: // Success
+            break;
+        default: // Unknown error
+            setdefault();
+            break;
+    }
+
+}
index 621b9b3..3aaee49 100644 (file)
--- a/i2c_io.c
+++ b/i2c_io.c
@@ -54,7 +54,7 @@ void i2c2_init(void)
  #ifdef _I2C_IO_ONE_MSSP
 void i2c1_init(void)
 {
-    unsigned char b;
//   unsigned char b;
 //    b = _SSPEN | _SSPM3;
 //    SSPCON1 = b;
 //    SSPADD = 19; // Fosc:8000[KHz] / (4 * I2C:Clock:100[KHz]) - 1
diff --git a/main.c b/main.c
index a9aba8c..2db8756 100644 (file)
--- a/main.c
+++ b/main.c
 //#pragma config WRTC=OFF,WRTB=OFF,WRTD=OFF
 //#pragma config EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF
 #endif
-unsigned int amfreq;
-unsigned int fmfreq;
-unsigned int amfreq_bank[AKC6955_BAND_AMEND];
-unsigned int fmfreq_bank[AKC6955_BAND_FMEND];
-
-const banddesc ambands[19] = {
-    {150,285},
-    {520,1710},
-    {522,1620},
-    {520,1710},
-    {4700, 10000},
-    {3200, 4100},
-    {4700, 5600},
-    {5700, 6400},
-    {6800, 7600},
-    {9200, 10000},
-    {11400,12200},
-    {13500,14300},
-    {15000,15900},
-    {17400,17900},
-    {18900,19700},
-    {21400,21900},
-    {11400, 17900},
-    {4000,8000}, // USER
-    {520,1730}
-};
-const
-const banddesc fmbands[8] = {
-    {8700, 10800},
-    {7600, 10800},
-    {7000, 9300},
-    {7600, 9000},
-    {6400, 8800},
-    {5625, 9175},
-    {17475, 22225},
-    {5000, 7000} // User
-};
-unsigned char amband;
-unsigned char fmband;
-unsigned char fm;
-unsigned char am_mode3k;
-unsigned char am_userbandnum;
-unsigned char fm_userbandnum;
-unsigned char threshold; // Reg 0x08
-_userband_t am_usrbands[USER_BAND_NUM];
-_userband_t fm_usrbands[USER_BAND_NUM];
-banddesc am_userband_freq[USER_BAND_NUM];
-banddesc fm_userband_freq[USER_BAND_NUM];
-unsigned char stereo;
-unsigned char volume;
-unsigned char prevolume;
-unsigned char fmbandwidth;
-unsigned char lowboost;
-
-int backlight_long;
-unsigned int ui_idlecount;
-unsigned char scanflag;
 
 /*
  * Statuses
@@ -244,526 +187,6 @@ DEF_INTHIGH(inthigh_handler)
 END_DEF
 
 
-
-
-void save_eeprom(void)
-{
-    unsigned int p = 0;
-    unsigned int sum = 0x0000;
-    unsigned char i;
-
-    // Magic word
-    writeword_eeprom(p, &sum, 0x1298);
-    p+= 2;
-    // amfreq
-    writeword_eeprom(p, &sum, amfreq);
-    p+= 2;
-    // amfreq
-    writeword_eeprom(p, &sum, fmfreq);
-    p+= 2;
-
-    writebyte_eeprom(p, &sum, amband);
-    p++;
-    writebyte_eeprom(p, &sum, fmband);
-    p++;
-    writebyte_eeprom(p, &sum, fm);
-    p++;
-    writebyte_eeprom(p, &sum, am_mode3k);
-    p++;
-    writebyte_eeprom(p, &sum, am_userbandnum);
-    p++;
-    writebyte_eeprom(p, &sum, fm_userbandnum);
-    p++;
-
-    for(i = 0 ; i < USER_BAND_NUM; i++){
-        writebyte_eeprom(p, &sum, am_usrbands[i].mode3k);
-        writebyte_eeprom(p + 1, &sum, am_usrbands[i].start);
-        writebyte_eeprom(p + 2, &sum, am_usrbands[i].stop);
-        writeword_eeprom(p + 3, &sum, am_usrbands[i].freq);
-        p += 5;
-    }
-    for(i = 0 ; i < USER_BAND_NUM; i++){
-        writebyte_eeprom(p, &sum, fm_usrbands[i].mode3k);
-        writebyte_eeprom(p + 1, &sum, fm_usrbands[i].start);
-        writebyte_eeprom(p + 2, &sum, fm_usrbands[i].stop);
-        writeword_eeprom(p + 3, &sum, fm_usrbands[i].freq);
-        p += 5;
-    }
-    for(i = 0; i < 19; i++){
-        writeword_eeprom(p    , &sum, amfreq_bank[i]);
-        p += 2;
-    }
-    for(i = 0; i < 8; i++){
-        writeword_eeprom(p    , &sum, fmfreq_bank[i]);
-        p += 2;
-    }
-    writebyte_eeprom(p, &sum, threshold);
-    p++;
-    writebyte_eeprom(p, &sum, lowboost);
-    p++;
-    writebyte_eeprom(p, &sum, stereo);
-    p++;
-    // Write checksum
-    eeprom_writebyte(p, sum >> 8);
-    eeprom_writebyte(p + 1, sum & 0xff);
-}
-
-unsigned char load_eeprom(void)
-{
-    unsigned int p = 0;
-    unsigned int sum = 0x0000;
-    unsigned char i;
-    unsigned int magic;
-
-    // Magic word
-    magic = readword_eeprom(p, &sum);
-    if(magic != 0x1298) return 0x01; // NO MAGICWORD
-    p+= 2;
-    // amfreq
-    amfreq = readword_eeprom(p, &sum);
-    p+= 2;
-    // fmfreq
-    fmfreq = readword_eeprom(p, &sum);
-    p+= 2;
-
-    amband = readbyte_eeprom(p, &sum);
-    p++;
-    fmband = readbyte_eeprom(p, &sum);
-    p++;
-    fm = readbyte_eeprom(p, &sum);
-    p++;
-    am_mode3k = readbyte_eeprom(p, &sum);
-    p++;
-    am_userbandnum = readbyte_eeprom(p, &sum);
-    p++;
-    fm_userbandnum = readbyte_eeprom(p, &sum);
-    p++;
-
-    for(i = 0 ; i < USER_BAND_NUM; i++){
-        am_usrbands[i].mode3k = readbyte_eeprom(p, &sum);
-        am_usrbands[i].start  = readbyte_eeprom(p + 1, &sum);
-        am_usrbands[i].stop   = readbyte_eeprom(p + 2, &sum);
-        am_usrbands[i].freq   = readword_eeprom(p + 3, &sum);
-        p += 5;
-    }
-    for(i = 0 ; i < USER_BAND_NUM; i++){
-        fm_usrbands[i].mode3k = readbyte_eeprom(p, &sum);
-        fm_usrbands[i].start  = readbyte_eeprom(p + 1, &sum);
-        fm_usrbands[i].stop   = readbyte_eeprom(p + 2, &sum);
-        fm_usrbands[i].freq   = readword_eeprom(p + 3, &sum);
-        p += 5;
-    }
-    for(i = 0; i < 19; i++){
-        amfreq_bank[i] = readword_eeprom(p    , &sum);
-        p += 2;
-    }
-    for(i = 0; i < 8; i++){
-        fmfreq_bank[i] = readword_eeprom(p    , &sum);
-        p += 2;
-    }
-    threshold = readbyte_eeprom(p    , &sum);
-    p++;
-    lowboost = readbyte_eeprom(p    , &sum);
-    p++;
-    stereo = readbyte_eeprom(p    , &sum);
-    p++;
-    // Write checksum
-    magic = (eeprom_readbyte(p) << 8) + eeprom_readbyte(p+1);
-
-    p+= 2;
-    if(sum != magic) return 0x00;
-    return 0xff;
-}
-
-
-
-void update_status(void)
-{
-
-    unsigned int adc;
-    fm = akc6955_get_fm();
-
-        recv_signal = akc6955_read_level();
-        diffstat = akc6955_get_diff();
-        volume = akc6955_getvolume();
-        prevolume = akc6955_get_prevolume();
-        if(fm != 0){
-            fmfreq = akc6955_get_freq();
-            fmband = akc6955_get_fmband();
-            stereoflag = akc6955_get_stereo();
-        } else {
-            amfreq = akc6955_get_freq();
-            amband = akc6955_get_amband();
-            stereoflag = 0x00;
-        }
-#if 1
-        tuneflag = akc6955_tune();
-        cnrlevel = akc6955_get_cnr();
-//        batlevel_6955 = akc6955_get_battery();
-        akc6955_get_fmbandwidth(fmbandwidth);
-#else
-        batlevel_6955 = 330;
-#endif
-    batlevel_6955 = 330;
-    startadc(7);
-    idle_time_ms(1);
-    polladc2(adc);
-    battlevel = adc_rawtobatt(adc, batlevel_6955);
-//    battlevel = adc;
-}
-
-void print_freq(unsigned char y)
-{
-    int freq;
-    int freq_lo;
-    int freq_hi;
-    _LOCATE(0,y);
-    if(fm != 0){ // FM
-        if(fmband < AKC6955_BAND_TV1) {
-            printstr("FM");
-            _PUTCHAR('1' + (fmband & 7));
-            printstr("  ");
-        } else if(fmband < AKC6955_BAND_FMUSER){
-            printstr("TV");
-            _PUTCHAR('1' + fmband - AKC6955_BAND_TV1);
-            printstr("  ");
-        } else { // USER
-            printstr("FMU");
-            _PUTCHAR('0' + fm_userbandnum);
-            _PUTCHAR(' ');
-        }
-    } else { // AM
-        if(amband == AKC6955_BAND_LW) {
-            printstr("LW");
-        } else if(amband <AKC6955_BAND_SW1) { //MW
-            printstr("MW");
-            _PUTCHAR('1' + amband - AKC6955_BAND_MW1);
-            printstr("  ");
-        } else if(amband <AKC6955_BAND_SW10) { //MW
-            printstr("SW");
-            _PUTCHAR('1' + amband - AKC6955_BAND_SW1);
-            printstr("  ");
-        } else if(amband < AKC6955_BAND_AMUSER) { //MW
-            printstr("SW1");
-            _PUTCHAR('0' + amband - AKC6955_BAND_SW10);
-            _PUTCHAR(' ');
-        } else if(amband == AKC6955_BAND_MW4){
-            printstr("MW4  ");
-        } else {
-            printstr("AMU");
-            _PUTCHAR('0' + am_userbandnum);
-            _PUTCHAR(' ');
-        }
-     }
-//     _LOCATE(15-5 ,1);
-     _LOCATE(16-3-6, y);
-     if(fm != 0){
-         if(stereoflag != 0){
-             printstr("ST");
-         } else {
-             printstr("  ");
-         }
-         freq = fmfreq + diffstat / 100;
-         freq_lo = freq % 100;
-         freq_hi = freq / 100;
-         print_numeric_nosupress(freq_hi, 3);
-         _PUTCHAR('.');
-         print_numeric_nosupress(freq_lo, 2);
-     } else {
-         freq = amfreq + diffstat / 10;
-         printstr("   ");
-         print_numeric_nosupress(freq, 5);
-     }
-     // Signal
-     _LOCATE(16-3, y);
-     if(fm != 0){
-         printstr("MHz");
-     } else {
-         printstr("KHz");
-     }
-}
-
-void update_display(void)
-{
-
-    unsigned int vol;
-    int lv;
-//    _HOME();
-    _LOCATE(0,0);
-    printstr("S");
-    if(recv_signal < 0){
-        _PUTCHAR('-');
-        lv = - recv_signal;
-        print_numeric_nosupress(lv / 20, 1);
-    } else {
-        lv = recv_signal;
-        print_numeric_nosupress(lv / 20, 1); // MAX=123
-        _PUTCHAR(' ');
-    }
-    if(fm == 0){
-        set_amlamp(1);
-        set_fmlamp(0);
-    } else {
-        set_amlamp(0);
-        set_fmlamp(1);
-    }
-     // vol = volume * 1.5 + prevolume * 3.5[dB]
-     if(volume > 24) {
-         vol = volume - 24;
-         vol = (vol * 3 + prevolume * 7) / 2;
-         printstr("V:");
-         print_numeric_nosupress(vol,2);
-     } else {
-         printstr("MUTE");
-     }
-
-     _LOCATE(16-5,0);
-     print_numeric_nosupress(battlevel / 100, 1);
-     _PUTCHAR('.');
-     print_numeric_nosupress(battlevel % 100, 2);
-     _PUTCHAR('V');
-     print_freq(1);
-//    _PUTCHAR(' ');
-    _HOME();
-}
-
-
-void setfreq_updown(unsigned char ctlword)
-{
-    switch(ctlword){
-        case charcode_8: // Change band
-                if(fm == 0){
-                    amfreq_bank[amband] = amfreq;
-                    if(amband >= AKC6955_BAND_MW4) {
-                        amband = 0;
-                    } else {
-                        amband++;
-                    }
-                    amfreq = amfreq_bank[amband];
-                akc6955_set_amband(amband);
-                akc6955_set_freq(amfreq);
-                idle_time_62_5ms(); // 62.5ms
-                amband = akc6955_get_amband();
-                amfreq = akc6955_get_freq();
-            } else {
-                    fmfreq_bank[fmband] = fmfreq;
-                    if(fmband >= AKC6955_BAND_FMUSER) {
-                        fmband = 0;
-                    } else {
-                        fmband++;
-                    }
-                    fmfreq = fmfreq_bank[fmband];
-                    akc6955_set_fmband(fmband);
-                    idle_time_62_5ms(); // 62.5ms
-                    akc6955_set_freq(fmfreq);
-                    fmband = akc6955_get_fmband();
-                    fmfreq = akc6955_get_freq();
-            }
-            break;
-        case charcode_2: // Change band
-                if(fm == 0){
-                    amfreq_bank[amband] = amfreq;
-                    if(amband == 0) {
-                        amband = AKC6955_BAND_MW4;
-                    } else if(amband > AKC6955_BAND_MW4) {
-                        amband = AKC6955_BAND_MW4;
-                    } else {
-                        amband--;
-                    }
-                    amfreq = amfreq_bank[amband];
-                akc6955_set_amband(amband);
-                akc6955_set_freq(amfreq);
-                    idle_time_62_5ms(); // 62.5ms
-                amband = akc6955_get_amband();
-                amfreq = akc6955_get_freq();
-            } else {
-                    fmfreq_bank[fmband] = fmfreq;
-                    if(fmband == 0) {
-                       fmband = AKC6955_BAND_FMUSER;
-                    } else if(fmband > AKC6955_BAND_FMUSER) {
-                        fmband = AKC6955_BAND_FMUSER;
-                    } else {
-                        fmband--;
-                    }
-                    fmfreq = fmfreq_bank[fmband];
-                    akc6955_set_fmband(fmband);
-                    idle_time_62_5ms(); // 62.5ms
-                    akc6955_set_freq(fmfreq);
-                    fmband = akc6955_get_fmband();
-                    fmfreq = akc6955_get_freq();
-            }
-            break;
-        case charcode_4: // Down Freq;
-            if(fm != 0){
-                fmfreq = akc6955_down_freq(25); // DOWN 250KHz
-            } else {
-                 amfreq = akc6955_down_freq(30); // DOWN 30KHz
-            }
-            break;
-        case charcode_6: // Down Freq;
-            if(fm != 0){
-    //            fmfreq += 10;
-                fmfreq = akc6955_up_freq(25); // UP 250KHz
-            } else {
-    //            amfreq += 10;
-                amfreq = akc6955_up_freq(30); // UP 30KHz
-            }
-            break;
-        case charcode_9: // Down Fast;
-            if(fm != 0){
-      //          fmfreq += 50;
-                fmfreq = akc6955_up_freq(50); // DOWN 500KHz
-            } else {
-      //          amfreq += 50;
-                amfreq = akc6955_up_freq(100); // DOWN 100KHz
-            }
-            break;
-        case charcode_7: // Down Fast;
-            if(fm != 0){
-//                fmfreq -= 50;
-                fmfreq = akc6955_down_freq(50); // UP 500KHz
-            } else {
-//                amfreq -= 50;
-                amfreq = akc6955_down_freq(100); // UP 10KHz
-            }
-            break;
-        case charcode_1: // Down Slow;
-            if(fm != 0){
-  //              fmfreq -= 3;
-                fmfreq = akc6955_down_freq(3); // DOWN 30KHz
-            } else {
-  //              amfreq -= 3;
-                if(amband == AKC6955_BAND_MW2) {
-                    amfreq = akc6955_down_freq(9);
-                } else if(amband == AKC6955_BAND_MW3) {
-                    amfreq = akc6955_down_freq(10);
-                } else if(am_mode3k == 0x00) {
-                    amfreq = akc6955_down_freq(3); // DOWN 50KHz
-                } else {
-                    amfreq = akc6955_down_freq(5); // DOWN 50KHz
-                }
-            }
-            break;
-        case charcode_3: // Down Slow;
-            if(fm != 0){
-//                fmfreq += 3;
-                fmfreq = akc6955_up_freq(3); // UP 30KHz
-            } else {
-//                amfreq += 3;
-                if(amband == AKC6955_BAND_MW2){
-                    amfreq = akc6955_up_freq(9);
-                } else if(amband == AKC6955_BAND_MW3) {
-                    amfreq = akc6955_up_freq(10);
-                } else if(am_mode3k == 0x00) {
-                    amfreq = akc6955_up_freq(3); // DOWN 50KHz
-                } else {
-                    amfreq = akc6955_up_freq(5); // DOWN 50KHz
-                }
-            }
-            break;
-        case charcode_0: // Step
-            if(fm == 0){
-                if(am_mode3k == 0) {
-                    am_mode3k = 0xff;
-                } else {
-                    am_mode3k = 0;
-                }
-                amfreq = akc6955_mode3k(am_mode3k);
-            }
-            break;
-        case charcode_a: // Toggle FM
-            toggle_amfm();
-            break;
-        case charcode_b:
-            set_volume();
-            break;
-        case charcode_c:
-            // Scan
-            scan_start();
-            break;
-        case charcode_d:
-            // FM Narrow/Wide
-            set_stereo();
-            break;
-        case charcode_e: // Backlight ON/OFF
-            if(backlight_counter > 0) {
-              backlight_counter = 0;
-           } else {
-              backlight_counter = backlight_long;
-           }
-            break;
-        case charcode_5:
-            main_menu();
-            break;
-        case charcode_f:
-            updown_help();
-            _CLS();
-            _LOCATE(0,0);
-            break;
-        default:
-            break;
-    }
-}
-/*
- * 
- */
-void setdefault(void)
-{
-    char i;
-    //amfreq = 954;
-    //fmfreq = 8000; // 10KHz order.
-    amband = AKC6955_BAND_MW2;
-    fmband = AKC6955_BAND_FM2;
-    am_mode3k = 0xff;
-    fm = 0;
-    am_userbandnum = 0;
-    fm_userbandnum = 0;
-    lowboost = 0xff;
-    threshold = 0b01011000;
-    for(i = 0; i < 4; i++){
-        am_usrbands[i].start = 0x19;
-        am_usrbands[i].stop  = 0x32;
-    }
-    for(i = 0; i < 4; i++){
-        fm_usrbands[i].start = 0x19;
-        fm_usrbands[i].stop  = 0x32;
-    }
-    for(i =0; i < 18; i++){
-      amfreq_bank[i] = ((ambands[i].end - ambands[i].start) >> 1) + ambands[i].start;
-    }
-    for(i =0; i < 8; i++){
-      fmfreq_bank[i] = ((fmbands[i].end - fmbands[i].start) >> 1) + fmbands[i].start;
-    }
-    fmfreq = fmfreq_bank[fmband];
-    amfreq = amfreq_bank[amband];
-    stereo = 0xff; // Auto
-}
-
-void valinit(void)
-{
-        // UI
-    backlight_long = 256;
-    backlight_counter = backlight_long;
-    backlight_level = 255;
-    ui_idlecount = 250; // 0.25Sec
-    // Statuses
-    scanflag = 0;
-    cnrlevel = 0;
-    recv_signal = 103;
-    battlevel = 0;
-    batlevel_6955 = 330; // 3.30V(temporally).
-    if(amband > 18) amband = 18;
-    if(fmband > 7) fmband = 7;
-    if(am_userbandnum >= USER_BAND_NUM) am_userbandnum = USER_BAND_NUM - 1;
-    if(fm_userbandnum >= USER_BAND_NUM) fm_userbandnum = USER_BAND_NUM - 1;
-    volume = 0;
-    prevolume = 0;
-    fmbandwidth = 0;
-    diffstat = 0;
-    cnrlevel = 103;
-    stereoflag = 0x00; // Auto
-}
-
 int main(void)
 {
     unsigned char c;
@@ -816,53 +239,7 @@ int main(void)
     printstr("Hello;-)");
     lcd_setbacklight(0xff, 100);
     idle_time_ms(1000);
-#if 1
-    switch(load_eeprom()) {
-        case 0x01: // No magic-word
-            idle_time_ms(2000);
-            _CLS();
-            setdefault();
-            _LOCATE(0,0);
-            printstr("EEPROM FORMATTING");
-            _LOCATE(0,1);
-            printstr("Press any key");
-            c = pollkey_single();
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Formatting...");
-            format_eeprom(2,250);
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Save defaults");
-            setdefault();
-            save_eeprom();
-            break;
-        case 0x00: // Checksum error
-           idle_time_ms(2000);
-           _CLS();
-            _LOCATE(0,0);
-            printstr("X-) Sum Error");
-            _LOCATE(0,1);
-            printstr("Press any key to format");
-            c = pollkey_single();
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Formatting...");
-            format_eeprom(2,250);
-//            writeword_eeprom(0, &sum, 0x1298);
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Save defaults");
-            setdefault();
-            save_eeprom();
-            break;
-        case 0xff: // Success
-            break;
-        default: // Unknown error
-            setdefault();
-            break;
-    }
-#endif
+    check_eeprom();
     // Init AKC6955
     /* Check EEPROM */
     /* Push default parameters to AKC6955*/
diff --git a/menu.h b/menu.h
index 6f0aec2..9f15ad0 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -101,6 +101,8 @@ extern "C" {
     extern void update_status(void);
     extern void save_eeprom(void);
     extern unsigned char load_eeprom(void);
+    extern void check_eeprom(void);
+
     extern void setfreq_updown(unsigned char ctlword);
     extern void setdefault(void);
 
@@ -118,10 +120,15 @@ extern "C" {
     extern void scan_start(void);
     extern void set_volume(void);
     extern void toggle_amfm(void);
+
+    extern unsigned char printhelp_2lines(char *l1, char *l2);
+    extern void setup_menu(void);
     extern void updown_help(void);
     extern void mainmenu_help(void);
     extern void print_freq(unsigned char y);
     extern void setup_akc6955(void);
+    extern void setdefault(void);
+    extern void valinit(void);
 
 #ifdef __cplusplus
 }
diff --git a/menu_defs.c b/menu_defs.c
new file mode 100644 (file)
index 0000000..8a54872
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * OpenI2CRADIO
+ * defines.
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <signal.h>
+#include <delay.h>
+
+#include "commondef.h"
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+#include "menu.h"
+#include "power.h"
+#include "adc_int.h"
+
+
+const banddesc ambands[19] = {
+    {150,285},
+    {520,1710},
+    {522,1620},
+    {520,1710},
+    {4700, 10000},
+    {3200, 4100},
+    {4700, 5600},
+    {5700, 6400},
+    {6800, 7600},
+    {9200, 10000},
+    {11400,12200},
+    {13500,14300},
+    {15000,15900},
+    {17400,17900},
+    {18900,19700},
+    {21400,21900},
+    {11400, 17900},
+    {4000,8000}, // USER
+    {520,1730}
+};
+const banddesc fmbands[8] = {
+    {8700, 10800},
+    {7600, 10800},
+    {7000, 9300},
+    {7600, 9000},
+    {6400, 8800},
+    {5625, 9175},
+    {17475, 22225},
+    {5000, 7000} // User
+};
+
+unsigned int amfreq;
+unsigned int fmfreq;
+unsigned int amfreq_bank[AKC6955_BAND_AMEND];
+unsigned int fmfreq_bank[AKC6955_BAND_FMEND];
+unsigned char amband;
+unsigned char fmband;
+unsigned char fm;
+unsigned char am_mode3k;
+unsigned char am_userbandnum;
+unsigned char fm_userbandnum;
+unsigned char threshold; // Reg 0x08
+_userband_t am_usrbands[USER_BAND_NUM];
+_userband_t fm_usrbands[USER_BAND_NUM];
+banddesc am_userband_freq[USER_BAND_NUM];
+banddesc fm_userband_freq[USER_BAND_NUM];
+unsigned char stereo;
+unsigned char volume;
+unsigned char prevolume;
+unsigned char fmbandwidth;
+unsigned char lowboost;
+
+int backlight_long;
+unsigned int ui_idlecount;
+unsigned char scanflag;
+
+
+/*
+ *
+ */
+void setdefault(void)
+{
+    char i;
+    //amfreq = 954;
+    //fmfreq = 8000; // 10KHz order.
+    amband = AKC6955_BAND_MW2;
+    fmband = AKC6955_BAND_FM2;
+    am_mode3k = 0xff;
+    fm = 0;
+    am_userbandnum = 0;
+    fm_userbandnum = 0;
+    lowboost = 0xff;
+    threshold = 0b01011000;
+    for(i = 0; i < 4; i++){
+        am_usrbands[i].start = 0x19;
+        am_usrbands[i].stop  = 0x32;
+    }
+    for(i = 0; i < 4; i++){
+        fm_usrbands[i].start = 0x19;
+        fm_usrbands[i].stop  = 0x32;
+    }
+    for(i =0; i < 18; i++){
+      amfreq_bank[i] = ((ambands[i].end - ambands[i].start) >> 1) + ambands[i].start;
+    }
+    for(i =0; i < 8; i++){
+      fmfreq_bank[i] = ((fmbands[i].end - fmbands[i].start) >> 1) + fmbands[i].start;
+    }
+    fmfreq = fmfreq_bank[fmband];
+    amfreq = amfreq_bank[amband];
+    stereo = 0xff; // Auto
+}
+
+void valinit(void)
+{
+        // UI
+    backlight_long = 256;
+    backlight_counter = backlight_long;
+    backlight_level = 255;
+    ui_idlecount = 250; // 0.25Sec
+    // Statuses
+    scanflag = 0;
+    cnrlevel = 0;
+    recv_signal = 103;
+    battlevel = 0;
+    batlevel_6955 = 330; // 3.30V(temporally).
+    if(amband > 18) amband = 18;
+    if(fmband > 7) fmband = 7;
+    if(am_userbandnum >= USER_BAND_NUM) am_userbandnum = USER_BAND_NUM - 1;
+    if(fm_userbandnum >= USER_BAND_NUM) fm_userbandnum = USER_BAND_NUM - 1;
+    volume = 0;
+    prevolume = 0;
+    fmbandwidth = 0;
+    diffstat = 0;
+    cnrlevel = 103;
+    stereoflag = 0x00; // Auto
+}
index a77a2a3..3cd164b 100644 (file)
@@ -45,11 +45,11 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
 # Object Files Quoted if spaced
-OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o ${OBJECTDIR}/power.o ${OBJECTDIR}/adc_int.o
-POSSIBLE_DEPFILES=${OBJECTDIR}/ui.o.d ${OBJECTDIR}/i2c_io.o.d ${OBJECTDIR}/main.o.d ${OBJECTDIR}/idle.o.d ${OBJECTDIR}/lcd_acm1602.o.d ${OBJECTDIR}/akc6955.o.d ${OBJECTDIR}/eeprom.o.d ${OBJECTDIR}/ioports.o.d ${OBJECTDIR}/menu.o.d ${OBJECTDIR}/power.o.d ${OBJECTDIR}/adc_int.o.d
+OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o ${OBJECTDIR}/power.o ${OBJECTDIR}/adc_int.o ${OBJECTDIR}/menu_defs.o ${OBJECTDIR}/eepromutil.o ${OBJECTDIR}/ui_updown.o ${OBJECTDIR}/ui_display.o ${OBJECTDIR}/radio_getstat.o
+POSSIBLE_DEPFILES=${OBJECTDIR}/ui.o.d ${OBJECTDIR}/i2c_io.o.d ${OBJECTDIR}/main.o.d ${OBJECTDIR}/idle.o.d ${OBJECTDIR}/lcd_acm1602.o.d ${OBJECTDIR}/akc6955.o.d ${OBJECTDIR}/eeprom.o.d ${OBJECTDIR}/ioports.o.d ${OBJECTDIR}/menu.o.d ${OBJECTDIR}/power.o.d ${OBJECTDIR}/adc_int.o.d ${OBJECTDIR}/menu_defs.o.d ${OBJECTDIR}/eepromutil.o.d ${OBJECTDIR}/ui_updown.o.d ${OBJECTDIR}/ui_display.o.d ${OBJECTDIR}/radio_getstat.o.d
 
 # Object Files
-OBJECTFILES=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o ${OBJECTDIR}/power.o ${OBJECTDIR}/adc_int.o
+OBJECTFILES=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o ${OBJECTDIR}/power.o ${OBJECTDIR}/adc_int.o ${OBJECTDIR}/menu_defs.o ${OBJECTDIR}/eepromutil.o ${OBJECTDIR}/ui_updown.o ${OBJECTDIR}/ui_display.o ${OBJECTDIR}/radio_getstat.o
 
 
 CFLAGS=
@@ -126,6 +126,31 @@ ${OBJECTDIR}/adc_int.o: adc_int.c  nbproject/Makefile-${CND_CONF}.mk
        ${RM} ${OBJECTDIR}/adc_int.o 
        ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 adc_int.c  -o${OBJECTDIR}/adc_int.o
        
+${OBJECTDIR}/menu_defs.o: menu_defs.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/menu_defs.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 menu_defs.c  -o${OBJECTDIR}/menu_defs.o
+       
+${OBJECTDIR}/eepromutil.o: eepromutil.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/eepromutil.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 eepromutil.c  -o${OBJECTDIR}/eepromutil.o
+       
+${OBJECTDIR}/ui_updown.o: ui_updown.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/ui_updown.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 ui_updown.c  -o${OBJECTDIR}/ui_updown.o
+       
+${OBJECTDIR}/ui_display.o: ui_display.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/ui_display.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 ui_display.c  -o${OBJECTDIR}/ui_display.o
+       
+${OBJECTDIR}/radio_getstat.o: radio_getstat.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/radio_getstat.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 radio_getstat.c  -o${OBJECTDIR}/radio_getstat.o
+       
 else
 ${OBJECTDIR}/ui.o: ui.c  nbproject/Makefile-${CND_CONF}.mk
        ${MKDIR} ${OBJECTDIR} 
@@ -182,6 +207,31 @@ ${OBJECTDIR}/adc_int.o: adc_int.c  nbproject/Makefile-${CND_CONF}.mk
        ${RM} ${OBJECTDIR}/adc_int.o 
        ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 adc_int.c  -o${OBJECTDIR}/adc_int.o
        
+${OBJECTDIR}/menu_defs.o: menu_defs.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/menu_defs.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 menu_defs.c  -o${OBJECTDIR}/menu_defs.o
+       
+${OBJECTDIR}/eepromutil.o: eepromutil.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/eepromutil.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 eepromutil.c  -o${OBJECTDIR}/eepromutil.o
+       
+${OBJECTDIR}/ui_updown.o: ui_updown.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/ui_updown.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 ui_updown.c  -o${OBJECTDIR}/ui_updown.o
+       
+${OBJECTDIR}/ui_display.o: ui_display.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/ui_display.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 ui_display.c  -o${OBJECTDIR}/ui_display.o
+       
+${OBJECTDIR}/radio_getstat.o: radio_getstat.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/radio_getstat.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small --obanksel=2 --optimize-cmp --optimize-df --opt-code-size    libc18f.lib libio18f45k20.lib -c -mpic16 -p18f45k20 radio_getstat.c  -o${OBJECTDIR}/radio_getstat.o
+       
 endif
 
 # ------------------------------------------------------------------------------------
index 60046fe..5c00157 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Fri Jun 28 14:10:41 JST 2013
+#Fri Jun 28 17:27:27 JST 2013
 default.languagetoolchain.dir=/usr/local/bin
 default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=8fe1589514540343a5279c082104bce0
index f0f073a..49d1c76 100644 (file)
     <itemPath>adc_int.c</itemPath>
     <itemPath>adc_int.h</itemPath>
     <itemPath>commondef.h</itemPath>
+    <itemPath>menu_defs.c</itemPath>
+    <itemPath>eepromutil.c</itemPath>
+    <itemPath>ui_updown.c</itemPath>
+    <itemPath>ui_display.c</itemPath>
+    <itemPath>radio_getstat.c</itemPath>
   </logicalFolder>
   <sourceRootList>
     <Elem>/usr/local/share/sdcc/lib/src/pic16/libc</Elem>
diff --git a/radio_getstat.c b/radio_getstat.c
new file mode 100644 (file)
index 0000000..a069564
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * OpenI2CRADIO
+ * Get status from chips.
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <signal.h>
+#include <delay.h>
+
+#include "commondef.h"
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+#include "menu.h"
+#include "power.h"
+#include "adc_int.h"
+
+
+void update_status(void)
+{
+
+    unsigned int adc;
+    fm = akc6955_get_fm();
+
+        recv_signal = akc6955_read_level();
+        diffstat = akc6955_get_diff();
+        volume = akc6955_getvolume();
+        prevolume = akc6955_get_prevolume();
+        if(fm != 0){
+            fmfreq = akc6955_get_freq();
+            fmband = akc6955_get_fmband();
+            stereoflag = akc6955_get_stereo();
+        } else {
+            amfreq = akc6955_get_freq();
+            amband = akc6955_get_amband();
+            stereoflag = 0x00;
+        }
+#if 1
+        tuneflag = akc6955_tune();
+        cnrlevel = akc6955_get_cnr();
+//        batlevel_6955 = akc6955_get_battery();
+        akc6955_get_fmbandwidth(fmbandwidth);
+#else
+        batlevel_6955 = 330;
+#endif
+    batlevel_6955 = 330;
+    startadc(7);
+    idle_time_ms(1);
+    polladc2(adc);
+    battlevel = adc_rawtobatt(adc, batlevel_6955);
+//    battlevel = adc;
+}
diff --git a/ui_display.c b/ui_display.c
new file mode 100644 (file)
index 0000000..4469b78
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * OpenI2CRADIO
+ * UI->LCD->Display status.
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <signal.h>
+#include <delay.h>
+
+#include "commondef.h"
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+#include "menu.h"
+#include "power.h"
+#include "adc_int.h"
+
+
+void print_freq(unsigned char y)
+{
+    int freq;
+    int freq_lo;
+    int freq_hi;
+    _LOCATE(0,y);
+    if(fm != 0){ // FM
+        if(fmband < AKC6955_BAND_TV1) {
+            printstr("FM");
+            _PUTCHAR('1' + (fmband & 7));
+            printstr("  ");
+        } else if(fmband < AKC6955_BAND_FMUSER){
+            printstr("TV");
+            _PUTCHAR('1' + fmband - AKC6955_BAND_TV1);
+            printstr("  ");
+        } else { // USER
+            printstr("FMU");
+            _PUTCHAR('0' + fm_userbandnum);
+            _PUTCHAR(' ');
+        }
+    } else { // AM
+        if(amband == AKC6955_BAND_LW) {
+            printstr("LW");
+        } else if(amband <AKC6955_BAND_SW1) { //MW
+            printstr("MW");
+            _PUTCHAR('1' + amband - AKC6955_BAND_MW1);
+            printstr("  ");
+        } else if(amband <AKC6955_BAND_SW10) { //MW
+            printstr("SW");
+            _PUTCHAR('1' + amband - AKC6955_BAND_SW1);
+            printstr("  ");
+        } else if(amband < AKC6955_BAND_AMUSER) { //MW
+            printstr("SW1");
+            _PUTCHAR('0' + amband - AKC6955_BAND_SW10);
+            _PUTCHAR(' ');
+        } else if(amband == AKC6955_BAND_MW4){
+            printstr("MW4  ");
+        } else {
+            printstr("AMU");
+            _PUTCHAR('0' + am_userbandnum);
+            _PUTCHAR(' ');
+        }
+     }
+//     _LOCATE(15-5 ,1);
+     _LOCATE(16-3-6, y);
+     if(fm != 0){
+         if(stereoflag != 0){
+             printstr("ST");
+         } else {
+             printstr("  ");
+         }
+         freq = fmfreq + diffstat / 100;
+         freq_lo = freq % 100;
+         freq_hi = freq / 100;
+         print_numeric_nosupress(freq_hi, 3);
+         _PUTCHAR('.');
+         print_numeric_nosupress(freq_lo, 2);
+     } else {
+         freq = amfreq + diffstat / 10;
+         printstr("   ");
+         print_numeric_nosupress(freq, 5);
+     }
+     // Signal
+     _LOCATE(16-3, y);
+     if(fm != 0){
+         printstr("MHz");
+     } else {
+         printstr("KHz");
+     }
+}
+
+void update_display(void)
+{
+
+    unsigned int vol;
+    int lv;
+//    _HOME();
+    _LOCATE(0,0);
+    printstr("S");
+    if(recv_signal < 0){
+        _PUTCHAR('-');
+        lv = - recv_signal;
+        print_numeric_nosupress(lv / 20, 1);
+    } else {
+        lv = recv_signal;
+        print_numeric_nosupress(lv / 20, 1); // MAX=123
+        _PUTCHAR(' ');
+    }
+    if(fm == 0){
+        set_amlamp(1);
+        set_fmlamp(0);
+    } else {
+        set_amlamp(0);
+        set_fmlamp(1);
+    }
+     // vol = volume * 1.5 + prevolume * 3.5[dB]
+     if(volume > 24) {
+         vol = volume - 24;
+         vol = (vol * 3 + prevolume * 7) / 2;
+         printstr("V:");
+         print_numeric_nosupress(vol,2);
+     } else {
+         printstr("MUTE");
+     }
+
+     _LOCATE(16-5,0);
+     print_numeric_nosupress(battlevel / 100, 1);
+     _PUTCHAR('.');
+     print_numeric_nosupress(battlevel % 100, 2);
+     _PUTCHAR('V');
+     print_freq(1);
+//    _PUTCHAR(' ');
+    _HOME();
+}
diff --git a/ui_updown.c b/ui_updown.c
new file mode 100644 (file)
index 0000000..18e6310
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * OpenI2CRADIO
+ * Up-down UI routine.
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <signal.h>
+#include <delay.h>
+
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+#include "menu.h"
+#include "power.h"
+#include "adc_int.h"
+
+void setfreq_updown(unsigned char ctlword)
+{
+    switch(ctlword){
+        case charcode_8: // Change band
+                if(fm == 0){
+                    amfreq_bank[amband] = amfreq;
+                    if(amband >= AKC6955_BAND_MW4) {
+                        amband = 0;
+                    } else {
+                        amband++;
+                    }
+                    amfreq = amfreq_bank[amband];
+                akc6955_set_amband(amband);
+                akc6955_set_freq(amfreq);
+                idle_time_62_5ms(); // 62.5ms
+                amband = akc6955_get_amband();
+                amfreq = akc6955_get_freq();
+            } else {
+                    fmfreq_bank[fmband] = fmfreq;
+                    if(fmband >= AKC6955_BAND_FMUSER) {
+                        fmband = 0;
+                    } else {
+                        fmband++;
+                    }
+                    fmfreq = fmfreq_bank[fmband];
+                    akc6955_set_fmband(fmband);
+                    idle_time_62_5ms(); // 62.5ms
+                    akc6955_set_freq(fmfreq);
+                    fmband = akc6955_get_fmband();
+                    fmfreq = akc6955_get_freq();
+            }
+            break;
+        case charcode_2: // Change band
+                if(fm == 0){
+                    amfreq_bank[amband] = amfreq;
+                    if(amband == 0) {
+                        amband = AKC6955_BAND_MW4;
+                    } else if(amband > AKC6955_BAND_MW4) {
+                        amband = AKC6955_BAND_MW4;
+                    } else {
+                        amband--;
+                    }
+                    amfreq = amfreq_bank[amband];
+                akc6955_set_amband(amband);
+                akc6955_set_freq(amfreq);
+                    idle_time_62_5ms(); // 62.5ms
+                amband = akc6955_get_amband();
+                amfreq = akc6955_get_freq();
+            } else {
+                    fmfreq_bank[fmband] = fmfreq;
+                    if(fmband == 0) {
+                       fmband = AKC6955_BAND_FMUSER;
+                    } else if(fmband > AKC6955_BAND_FMUSER) {
+                        fmband = AKC6955_BAND_FMUSER;
+                    } else {
+                        fmband--;
+                    }
+                    fmfreq = fmfreq_bank[fmband];
+                    akc6955_set_fmband(fmband);
+                    idle_time_62_5ms(); // 62.5ms
+                    akc6955_set_freq(fmfreq);
+                    fmband = akc6955_get_fmband();
+                    fmfreq = akc6955_get_freq();
+            }
+            break;
+        case charcode_4: // Down Freq;
+            if(fm != 0){
+                fmfreq = akc6955_down_freq(25); // DOWN 250KHz
+            } else {
+                 amfreq = akc6955_down_freq(30); // DOWN 30KHz
+            }
+            break;
+        case charcode_6: // Down Freq;
+            if(fm != 0){
+    //            fmfreq += 10;
+                fmfreq = akc6955_up_freq(25); // UP 250KHz
+            } else {
+    //            amfreq += 10;
+                amfreq = akc6955_up_freq(30); // UP 30KHz
+            }
+            break;
+        case charcode_9: // Down Fast;
+            if(fm != 0){
+      //          fmfreq += 50;
+                fmfreq = akc6955_up_freq(50); // DOWN 500KHz
+            } else {
+      //          amfreq += 50;
+                amfreq = akc6955_up_freq(100); // DOWN 100KHz
+            }
+            break;
+        case charcode_7: // Down Fast;
+            if(fm != 0){
+//                fmfreq -= 50;
+                fmfreq = akc6955_down_freq(50); // UP 500KHz
+            } else {
+//                amfreq -= 50;
+                amfreq = akc6955_down_freq(100); // UP 10KHz
+            }
+            break;
+        case charcode_1: // Down Slow;
+            if(fm != 0){
+  //              fmfreq -= 3;
+                fmfreq = akc6955_down_freq(3); // DOWN 30KHz
+            } else {
+  //              amfreq -= 3;
+                if(amband == AKC6955_BAND_MW2) {
+                    amfreq = akc6955_down_freq(9);
+                } else if(amband == AKC6955_BAND_MW3) {
+                    amfreq = akc6955_down_freq(10);
+                } else if(am_mode3k == 0x00) {
+                    amfreq = akc6955_down_freq(3); // DOWN 50KHz
+                } else {
+                    amfreq = akc6955_down_freq(5); // DOWN 50KHz
+                }
+            }
+            break;
+        case charcode_3: // Down Slow;
+            if(fm != 0){
+//                fmfreq += 3;
+                fmfreq = akc6955_up_freq(3); // UP 30KHz
+            } else {
+//                amfreq += 3;
+                if(amband == AKC6955_BAND_MW2){
+                    amfreq = akc6955_up_freq(9);
+                } else if(amband == AKC6955_BAND_MW3) {
+                    amfreq = akc6955_up_freq(10);
+                } else if(am_mode3k == 0x00) {
+                    amfreq = akc6955_up_freq(3); // DOWN 50KHz
+                } else {
+                    amfreq = akc6955_up_freq(5); // DOWN 50KHz
+                }
+            }
+            break;
+        case charcode_0: // Step
+            if(fm == 0){
+                if(am_mode3k == 0) {
+                    am_mode3k = 0xff;
+                } else {
+                    am_mode3k = 0;
+                }
+                amfreq = akc6955_mode3k(am_mode3k);
+            }
+            break;
+        case charcode_a: // Toggle FM
+            toggle_amfm();
+            break;
+        case charcode_b:
+            set_volume();
+            break;
+        case charcode_c:
+            // Scan
+            scan_start();
+            break;
+        case charcode_d:
+            // FM Narrow/Wide
+            set_stereo();
+            break;
+        case charcode_e: // Backlight ON/OFF
+            if(backlight_counter > 0) {
+              backlight_counter = 0;
+           } else {
+              backlight_counter = backlight_long;
+           }
+            break;
+        case charcode_5:
+            main_menu();
+            break;
+        case charcode_f:
+            updown_help();
+            _CLS();
+            _LOCATE(0,0);
+            break;
+        default:
+            break;
+    }
+}