OSDN Git Service

[LCD][4bit] Using bit-manipulation to communicate LCD.
[openi2cradio/OpenI2CRadio.git] / idle.c
1 /*
2  * OpenI2CRADIO
3  * Idle routine.
4  * Using timer0.
5  * Copyright (C) 2013-06-11 K.Ohta <whatisthis.sowhat ai gmail.com>
6  * License: GPL2+LE
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2,
11  *  or (at your option) any later version.
12  *  This library / program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *  See the GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this library; see the file COPYING. If not, write to the
19  *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20  *  MA 02110-1301, USA.
21  *
22  *  As a special exception, if you link this(includeed from sdcc) library
23  *  with other files, some of which are compiled with SDCC,
24  *  to produce an executable, this library does not by itself cause
25  *  the resulting executable to be covered by the GNU General Public License.
26  *  This exception does not however invalidate any other reasons why
27  *  the executable file might be covered by the GNU General Public License.
28  */
29 #include <sdcc-lib.h>
30 #include <pic18fregs.h> /* ONLY FOR PIC18x */
31 #include <signal.h>
32 #include "iodef.h"
33
34
35 void idle_init(void)
36 {
37    INTCON = INTCON & ~(_TMR0IF | _INT0IF | _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
38    INTCON2 = ~_TMR0IP & _TMR0IP; // Interrupt is lower.
39
40    WDTCON = 1; // OK? WDT=Disabled.
41 }
42
43
44 void stop_idle(void)
45 {
46     T0CONbits.TMR0ON = 0;
47 }
48
49
50 void idle(unsigned int initial)
51 {
52    unsigned char osccon;
53    unsigned char  contword;
54
55    /* Enable IDLE */
56    osccon = OSCCON;
57  //  osccon = osccon | _IDLEN |  _SCS1 | _SCS0;
58   osccon = osccon | _IDLEN;
59    OSCCON = osccon;
60    INTCON |= _TMR0IE; // Enable tmr0 as interrupt and clear interrupt flags.
61    
62    /* Set TMR0 for interrupt*/
63    /* Pre-scaler: 1/16, PSA=0(ON), TOSE=0, T0CS=0(INTERNAL), T08BIT=0(16bit), TMR0ON=1(START) */
64    contword = _T0PS0 | _T0PS1 |  _TMR0ON; // _T0PS2
65    TMR0H = initial >> 8;
66    TMR0L = initial & 0xff;
67 //   TMR0H = initial >> 8;
68    T0CON = contword;
69    
70    Sleep();
71 }