OSDN Git Service

[Power] Improve more efficient power.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 13 Aug 2013 15:06:45 +0000 (00:06 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 13 Aug 2013 15:06:45 +0000 (00:06 +0900)
idle.c
iodef.h
lcd_acm1602.c
lcd_acm1602.h
main.c
nbproject/Makefile-genesis.properties
nbproject/configurations.xml
power.c
power.h
ui.c

diff --git a/idle.c b/idle.c
index 77eb264..1e2fbc9 100644 (file)
--- a/idle.c
+++ b/idle.c
@@ -43,7 +43,7 @@ void idle_init(void)
 
     INTCONbits.TMR0IF = 0;
     INTCONbits.TMR0IE =  1;
-    INTCONbits.RBIF = 0;
+//    INTCONbits.RBIF = 0;
     INTCON2bits.TMR0IP = 0;
 //   INTCON = INTCON & ~(_TMR0IF |  _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
 //   INTCON2 = ~_TMR0IP & _TMR0IP; // Interrupt is lower.
diff --git a/iodef.h b/iodef.h
index 1b2515f..a9fb61e 100644 (file)
--- a/iodef.h
+++ b/iodef.h
@@ -92,7 +92,8 @@ extern "C" {
  *        RA1 : KO1
  *        RA2 : KO2
  *        RA3 : KO7
- *        RA2-RA5 : READ
+ *        RA4 : AM LAMP('1' = On)
+ *        RA5:  FM LAMP('1) = On)
  *        RA6-RA7 : Used for CLOCK, connect to 8MHz resonator.
  *
  * PORTB:
@@ -122,8 +123,8 @@ extern "C" {
  *        RD4-RD7: LCD DB4-DB7
  *
  * PORTE:
- *        RE0:
- *        RE1:
+ *        RE0: External Power AMP
+ *        RE1: Power to Radio-Chip.
  *        RE2: ADC(IN) to measure battery
  *        RE3: VPP (ICSP Programming Voltage) / MCLR
  */
index 24ee69a..7c830fd 100644 (file)
@@ -519,6 +519,13 @@ void acm1602_suspend(unsigned char addr)
     _ACM1602_LONG_WAIT();
 }
 
+void acm1602_resume(unsigned char addr)
+{
+    sendcmd(addr, 0x0c, 0xff);
+    _ACM1602_LONG_WAIT();
+}
+
+
 #ifdef _USE_I2C_1602
 /*
  * st7032 extensions.
index effc371..cd2e118 100644 (file)
@@ -85,6 +85,7 @@ extern void acm1602_cursordir(unsigned char addr, unsigned char right);
 extern void acm1602_dispcursor(unsigned char addr, unsigned char flag);
 extern void acm1602_init(unsigned char addr, unsigned char cls);
 extern void acm1602_suspend(unsigned char addr);
+extern void acm1602_resume(unsigned char addr);
 
 //extern unsigned char acm1602_getchar(unsigned char addr);
 
diff --git a/main.c b/main.c
index f63ccc8..78e218d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -251,37 +251,42 @@ void lowbatt(void)
 int main(void)
 {
     unsigned char c;
-    unsigned int sum = 0;
     unsigned char pbutton;
     unsigned char reset_status;
     unsigned char p;
+    unsigned char lvcount = 0;
+    unsigned char dispf = 0xff;
     
     OSCCON =  (0x80 & 0b11111100) | 0b00111000;
 //    OSCCON =  (0x80 & 0b11111100) | 0b00110010; // 8MHz 
     idle_init();
     keyin_init();
     keyin_ioinit();
-    WDTCONbits.SWDTEN = 0; // WDT OFF.
+    i2c1_init();
     reset_status = chk_reset();
     idle_time_ms(300); // Wait for setup.
+    WDTCONbits.SWDTEN = 0; // WDT OFF.
     switch(reset_status){
         case RESET_MCLR:
-        case RESET_WDT:  // Workaround random reset.
         case RESET_BOR:
             shutdown(0); // Save and halt on BOR.
             break;
         case RESET_SOFTWARE: //
             RCONbits.RI = 0;
+           pbutton = chk_powerbutton();
+            if(pbutton == 0) shutdown(0); // Not-Pressed power-button -> shutdown( not save).
+            break;
+        case RESET_POR:
+        case RESET_WDT:  // Workaround random reset.
+ //           shutdown(0);
             break;
         default:
             break;
     }
     WDTCONbits.SWDTEN = 1; // WDT ON.
-    i2c1_init();
     power_on(1);
     intadc_init();
     set_powerlamp(1);
-//    idle_time_ms(125);
     valinit();
 
     acm1602_init(0xa0, 1); //Init LCD
@@ -305,32 +310,49 @@ int main(void)
     lcd_setbacklight(0xff, 255);
     do {
             if(battlevel <= 340) { // 3.4V
-               lowbatt();
+                lvcount++;
+                if(lvcount > 4) {
+                    if(dispf == 0) {
+                        acm1602_resume(LCD_I2CADDR);
+                        dispf = 0xff;
+                     }
+                    lowbatt(); //Zap 4Times on LowVoltage.
+                }
+            } else {
+                lvcount = 0;
             }
         /* Main routine*/
-           c = pollkeys(pollkeybuf, 5, 1); // 23*10=135ms
+           c = pollkeys(pollkeybuf, 19, 1); // 23*19=437ms
            p = 0;
             while(c > 0) {
                 ClrWdt();
+                if(dispf == 0) {
+                    acm1602_resume(LCD_I2CADDR);
+                    dispf = 0xff;
+                }
                 setfreq_updown(pollkeybuf[p]);
                 c--;
                  p++;
             }
-//       idle_time_ms(ui_idlecount);
-            _LOCATE(0,0);
-            pbutton = chk_powerbutton();
+//            _LOCATE(0,0);
+            pbutton = chk_powerbutton(); // 48ms
             if(pbutton != 0) shutdown(1); // Button pressed.
-
+            ClrWdt();
+            update_status();
             if(backlight_counter > 0) {
+                if(dispf == 0) {
+                    acm1602_resume(LCD_I2CADDR);
+                    dispf = 0xff;
+                }
                 backlight_counter--;
                 lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+                update_display();
             } else {
                 lcd_setbacklight(0x00, 0); // Turn OFF
+                acm1602_suspend(LCD_I2CADDR);
+                dispf = 0;
         }
         ClrWdt();
-        update_status();
-        update_display();
-        ClrWdt();
     } while(1);
 }
 
index 25812c9..e0454cd 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Mon Jul 29 14:19:15 JST 2013
+#Tue Aug 13 23:15:40 JST 2013
 default.languagetoolchain.dir=/usr/local/bin
 default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1c49f19f6a43b876c317e0d8d41c0854
index 46247c1..54bcca6 100644 (file)
         <makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
         <makeCustomizationNormalizeHexFile>true</makeCustomizationNormalizeHexFile>
       </makeCustomizationType>
-      <HI-TECH-COMP>
-        <property key="asmlist" value="true"/>
-        <property key="define-macros" value=""/>
-        <property key="extra-include-directories" value=""/>
-        <property key="identifier-length" value="255"/>
-        <property key="operation-mode" value="free"/>
-        <property key="opt-xc8-compiler-strict_ansi" value="false"/>
-        <property key="optimization-assembler" value="true"/>
-        <property key="optimization-assembler-files" value="true"/>
-        <property key="optimization-debug" value="false"/>
-        <property key="optimization-global" value="true"/>
-        <property key="optimization-level" value="9"/>
-        <property key="optimization-set" value="default"/>
-        <property key="optimization-speed" value="false"/>
-        <property key="preprocess-assembler" value="true"/>
-        <property key="undefine-macros" value=""/>
-        <property key="use-cci" value="false"/>
-        <property key="verbose" value="false"/>
-        <property key="warning-level" value="0"/>
-        <property key="what-to-do" value="ignore"/>
-      </HI-TECH-COMP>
-      <HI-TECH-LINK>
-      </HI-TECH-LINK>
       <PICkit3PlatformTool>
         <property key="AutoSelectMemRanges" value="auto"/>
         <property key="Freeze Peripherals" value="true"/>
         <property key="programoptions.uselvpprogramming" value="false"/>
         <property key="voltagevalue" value="3.25"/>
       </PICkit3PlatformTool>
-      <XC8-config-global>
-      </XC8-config-global>
       <sdcc>
         <property key="V-show-commands-compiler" value="true"/>
         <property key="Werror" value="false"/>
diff --git a/power.c b/power.c
index 377fe01..bd98772 100644 (file)
--- a/power.c
+++ b/power.c
@@ -58,13 +58,19 @@ unsigned char chk_reset(void)
 #endif
     rcon.byte = RCON;
     stkptr.byte = STKPTR;
-    RCON |= 0b01010011; // SBOREN,*RI,*POR,*BOR = '1'.
-    if((rcon.b.POR ==0) && (rcon.b.BOR == 0)) {
+    if(rcon.b.POR ==0) {
+        RCONbits.POR = 1;
         return RESET_POR;
     }
 
-    if(rcon.b.BOR == 0) return RESET_BOR;
-    if(rcon.b.RI == 0) return RESET_SOFTWARE;
+    if(rcon.b.BOR == 0) {
+        RCONbits.BOR = 1;
+        return RESET_BOR;
+    }
+    if(rcon.b.RI == 0) {
+        RCONbits.RI = 1;
+        return RESET_SOFTWARE;
+    }
     if(rcon.b.TO == 0) return RESET_WDT;
     if(rcon.b.PD == 0) return RESET_POWERDOWN;
     if(stkptr.b.STKOVF) return RESET_STACK_FULL;
@@ -85,13 +91,13 @@ void power_on_inthook(void)
 void power_on(unsigned char f)
 {
     if(f == 0x00){
-        set_examp_mute(1);
+        set_examp_mute(0xff);
         idle_time_ms(200);
-        set_radiopower(0);
+        set_radiopower(0x00);
     } else {
-        set_examp_mute(0);
+        set_examp_mute(0x00);
         idle_time_ms(100);
-        set_radiopower(1);
+        set_radiopower(0xff);
     }
 }
 
@@ -117,12 +123,14 @@ unsigned char chk_powerbutton(void)
 {
     unsigned char count = 0;
     char i;
-    for(i = 0; i < 24; i++) {  // 10*24=240ms.
+
+    TRISBbits.RB4 = 1; // Set Input
+    for(i = 0; i < 24; i++) {  // 2*24=48ms.
         if(PORTBbits.RB4) count++;
         _POWER_DELAY();
         ClrWdt();
     }
-    if(count <= 12) { // 120ms
+    if(count <= 12) { // 24ms
         return 0xff; // Pressed
     }
     return 0; // Not pressed
@@ -160,7 +168,9 @@ void power_off(unsigned char save)
         // Wake up
         if(INTCONbits.RBIF) {
                 INTCONbits.RBIF = 0;
+                idle_init();
                 sts = chk_powerbutton();
+          //      sts = 0xff;
         }
     } while(sts == 0);
     
diff --git a/power.h b/power.h
index 1d41cb0..ed61034 100644 (file)
--- a/power.h
+++ b/power.h
@@ -57,9 +57,11 @@ extern "C" {
 #endif
 
 #ifdef __SDCC
-#define _POWER_DELAY() delay1ktcy(2*8) // 2ms
+//#define _POWER_DELAY() delay1ktcy(2*8) // 2ms
+#define _POWER_DELAY() idle_time_ms(2) // 2ms
 #else
-#define _POWER_DELAY() __delay_ms(2)
+//#define _POWER_DELAY() __delay_ms(2)
+#define _POWER_DELAY() idle_time_ms(2) // 2ms
 #endif
 
 
diff --git a/ui.c b/ui.c
index 918f3b2..d8901a6 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -286,14 +286,14 @@ unsigned char readkey(void)
  */
 unsigned char pollkeys(unsigned char *p, unsigned int limit, unsigned char repeat)
 {
-    unsigned int count = 0;
+    unsigned char count = 0;
     unsigned int lifetime = 0;
     unsigned int penalty = 0;
     unsigned char c;
 
     do {
         idle_time_ms(5); // 5ms.
-        c = readkey(); //
+        c = readkey(); //18ms
         ClrWdt();
         if(c != charcode_null) {
             push_keyinfifo(c);