OSDN Git Service

[UI][RENCODER] Use RB6 for ICSP/Rotary encoder.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 30 Oct 2013 12:48:27 +0000 (21:48 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 30 Oct 2013 12:48:27 +0000 (21:48 +0900)
[Schematic] Move power-lamp to AKCPOW, use of RS232C.
[RENCODER] Use interrupt to save battery.

gSCH/OpenI2CRadio-v1.00-p1.png
gSCH/OpenI2CRadio-v1.00-p1.sch
ioports.c
ioports.h
main.c
nbproject/Makefile-genesis.properties
power.c
rencoder.c
rencoder.h

index 1ffce96..3a8db6b 100644 (file)
Binary files a/gSCH/OpenI2CRadio-v1.00-p1.png and b/gSCH/OpenI2CRadio-v1.00-p1.png differ
index b42520b..c71a730 100644 (file)
@@ -26,7 +26,7 @@ device=CONNECTOR_2
 T 54900 47150 5 10 0 0 0 0 1
 footprint=SIP2N
 }
-U 53000 48600 53000 42800 10 1
+U 53000 48600 53000 45500 10 1
 N 50600 46200 52800 46200 4
 {
 T 52500 46300 5 10 1 1 0 0 1
@@ -141,14 +141,6 @@ device=none
 T 43900 46300 5 10 1 1 0 0 1
 net=FM_D
 }
-N 50600 42600 52800 42600 4
-C 52800 42600 1 0 0 busripper-1.sym
-{
-T 52800 43000 5 8 0 0 0 0 1
-device=none
-T 53000 42600 5 10 1 1 0 0 1
-net=POWD
-}
 C 56200 46800 1 180 1 connector10-2.sym
 {
 T 56900 47300 5 10 1 1 180 0 1
@@ -197,7 +189,7 @@ C 42100 44100 1 270 1 resonator-1.sym
 {
 T 43100 44400 5 10 0 0 90 2 1
 device=RESONATOR
-T 42500 43800 5 10 1 1 180 2 1
+T 42200 44700 5 10 1 1 180 2 1
 refdes=X1
 T 43300 44400 5 10 0 0 90 2 1
 symversion=0.1
@@ -342,9 +334,7 @@ C 47700 49100 1 0 0 gnd-2.sym
 N 50600 48000 53200 48000 4
 N 53200 48000 53200 49500 4
 N 53200 49500 55100 49500 4
-N 50600 47700 52800 47700 4
 N 55100 49200 52800 49200 4
-N 52800 49200 52800 47700 4
 N 50600 45000 55500 45000 4
 N 55500 45000 55500 45600 4
 N 55500 45600 56200 45600 4
@@ -429,7 +419,7 @@ value=15K
 }
 C 43100 49400 1 270 0 switch-pushbutton-no-1.sym
 {
-T 42900 48200 5 10 1 1 0 0 1
+T 43400 49000 5 10 1 1 0 0 1
 refdes=S1
 T 43700 49000 5 10 0 0 270 0 1
 device=SWITCH_PUSHBUTTON_NO
@@ -438,7 +428,7 @@ C 41900 47500 1 0 0 gnd-2.sym
 N 43100 48400 42000 48400 4
 N 42000 48400 42000 47800 4
 N 42000 50400 45200 50400 4
-T 42800 48000 9 10 1 0 0 0 1
+T 43400 48800 9 10 1 0 0 0 1
 RESET
 N 40800 46900 41300 46900 4
 N 42000 44500 42100 44500 4
@@ -457,12 +447,12 @@ T 51000 40100 9 10 1 0 0 0 1
 T 51500 40100 9 10 1 0 0 0 1
 9
 T 53900 40400 9 10 1 0 0 0 1
-2.01
+2.02
 T 53900 40000 9 10 1 0 0 0 2
 K.Ohta
   <whatisthis.sowhat@gmail.com>
 T 55900 40400 9 10 1 0 0 0 1
-Oct 24,2013
+Oct 30,2013
 G 55500 40772 1500 528 0 0 0
 /home/whatisthis/Bunsho/001_回路図/OpenI2CRadio/by-sa.png
 U 53000 48600 43600 48600 10 0
@@ -488,30 +478,30 @@ T 41400 44300 5 10 1 1 180 0 1
 net=TUN_D
 }
 N 40800 44100 41300 44100 4
-C 42700 45200 1 0 0 input-1.sym
+C 42300 45200 1 0 0 input-1.sym
 {
-T 42700 45500 5 10 0 0 0 0 1
+T 42300 45500 5 10 0 0 0 0 1
 device=INPUT
-T 41800 45200 5 10 1 1 0 0 1
+T 41800 45000 5 10 1 1 0 0 1
 net=VBATDET
 }
-C 43500 45500 1 0 1 output-1.sym
+C 43100 45500 1 0 1 output-1.sym
 {
-T 43400 45800 5 10 0 0 0 6 1
+T 43000 45800 5 10 0 0 0 6 1
 device=OUTPUT
-T 41800 45500 5 10 1 1 0 0 1
+T 41600 45700 5 10 1 1 0 0 1
 net=AKCPOW
 }
-C 43500 46000 1 180 0 output-1.sym
+C 43100 46000 1 180 0 output-1.sym
 {
-T 43400 45700 5 10 0 0 180 0 1
+T 43000 45700 5 10 0 0 180 0 1
 device=OUTPUT
-T 41800 45900 5 10 1 1 0 0 1
+T 41700 46100 5 10 1 1 0 0 1
 net=AMPMUTE
 }
-N 43500 45600 45200 45600 4
-N 43500 45300 45200 45300 4
-N 43500 45900 45200 45900 4
+N 43100 45600 45200 45600 4
+N 43100 45300 45200 45300 4
+N 43100 45900 45200 45900 4
 C 43800 41200 1 90 0 busripper-1.sym
 {
 T 43400 41200 5 8 0 0 90 0 1
@@ -697,22 +687,21 @@ value=0.1u
 N 46200 50600 46200 50300 4
 N 47800 50600 47800 50300 4
 C 46700 49100 1 0 0 gnd-2.sym
-C 51800 43100 1 0 1 input-1.sym
+C 52300 47600 1 0 1 input-1.sym
 {
-T 51800 43400 5 10 0 0 0 6 1
+T 52300 47900 5 10 0 0 0 6 1
 device=INPUT
-T 51800 43200 5 10 1 1 0 0 1
+T 52300 47700 5 10 1 1 0 0 1
 net=ROT_B
 }
-N 51000 43200 50600 43200 4
-C 52200 47300 1 0 1 input-1.sym
+C 52300 47300 1 0 1 input-1.sym
 {
-T 52200 47600 5 10 0 0 0 6 1
+T 52300 47600 5 10 0 0 0 6 1
 device=INPUT
-T 52200 47400 5 10 1 1 0 0 1
+T 52300 47400 5 10 1 1 0 0 1
 net=ROT_A
 }
-N 51400 47400 50600 47400 4
+N 51500 47400 50600 47400 4
 N 45200 50400 45200 50600 4
 C 51500 49200 1 90 0 resistor-1.sym
 {
@@ -732,8 +721,7 @@ refdes=R12
 T 51000 50300 5 10 1 1 180 0 1
 value=10K
 }
-N 51400 47400 51400 49200 4
-N 50900 49200 50900 43200 4
+N 50900 49200 50900 47700 4
 N 53600 47100 50600 47100 4
 T 51000 50600 9 10 1 0 0 0 1
 ※7
@@ -743,8 +731,6 @@ T 54700 50200 9 10 1 0 0 0 1
 ※7
 T 51300 47200 9 10 1 0 0 0 1
 ※7
-T 52600 43200 9 10 1 0 0 0 1
-※7
 T 46300 49500 9 10 1 0 0 0 1
 ※7
 T 47700 41100 9 10 1 0 0 0 1
@@ -832,3 +818,32 @@ device=PIC18F46K20_DIP40
 T 45500 48800 5 10 0 0 0 0 1
 footprint=DIP40
 }
+C 43300 46400 1 90 0 resistor-1.sym
+{
+T 42900 46700 5 10 0 0 90 0 1
+device=RESISTOR
+T 42900 47100 5 10 1 1 180 0 1
+refdes=R13
+T 42700 46700 5 10 1 1 0 0 1
+value=1K
+}
+C 43400 47600 1 0 0 busripper-1.sym
+{
+T 43400 48000 5 8 0 0 0 0 1
+device=none
+T 42900 47800 5 10 1 1 0 0 1
+net=POWD
+}
+N 43400 47600 43200 47600 4
+N 43200 47600 43200 47300 4
+N 43200 46400 43200 45600 4
+T 52500 42800 9 10 1 0 0 0 1
+※9
+T 51000 47800 9 10 1 0 0 0 1
+※9
+T 42800 47300 9 10 1 0 0 0 1
+※9
+T 47700 40700 9 10 1 0 0 0 1
+※9 2013-10-30
+N 51500 47700 50600 47700 4
+N 51400 49200 51400 47400 4
index eb645c3..09b7b4e 100644 (file)
--- a/ioports.c
+++ b/ioports.c
@@ -61,14 +61,6 @@ void set_radiopower(unsigned char f)
     }
 }
 
-void set_powerlamp(unsigned char f)
-{
-    if(f == 0x00) {
-        _POW_STATLAMP = 0;
-    } else {
-        _POW_STATLAMP = 1;
-    }
-}
 
 
 void TMR3_set(void)
index 8aa6318..e486e5b 100644 (file)
--- a/ioports.h
+++ b/ioports.h
@@ -43,7 +43,6 @@ extern "C" {
 #endif
 
 extern void set_amfmlamp(unsigned char f);
-extern void set_powerlamp(unsigned char f);
 extern void keyin_ioinit(void);
 extern void io_intcountinit(void);
 extern void TMR3_set(void);
diff --git a/main.c b/main.c
index d505a75..1f774e9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -128,10 +128,8 @@ void TMR1_Handler(void)
 SIGHANDLER(TMR1_Handler)
 #endif
 {
-#ifdef USE_RENCODER
-    rencoder_count();
-#endif   
-    rencoder_restart();
+//    rencoder_count();
+        rencoder_tmrhook();
 }
 
 #ifdef __XC
@@ -165,10 +163,11 @@ void RBIF_handler(void)
 SIGHANDLER(RBIF_handler)
 #endif
 {
-    power_on_inthook();
-//    if(chk_powerbutton(0, 0) != 0) { // If pressed on
-//      power_off(1); //
-//    }
+    if(IOCBbits.IOCB4 != 0) {
+        power_on_inthook();
+    } else {
+        rencoder_inthook();
+    }
 }
 #ifdef __XC
 void  EEPROM_handler(void)
@@ -308,7 +307,6 @@ int main(void)
     WDTCONbits.SWDTEN = 1; // WDT ON.
     power_on(1);
     //intadc_init();
-    set_powerlamp(1);
     valinit();
     acm1602_init(LCD_I2CADDR, 1); //Init LCD
     lcd_setbacklight(0xff, 255);
index 5ac7765..44f8339 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Thu Oct 24 15:56:48 JST 2013
+#Wed Oct 30 20:33:22 JST 2013
 default.languagetoolchain.dir=/opt/microchip/xc8/v1.21/bin
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=0d2b1469ad71adb787c711a416386331
 default.languagetoolchain.version=1.21
diff --git a/power.c b/power.c
index 7ece052..04d2895 100644 (file)
--- a/power.c
+++ b/power.c
@@ -156,7 +156,7 @@ void power_off(unsigned char savef)
         save_eeprom();
         save_userbands();
     }
-    set_powerlamp(0);
+//    set_powerlamp(0);
     _AM_STATLAMP = 0;
     _FM_STATLAMP = 0;
 
index 9a638f1..4340a09 100644 (file)
@@ -33,6 +33,8 @@ unsigned char renc_dir;
 unsigned int renc_count;
 static unsigned int renc_reset_count;
 //static unsigned char renc_penalty;
+unsigned char renc_flag;
+
 
 void rencoder_init(void)
 {
@@ -43,6 +45,7 @@ void rencoder_init(void)
    renc_state_a = RENC_PH_A;
    renc_state_b = RENC_PH_B;
    renc_reset_count = 0;
+   renc_flag = 0;
 //   renc_penalty = 0;
 }
 
@@ -51,8 +54,8 @@ void rencoder_restart(void)
 {
  //  T1CONbits.TMR1ON = 1;
    T1CON = 0b10110100;// RD16, T1RUN=0, 1/32 fOSC, TNR1CS=0, TMR1ON=0;
-   TMR1H = (65536 - 600) >> 8; // Tick = 4us, Count = 600(2.4ms)
-   TMR1L = (65536 - 600) & 255;
+   TMR1H = (65536 - 400) >> 8; // Tick = 4us, Count = 600(2.4ms)
+   TMR1L = (65536 - 400) & 255;
 //   T1CONbits.TMR1ON = 0;
    PIR1bits.TMR1IF = 0;
    PIE1bits.TMR1IE = 1;
@@ -64,7 +67,41 @@ void rencoder_start(void)
 {
     rencoder_stop();
     rencoder_init();
+//    rencoder_restart();
+    IOCB = 0b01100000; // RB5,RB6
+    INTCONbits.RBIF = 0;
+    INTCONbits.RBIE = 1;
+    INTCONbits.GIE = 1;
+    INTCONbits.PEIE = 1;
+
+}
+
+void rencoder_inthook(void)
+{
+//    IOCB = 0b01100000;
+//    IOCBbits.IOCB4 = 1;
+    INTCONbits.RBIF = 0;
+    if(renc_flag != 0) return;
+//    renc_state_a = RENC_PH_A;
+//    renc_state_b = RENC_PH_B;
+    renc_flag = 0xff;
     rencoder_restart();
+    rencoder_count();
+    INTCONbits.RBIE = 1;
+}
+
+void rencoder_tmrhook(void)
+{
+    renc_flag = 0;
+    rencoder_count();
+    IOCB = 0b01100000;
+    INTCONbits.RBIF = 0;
+    INTCONbits.RBIE = 1;
+
+   PIR1bits.TMR1IF = 0;
+   PIE1bits.TMR1IE = 0;
+   IPR1bits.TMR1IP = 1;
+
 }
 
 void rencoder_stop(void)
@@ -75,6 +112,9 @@ void rencoder_stop(void)
    PIR1bits.TMR1IF = 0;
    PIE1bits.TMR1IE = 0;
    IPR1bits.TMR1IP = 1;
+    IOCB = 0b00000000; // RB5,RB6
+    INTCONbits.RBIE = 0;
+    INTCONbits.RBIF = 0;
 //   rencoder_init();
 }
 
@@ -85,6 +125,7 @@ void rencoder_count(void)
    unsigned char pha = RENC_PH_A;
    unsigned char phb = RENC_PH_B;
 
+  // if(renc_flag != 0) return;
 //   if(renc_penalty != 0){
 //       renc_penalty++;
 //       if(renc_penalty > 1) {
index afe7b11..c5c4fac 100644 (file)
 #include "iodef.h"
 
 #define RENC_PH_A PORTBbits.RB5
-#define RENC_PH_B PORTCbits.RC5
+#define RENC_PH_B PORTBbits.RB6
 #define RENC_TRIS_A TRISBbits.TRISB5
-#define RENC_TRIS_B TRISCbits.TRISC5
+#define RENC_TRIS_B TRISBbits.TRISB6
 #define RENC_NONE 0x00
 #define RENC_LEFT 0x7f
 #define RENC_RIGHT 0xff
 
 extern unsigned char renc_dir;
 extern unsigned int renc_count;
+extern unsigned char renc_flag;
+
 
-extern void rencoder_up(unsigned char dir);
 extern void rencoder_init(void);
-extern void rencoder_count(void);
 extern void rencoder_start(void);
 extern void rencoder_restart(void);
 extern void rencoder_stop(void);
+extern void rencoder_inthook(void);
+extern void rencoder_tmrhook(void);
+extern void rencoder_count(void);
+