4 * Copyright (C) 2013-08-31 K.Ohta <whatisthis.sowhat ai gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2,
9 * or (at your option) any later version.
10 * This library / program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this library; see the file COPYING. If not, write to the
17 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 * As a special exception, if you link this(includeed from sdcc) library
21 * with other files, some of which are compiled with SDCC,
22 * to produce an executable, this library does not by itself cause
23 * the resulting executable to be covered by the GNU General Public License.
24 * This exception does not however invalidate any other reasons why
25 * the executable file might be covered by the GNU General Public License.
28 #include "backlight.h"
33 int backlight_counter;
34 unsigned char l_backlight_level;
36 void lcd_setbacklight(unsigned char flag, unsigned char level)
40 l_backlight_level = level;
42 d.byte = _LCD_BACKLIGHT_TRIS;
43 d._LCD_BACKLIGHT_BIT = 1;
44 _LCD_BACKLIGHT_TRIS = d.byte;
54 if(h == CCPR1L) return;
55 // l = 2 << 4; //(lv & 0x0300) >> 4;
56 d.byte = _LCD_BACKLIGHT_TRIS;
57 d._LCD_BACKLIGHT_BIT = 1;
58 _LCD_BACKLIGHT_TRIS = d.byte;
67 T2CON = 0b01111000; // Pre-scaler=1/1,Post-scaler = 1/16
68 // -> Freq = 2.44KHz * 16 = 39.4KHz.
73 } while(PIR1bits.TMR2IF == 0);
74 d.byte = _LCD_BACKLIGHT_TRIS;
75 d._LCD_BACKLIGHT_BIT = 0;
76 _LCD_BACKLIGHT_TRIS = d.byte;
78 // _LCD_PORT |= _LCD_BACKLIGHT;
82 void backlight_reset(unsigned char ctlword)
84 if(ctlword == charcode_e){
85 if(backlight_counter != 0){
86 backlight_counter = 0;
87 lcd_setbacklight(0x00, 0); // Turn OFF
89 backlight_counter = setup.backlight_long;
90 lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
94 if((ctlword >= charcode_1) && (ctlword <= charcode_f)) {
95 backlight_counter = setup.backlight_long;
96 lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
101 unsigned char backlight_dec(unsigned char dispf)
103 unsigned char pbutton;
104 unsigned char stat = dispf;
106 pbutton = chk_powerbutton(); // 48ms
107 if(pbutton != 0) shutdown(1); // Button pressed.
110 if(backlight_counter > 0) {
112 acm1602_resume(LCD_I2CADDR);
114 lcd_setbacklight(0xff, setup.backlight_level);
118 //lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
120 lcd_setbacklight(0x00, 0); // Turn OFF
121 acm1602_suspend(LCD_I2CADDR);