OSDN Git Service

[LCD] Fix click-noise of LCD=ON.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 20 Oct 2013 18:04:11 +0000 (03:04 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 20 Oct 2013 18:04:11 +0000 (03:04 +0900)
adc_int.c
backlight.c
ioports.c
main.c
power.c

index b51bf1b..f9c7bdb 100644 (file)
--- a/adc_int.c
+++ b/adc_int.c
@@ -96,7 +96,7 @@ void startadc(unsigned char ch)
         ansel_val = 0x0001 << ch;
 //        ansel_val = 0x0080;
     } else {
-        ADCON0 = 0x0f << 2;
+        ADCON0 = 0b00111100; //0x0f << 2;
        ansel_val = 0x0000;
     }
     ANSELH = ansel_val >> 8;
index af36dc8..cefcbd2 100644 (file)
 #include "power.h"
 
 int backlight_counter;
-
+unsigned char l_backlight_level;
 
 void lcd_setbacklight(unsigned char flag, unsigned char level)
 {
     __bitops_t  b;
     __bitops_t d;
-#if 0
-    d.byte = _LCD_BACKLIGHT_TRIS;
-    d._LCD_BACKLIGHT_BIT = 0;
-   _LCD_BACKLIGHT_TRIS = d.byte;
-
-    b.byte = _LCD_BACKLIGHT;
-    b._LCD_BACKLIGHT_BIT = 0;
-    if(flag != 0){
-       b._LCD_BACKLIGHT_BIT = 1;
-    }
-    _LCD_BACKLIGHT = b.byte;
-#else
-    if(flag == 0) {
+   l_backlight_level = level;
+   if(flag == 0) {
         d.byte = _LCD_BACKLIGHT_TRIS;
         d._LCD_BACKLIGHT_BIT = 1;
         _LCD_BACKLIGHT_TRIS = d.byte;
@@ -61,10 +50,6 @@ void lcd_setbacklight(unsigned char flag, unsigned char level)
         CCPR2H = 0;
     } else {
       unsigned char h,l;
-//      lv = level;
-//      lv <<= 2;
-//      level = (level * 25) / 10;
-//      level = 255;
       h = level >> 1;
       if(h == CCPR1L) return;
  //     l = 2 << 4; //(lv & 0x0300) >> 4;
@@ -84,15 +69,14 @@ void lcd_setbacklight(unsigned char flag, unsigned char level)
       TMR2 = 0x00;
       T2CONbits.TMR2ON = 1;
       do {
-          idle_time_ms(1);
-      } while(PIR1bits.TMR2IF ==0);
+          idle_time_ms(2); // 
+      } while(PIR1bits.TMR2IF == 0);
       d.byte = _LCD_BACKLIGHT_TRIS;
       d._LCD_BACKLIGHT_BIT = 0;
       _LCD_BACKLIGHT_TRIS = d.byte;
 
 //      _LCD_PORT |= _LCD_BACKLIGHT;
     }
-#endif
 }
 
 void backlight_reset(unsigned char ctlword)
@@ -100,8 +84,10 @@ void backlight_reset(unsigned char ctlword)
     if(ctlword == charcode_e){
         if(backlight_counter != 0){
            backlight_counter = 0;
+           lcd_setbacklight(0x00, 0); // Turn OFF
         } else {
            backlight_counter = setup.backlight_long;
+           lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
         }
         return;
     }
@@ -125,10 +111,11 @@ unsigned char backlight_dec(unsigned char dispf)
           if(dispf == 0) {
               acm1602_resume(LCD_I2CADDR);
                stat = 0xff;
-           }
+              lcd_setbacklight(0xff, setup.backlight_level);
+         }
 
            backlight_counter--;
-           lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+           //lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
        } else {
            lcd_setbacklight(0x00, 0); // Turn OFF
            acm1602_suspend(LCD_I2CADDR);
index 1301222..42673b0 100644 (file)
--- a/ioports.c
+++ b/ioports.c
@@ -120,7 +120,7 @@ void keyin_ioinit(void)
     ANSELC = AN_C_VAL;
     TRISC = TRIS_C_VAL_O;
  //   lcd_backlightinit();
-//    io_intcountinit();
+    io_intcountinit();
 }
 #endif
 
@@ -194,7 +194,7 @@ void keyin_ioinit(void)
     INTCON3bits.INT2IE = 0;
 
 //    lcd_backlightinit();
-    io_intcountinit();
+//    io_intcountinit();
 }
 #else
 void keyin_ioinit(void)
@@ -214,7 +214,7 @@ void keyin_ioinit(void)
     LATC = 0x00;
     TRISC = TRIS_C_VAL_O;
 //    lcd_backlightinit();
-    io_intcountinit();
+//    io_intcountinit();
 }
 #endif
 
diff --git a/main.c b/main.c
index 9435ee6..92cfb47 100644 (file)
--- a/main.c
+++ b/main.c
@@ -84,6 +84,9 @@
                MCLRE=ON,STVREN=ON,DEBUG=ON, \
                XINST=OFF
 #endif
+
+#define USE_RENCODER
+
 /*
  * Statuses
   */
@@ -125,7 +128,9 @@ void TMR1_Handler(void)
 SIGHANDLER(TMR1_Handler)
 #endif
 {
+#ifdef USE_RENCODER
     rencoder_count();
+#endif   
 //    rencoder_restart();
    T1CON = 0b10110100;// RD16, T1RUN=0, 1/32 fOSC, TNR1CS=0, TMR1ON=0;
    TMR1H = 63036 >> 8; // Tick = 4us, Count = 2500
@@ -137,6 +142,17 @@ SIGHANDLER(TMR1_Handler)
 }
 
 #ifdef __XC
+void TMR3_Handler(void)
+#else
+SIGHANDLER(TMR3_Handler)
+#endif
+{
+   PIR2bits.TMR3IF = 0;
+   PIE2bits.TMR3IE = 0;
+   IPR2bits.TMR3IP = 0;
+}
+
+#ifdef __XC
 void EXINT_Handler(void)
 #else
 SIGHANDLER(EXINT_Handler)
@@ -210,7 +226,7 @@ SIGHANDLER(I2CBus_handler)
 DEF_INTLOW(intlow_handler)
   DEF_HANDLER(SIG_TMR0, TMR0_handler)
   DEF_HANDLER(SIG_INT0, EXINT_Handler)
-//  DEF_HANDLER(SIG_TMR1, I2C_handler)
+  DEF_HANDLER(SIG_TMR3, TMR3_Handler)
 END_DEF
 
 DEF_INTHIGH(inthigh_handler)
@@ -235,9 +251,9 @@ void interrupt high_priority inthigh_handler(void)
     if(INTCONbits.RBIF) RBIF_handler();
     if(PIR2bits.EEIF)   EEPROM_handler();
     if(PIR1bits.TMR1IF) TMR1_Handler();
-   // if(INTCONbits.TMR0IF) TMR0_handler();
-//    if(INTCON3bits.INT1IF) EXINT_Handler();
-//    if(INTCON3bits.INT2IF) EXINT_Handler();
+    if(PIR2bits.TMR3IF) TMR3_Handler();
+    if(INTCON3bits.INT1IF) EXINT_Handler();
+    if(INTCON3bits.INT2IF) EXINT_Handler();
     if(PIR1bits.ADIF) INADC_handler();
 
 //    if(PIR1bits.SSPIF)    I2C_handler();
@@ -313,8 +329,10 @@ int main(void)
     ClrWdt();
     ui_idlekey = setup.ui_idlecount / 92;
     ui_idlepad = setup.ui_idlecount % 23;
-    rencoder_start();
-    do {
+#ifdef USE_RENCODER
+   rencoder_start();
+#endif
+   do {
 
 #if 1
         if(battlevel < 340) { // 3.4V
@@ -342,12 +360,17 @@ int main(void)
                     acm1602_resume(LCD_I2CADDR);
                     dispf = 0xff;
                 }
+#ifdef USE_RENCODER
                rencoder_stop();
-                setfreq_updown(c);
+#endif
+               setfreq_updown(c);
                update_status();
                 update_display();
+#ifdef USE_RENCODER
                rencoder_start();
+#endif
             }
+#ifdef USE_RENCODER
             if(renc_dir == RENC_LEFT) {
               akc6955_down_freq(renc_count);
               rencoder_init();
@@ -355,6 +378,7 @@ int main(void)
               akc6955_up_freq(renc_count);
               rencoder_init();
            }
+#endif    
             ClrWdt();
         }
          update_status();
diff --git a/power.c b/power.c
index b13a418..297d1aa 100644 (file)
--- a/power.c
+++ b/power.c
@@ -31,6 +31,7 @@
 #include "power.h"
 #include "menu.h"
 #include "backlight.h"
+#include "rencoder.h"
 
 /*
  * Detect reset condition.
@@ -160,6 +161,7 @@ void power_off(unsigned char savef)
 
     WDTCONbits.SWDTEN = 0; // Lame WDT OFF.
     sts = 0;
+    rencoder_stop();
     do {
         RCONbits.IPEN = 1;
         IOCB = 0x10; // IOCB4 ONLY.