4 * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 * This library / program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this library; see the file COPYING. If not, write to the
18 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 * As a special exception, if you link this(includeed from sdcc) library
22 * with other files, some of which are compiled with SDCC,
23 * to produce an executable, this library does not by itself cause
24 * the resulting executable to be covered by the GNU General Public License.
25 * This exception does not however invalidate any other reasons why
26 * the executable file might be covered by the GNU General Public License.
29 #include "commondef.h"
30 #include "lcd_acm1602.h"
33 #include "backlight.h"
36 * Detect reset condition.
38 unsigned char chk_reset(void)
73 return RESET_SOFTWARE;
75 if(rcon.b.TO == 0) return RESET_WDT;
76 if(rcon.b.PD == 0) return RESET_POWERDOWN;
77 if(stkptr.b.STKOVF) return RESET_STACK_FULL;
78 if(stkptr.b.STKUNF) return RESET_STACK_UNDER;
82 void power_on_inthook(void)
86 // IOCBbits.IOCB4 = 1;
92 void power_on(unsigned char f)
101 set_radiopower(0xff);
105 void rfamp_power(unsigned char b)
123 unsigned char chk_powerbutton(void)
125 unsigned char count = 0;
128 TRISBbits.RB4 = 1; // Set Input
129 for(i = 0; i < 24; i++) { // 2*24=48ms.
130 if(PORTBbits.RB4) count++;
134 if(count <= 12) { // 24ms
135 return 0xff; // Pressed
137 return 0; // Not pressed
140 void shutdown(unsigned char save_v)
142 rfamp_power(RFAMP_OFF);
144 acm1602_suspend(LCD_I2CADDR);
145 lcd_setbacklight(0, 0);
149 void power_off(unsigned char save_v)
155 // save_frequencies();
161 WDTCONbits.SWDTEN = 0; // Lame WDT OFF.
165 IOCB = 0x10; // IOCB4 ONLY.
166 OSCCONbits.IDLEN = 0; // Not Idle.
167 INTCON2bits.RBIP = 1; // Priority = HIGH;
169 T0CONbits.TMR0ON = 0;
172 if(INTCONbits.RBIF) {
175 sts = chk_powerbutton();
182 // Button pressed, software reset.