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.
}
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.
}
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) {