#include "backlight.h"
#include "idle.h"
+#include "menu.h"
+#include "power.h"
+
+int backlight_counter;
+unsigned char l_backlight_level;
void lcd_setbacklight(unsigned char flag, unsigned char level)
{
__bitops_t b;
__bitops_t d;
-#if 0
- d.byte = _LCD_BACKLIGHT_TRIS;
- d._LCD_BACKLIGHT_BIT = 0;
- _LCD_BACKLIGHT_TRIS = d.byte;
-
- b.byte = _LCD_BACKLIGHT;
- b._LCD_BACKLIGHT_BIT = 0;
- if(flag != 0){
- b._LCD_BACKLIGHT_BIT = 1;
- }
- _LCD_BACKLIGHT = b.byte;
-#else
- if(flag == 0) {
+ l_backlight_level = level;
+ if(flag == 0) {
d.byte = _LCD_BACKLIGHT_TRIS;
d._LCD_BACKLIGHT_BIT = 1;
_LCD_BACKLIGHT_TRIS = d.byte;
CCPR2H = 0;
} else {
unsigned char h,l;
-// lv = level;
-// lv <<= 2;
-// level = (level * 25) / 10;
-// level = 255;
h = level >> 1;
if(h == CCPR1L) return;
// l = 2 << 4; //(lv & 0x0300) >> 4;
TMR2 = 0x00;
T2CONbits.TMR2ON = 1;
do {
- idle_time_ms(1);
- } while(PIR1bits.TMR2IF ==0);
+ idle_time_ms(2); //
+ } while(PIR1bits.TMR2IF == 0);
d.byte = _LCD_BACKLIGHT_TRIS;
d._LCD_BACKLIGHT_BIT = 0;
_LCD_BACKLIGHT_TRIS = d.byte;
// _LCD_PORT |= _LCD_BACKLIGHT;
}
-#endif
}
+void backlight_reset(unsigned char ctlword)
+{
+ if(ctlword == charcode_e){
+ if(backlight_counter != 0){
+ backlight_counter = 0;
+ lcd_setbacklight(0x00, 0); // Turn OFF
+ } else {
+ backlight_counter = setup.backlight_long;
+ lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+ }
+ return;
+ }
+ if((ctlword >= charcode_1) && (ctlword <= charcode_f)) {
+ backlight_counter = setup.backlight_long;
+ lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+ }
+}
+
+
+unsigned char backlight_dec(unsigned char dispf)
+{
+ unsigned char pbutton;
+ unsigned char stat = dispf;
+
+ pbutton = chk_powerbutton(); // 48ms
+ if(pbutton != 0) shutdown(1); // Button pressed.
+ ClrWdt();
+
+ if(backlight_counter > 0) {
+ if(dispf == 0) {
+ acm1602_resume(LCD_I2CADDR);
+ stat = 0xff;
+ lcd_setbacklight(0xff, setup.backlight_level);
+ }
+
+ backlight_counter--;
+ //lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+ } else {
+ lcd_setbacklight(0x00, 0); // Turn OFF
+ acm1602_suspend(LCD_I2CADDR);
+ stat = 0;
+ }
+ return stat;
+}
\ No newline at end of file