OSDN Git Service

[Backlight] Use PWM mode for backlight, to save battery.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 17:11:47 +0000 (02:11 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 17:11:47 +0000 (02:11 +0900)
eepromutil.c
helps.c
ioports.c
main.c
menu.c

index 95b8b6e..c833d5d 100644 (file)
@@ -151,6 +151,8 @@ void save_eeprom(void)
     p += 2;
     writeword_eeprom(p, &sum, ui_idlecount);
     p += 2;
+    writebyte_eeprom(p, &sum, backlight_level);
+    p += 1;
 
     // Write checksum
     eeprom_writebyte(p, sum >> 8);
@@ -263,7 +265,9 @@ unsigned char load_eeprom(void)
     p += 2;
     ui_idlecount = readword_eeprom(p, &sum);
     p += 2;
-                                                                            // Write checksum
+    backlight_level = readbyte_eeprom(p, &sum);
+    p += 1;
+     // Write checksum
     magic = (eeprom_readbyte(p) << 8) + eeprom_readbyte(p+1);
 
     if(sum != magic) return 0x00;
diff --git a/helps.c b/helps.c
index 46faa48..657078a 100644 (file)
--- a/helps.c
+++ b/helps.c
@@ -57,14 +57,14 @@ const char *setup_helpstr[16] = {
 
 const char *mainmenu_helpstr[18] = {
         "Help", "F=exit any=continue",
-        "0: Setup", "1: Reserve",
-        "2: Band", "3: Freq",
+        "0: Setup", "1: Band",
+        "2: Reserve", "3: Freq",
         "4: Reserve", "5: Scan"
-        "6: Gain", "7: Volume",
-        "8: FM Wide/Narrow", "9: Reserved",
-        "a: PowOFF", "b: Cancel",
+        "6: Reserve", "7: Power Off",
+        "8: Reserve", "9: Width",
+        "a: AM/FM", "b: Cancel",
         "c: Set user", "d: Input user",
-        "e: AM/FM", "f: (Exit) Help"
+        "e: Reserve", "f: (Exit) Help"
 };
 
 const char *numeric_helpstr[10] = {
index 6b67b8b..1e22961 100644 (file)
--- a/ioports.c
+++ b/ioports.c
@@ -73,8 +73,7 @@ void lcd_setbacklight(unsigned char flag, unsigned char level)
 {
     __bitops_t  b;
     __bitops_t d;
-
-#if 1
+#if 0
     d.byte = _LCD_BACKLIGHT_TRIS;
    d._LCD_BACKLIGHT_BIT = 0;
    _LCD_BACKLIGHT_TRIS = d.byte;
@@ -87,22 +86,42 @@ void lcd_setbacklight(unsigned char flag, unsigned char level)
     _LCD_BACKLIGHT = b.byte;
 #else
     if(flag == 0) {
+        d.byte = _LCD_BACKLIGHT_TRIS;
+        d._LCD_BACKLIGHT_BIT = 1;
+        _LCD_BACKLIGHT_TRIS = d.byte;
+        PSTRCONbits.STRA = 0;
         T2CONbits.TMR2ON = 0;
         TMR2 = 0x00;
-        CCP1CON &= 0x00;
+        CCP1CON = 0x00;
         CCPR1L = 0;
     } else {
       unsigned char h,l;
-      unsigned char b;
-      if(level > 100) level = 100;
-      h = (level & 0xfc) >> 2;
-      l = (level & 0x03) << 4;
-      b = CCP1CON & 0x0c;
-      b = b | 0x0c | l;
+//      lv = level;
+//      lv <<= 2;
+//      level = (level * 25) / 10;
+//      level = 255;
+      h = level >> 1; // PWM Level
+      if(level == 255) h = 255;
+ //     l = 2 << 4; //(lv & 0x0300) >> 4;
+      PSTRCONbits.STRA = 1;
       CCPR1L = h;
+      CCPR1H = h;
+      b.b2 = 1;
+      b.b3 = 1;
+      CCP1CON = b.byte | 0;
+      PR2 = 0x65;
+      PIR1bits.TMR2IF = 0;
+      T2CON = 0b01111001; // Pre-scaler=1/16,Post-scaler = 1/16
+      // -> Freq = 1.22KHz * 4 = 4.84KHz.
       TMR2 = 0x00;
-      CCPR1L = h;
-       T2CONbits.TMR2ON = 1;
+      T2CONbits.TMR2ON = 1;
+      do {
+          idle_time_ms(1);
+      } while(PIR1bits.TMR2IF ==0);
+      d.byte = _LCD_BACKLIGHT_TRIS;
+      d._LCD_BACKLIGHT_BIT = 0;
+      _LCD_BACKLIGHT_TRIS = d.byte;
+
 //      _LCD_PORT |= _LCD_BACKLIGHT;
     }
 #endif
diff --git a/main.c b/main.c
index dd8af64..4f49639 100644 (file)
--- a/main.c
+++ b/main.c
@@ -300,7 +300,7 @@ int main(void)
     _PUTCHAR(' '); //
     _LOCATE(0,1);
     printstr("Hello;-)");
-    lcd_setbacklight(0xff, 100);
+    lcd_setbacklight(0xff, 255);
     idle_time_ms(1000);
     check_eeprom();
     // Init AKC6955
@@ -316,7 +316,7 @@ int main(void)
     ClrWdt();
 //    _LOCATE(0,0);
 //    printstr("OK");
-   lcd_setbacklight(0xff, 100);
+   lcd_setbacklight(0xff, 255);
     do {
 //            if(battlevel <= 408) { // 4.80*0.85
  //               lowbatt();
diff --git a/menu.c b/menu.c
index 7b39f38..5517fe2 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -569,24 +569,14 @@ void setup_menu(void)
 
     c = printhelp_2lines("Setup F=HELP", "5=Return");
     switch(c){
-        case charcode_f:
-            setup_help();
-            break;
-        case charcode_5:
-            break;
-        case charcode_0:
-            menu_poweroff();
-            break;
-        case charcode_c:
-            menu_save();
-            break;
-        case charcode_a:
-            menu_load();
-            break;
-        case charcode_d:
-            setdefault();
-            break;
-        case charcode_e:
+        case charcode_3:
+            _CLS();
+            _LOCATE(0,0);
+            printstr("BL Level:");
+            val = read_numeric(backlight_level, 3, 0,1);
+            if(val > 255) val = 255;
+            if(val < 10) val = 15;
+            backlight_level = (unsigned char)val;
             break;
         case charcode_4:
             _CLS();
@@ -597,7 +587,9 @@ void setup_menu(void)
             fmbandwidth = (unsigned char)val;
             akc6955_set_fmbandwidth(fmbandwidth);
             break;
-        case charcode_1:
+        case charcode_5:
+            break;
+        case charcode_7:
             _CLS();
             _LOCATE(0,0);
             printstr("FM-CNR threshold:");
@@ -605,7 +597,7 @@ void setup_menu(void)
             val = read_numeric(val, 1, 0, 1);
             set_thresh_fmcnr((unsigned char)val);
             break;
-        case charcode_2:
+        case charcode_8:
             _CLS();
             _LOCATE(0,0);
             printstr("AM-CNR threshold:");
@@ -613,7 +605,7 @@ void setup_menu(void)
             val = read_numeric(val, 1, 0, 1);
             set_thresh_amcnr((unsigned char)val);
             break;
-        case charcode_3:
+        case charcode_9:
             _CLS();
             _LOCATE(0,0);
             printstr("Stereo threshold:");
@@ -621,6 +613,31 @@ void setup_menu(void)
             val = read_numeric(val, 1, 0, 1);
             set_thresh_fmstereo((unsigned char)val);
             break;
+        case charcode_f:
+            setup_help();
+            break;
+        case charcode_0:
+            menu_poweroff();
+            break;
+        case charcode_a:
+            menu_load();
+            break;
+        case charcode_c:
+            menu_save();
+            break;
+        case charcode_d:
+            setdefault();
+            break;
+        case charcode_e:
+            _CLS();
+            _LOCATE(0,0);
+            printstr("BL Long:");
+            val = read_numeric(backlight_long, 3, 0,1);
+            if(val > 999) val = 999;
+            backlight_long = val;
+            break;
+        default:
+            break;
     }
 }
 /*
@@ -644,33 +661,25 @@ void main_menu(void)
        } while(n == 0);
        p = 0;
        c = pollkeybuf[0];
-        if(c == charcode_f){
-            mainmenu_help();
-            // HELP
-        } else if(c == charcode_b){
-            // Cancel
-        } else if(c == charcode_1){
-            
-        } else if(c == charcode_2){
+        if(c == charcode_1){
             // Band
             setband_direct();
+        } else if(c == charcode_2){
         } else if(c == charcode_3){
             // Band
             setfreq_direct();
-        } else if(c == charcode_a){
-            menu_poweroff();
-        } else if(c == charcode_5){
+        } else if(c == charcode_4){
+
+        }else if(c == charcode_5){
             scan_start();
             // Scan
         } else if(c == charcode_6){
-            
-        } else if(c == charcode_4){
 
         } else if(c == charcode_7){
+            menu_poweroff();
+        } else if(c == charcode_8){
             // Set volume
             set_volume();
-        } else if(c == charcode_8){
-            // Reserve
         } else if(c == charcode_9){
             _CLS();
             _LOCATE(0,0);
@@ -682,14 +691,22 @@ void main_menu(void)
         } else if(c == charcode_0){
             // Setup Menu
             setup_menu();
-        } else if(c == charcode_d){
-            // Call userband
-            input_userband();
+        } else if(c == charcode_a){
+            toggle_amfm();
+        } else if(c == charcode_b){
+            // Cancel
         } else if(c == charcode_c){
             // Set userband
             set_userband();
+        } else if(c == charcode_d){
+            // Call userband
+            input_userband();
         } else if(c == charcode_e){
-            toggle_amfm();
+            // Backlight
+            
+        } else if (c == charcode_f){
+            mainmenu_help();
+            // HELP
         }
        _CLS();
        _LOCATE(0,0);