OSDN Git Service

[Schematic][PREAMP] Change 2SC3110 to 2SK241 for MW/LW Amp.
[openi2cradio/OpenI2CRadio.git] / idle.c
diff --git a/idle.c b/idle.c
index 289e99c..ae8db1d 100644 (file)
--- a/idle.c
+++ b/idle.c
 
 void idle_init(void)
 {
-#if defined(__SDCC)
+    RCONbits.IPEN = 1;
+    INTCONbits.GIE = 1;
+
     INTCONbits.TMR0IF = 0;
-    INTCONbits.RBIF = 0;
+    INTCONbits.TMR0IE =  1;
+//    INTCONbits.RBIF = 0;
     INTCON2bits.TMR0IP = 0;
 //   INTCON = INTCON & ~(_TMR0IF |  _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
 //   INTCON2 = ~_TMR0IP & _TMR0IP; // Interrupt is lower.
-#else
-   INTCON = INTCON & ~(_INTCON_TMR0IF_MASK |  _INTCON_RBIF_MASK); // Enable tmr0 as interrupt and clear interrupt flags.
-   INTCON2bits.TMR0IP = 0; // Interrupt is lower.
-#endif
    WDTCON = 1; // OK? WDT=Disabled.
 }
 
@@ -61,23 +60,27 @@ void stop_idle(void)
 void idle(unsigned int initial)
 {
 
+   unsigned int i;
    WDTCONbits.SWDTEN = 0; // Lame WDT OFF.
    /* Enable IDLE */
-   OSCCONbits.IDLEN = 1;
-   INTCONbits.TMR0IF = 0;
-   INTCONbits.TMR0IE = 1; // Enable tmr0 as interrupt and clear interrupt flags.
    /* Set TMR0 for interrupt*/
    /* Pre-scaler: 1/2, PSA=1(ON), TOSE=0, T0CS=0(INTERNAL), T08BIT=0(16bit), TMR0ON=1(START) */
    /* 1Tick = 1/1000 ms*/
    T0CON = 0b00001000; // 1/2
+//   T0CON = 0b00001010; // 1/8
+   OSCCONbits.IDLEN = 1;
+   INTCONbits.TMR0IF = 0;
+   INTCONbits.TMR0IE = 1;
+//   TMR0L = initial & 0xff;
 //   TMR0H = initial >> 8; // Write order : L->H
+   TMR0H = initial >> 8; // Write order : H->L
    TMR0L = initial & 0xff;
-   TMR0H = initial >> 8; // Write order : L->H
    T0CONbits.TMR0ON = 1; // Start
-//   do {
+  do {
        Sleep();
 //       i = TMR0H << 8 + TMR0L; // Check if IDLE-Timer was elapsed.
-//   } while(i < 3); // Dead area : 0-2.
+   } while(INTCONbits.TMR0IF == 0); // Dead area : 0-2.
+   INTCONbits.TMR0IF = 0;
    WDTCONbits.SWDTEN = 1; // WDT ON.
 }
 
@@ -88,8 +91,7 @@ void idle_time_ms(unsigned int ms)
     unsigned int upper;
 
     if(ms == 0) return;
-    upper = (ms & 0xffc0) >> 10;
-//    tim = ms * 8 - ms / 16 - ms / 8;
+    upper = (ms & 0xffc0) >> 6;
     tim = (ms   & 0x3f) * 1000; //
     tim = (65535 - tim) + 1; // tim = 65536 - tim;
     while(upper > 0) {