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;
36 void lcd_setbacklight(unsigned char flag, unsigned char level)
41 d.byte = _LCD_BACKLIGHT_TRIS;
42 d._LCD_BACKLIGHT_BIT = 0;
43 _LCD_BACKLIGHT_TRIS = d.byte;
45 b.byte = _LCD_BACKLIGHT;
46 b._LCD_BACKLIGHT_BIT = 0;
48 b._LCD_BACKLIGHT_BIT = 1;
50 _LCD_BACKLIGHT = b.byte;
53 d.byte = _LCD_BACKLIGHT_TRIS;
54 d._LCD_BACKLIGHT_BIT = 1;
55 _LCD_BACKLIGHT_TRIS = d.byte;
66 // level = (level * 25) / 10;
69 if(h == CCPR1L) return;
70 // l = 2 << 4; //(lv & 0x0300) >> 4;
71 d.byte = _LCD_BACKLIGHT_TRIS;
72 d._LCD_BACKLIGHT_BIT = 1;
73 _LCD_BACKLIGHT_TRIS = d.byte;
82 T2CON = 0b01111000; // Pre-scaler=1/1,Post-scaler = 1/16
83 // -> Freq = 2.44KHz * 16 = 39.4KHz.
88 } while(PIR1bits.TMR2IF ==0);
89 d.byte = _LCD_BACKLIGHT_TRIS;
90 d._LCD_BACKLIGHT_BIT = 0;
91 _LCD_BACKLIGHT_TRIS = d.byte;
93 // _LCD_PORT |= _LCD_BACKLIGHT;
98 void backlight_reset(unsigned char ctlword)
100 if(ctlword == charcode_e){
101 if(backlight_counter != 0){
102 backlight_counter = 0;
104 backlight_counter = setup.backlight_long;
108 if((ctlword >= charcode_1) && (ctlword <= charcode_f)) {
109 backlight_counter = setup.backlight_long;
110 lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
115 unsigned char backlight_dec(unsigned char dispf)
117 unsigned char pbutton;
118 unsigned char stat = dispf;
120 pbutton = chk_powerbutton(); // 48ms
121 if(pbutton != 0) shutdown(1); // Button pressed.
124 if(backlight_counter > 0) {
126 acm1602_resume(LCD_I2CADDR);
131 lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
133 lcd_setbacklight(0x00, 0); // Turn OFF
134 acm1602_suspend(LCD_I2CADDR);