From 3db67a073bb6873230e6d711e4e16f42fcbd27ae Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Mon, 8 Jul 2013 03:17:28 +0900 Subject: [PATCH] [LCD] Change IOPORT RC2 TO RC1 (PWM1 to PWM2) issue of ECCP, P1B-P1D is synced with P1A, why?(Still single mode). --- iodef.h | 2 +- ioports.c | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/iodef.h b/iodef.h index 5a89569..699048e 100644 --- a/iodef.h +++ b/iodef.h @@ -148,7 +148,7 @@ extern "C" { #define _PORT_RADIOPOW LATEbits.LATE1 //#ifdef __SDCC #define _LCD_BACKLIGHT LATC -#define _LCD_BACKLIGHT_BIT b2 +#define _LCD_BACKLIGHT_BIT b1 #define _LCD_BACKLIGHT_TRIS TRISC //#else //#define _LCD_BACKLIGHT _PORTC_RC2_MASK diff --git a/ioports.c b/ioports.c index 1e22961..07fb764 100644 --- a/ioports.c +++ b/ioports.c @@ -75,7 +75,7 @@ void lcd_setbacklight(unsigned char flag, unsigned char level) __bitops_t d; #if 0 d.byte = _LCD_BACKLIGHT_TRIS; - d._LCD_BACKLIGHT_BIT = 0; + d._LCD_BACKLIGHT_BIT = 0; _LCD_BACKLIGHT_TRIS = d.byte; b.byte = _LCD_BACKLIGHT; @@ -92,27 +92,31 @@ void lcd_setbacklight(unsigned char flag, unsigned char level) PSTRCONbits.STRA = 0; T2CONbits.TMR2ON = 0; TMR2 = 0x00; - CCP1CON = 0x00; - CCPR1L = 0; + CCP2CON = 0x00; + CCPR2L = 0; + CCPR2H = 0; } else { unsigned char h,l; // lv = level; // lv <<= 2; // level = (level * 25) / 10; // level = 255; - h = level >> 1; // PWM Level - if(level == 255) h = 255; + h = level >> 1; + if(h == CCPR1L) return; // l = 2 << 4; //(lv & 0x0300) >> 4; - PSTRCONbits.STRA = 1; - CCPR1L = h; - CCPR1H = h; + d.byte = _LCD_BACKLIGHT_TRIS; + d._LCD_BACKLIGHT_BIT = 1; + _LCD_BACKLIGHT_TRIS = d.byte; + //PSTRCON = 0; + CCPR2L = h; + CCPR2H = h; b.b2 = 1; b.b3 = 1; - CCP1CON = b.byte | 0; - PR2 = 0x65; + CCP2CON = b.byte; + PR2 = 50; PIR1bits.TMR2IF = 0; - T2CON = 0b01111001; // Pre-scaler=1/16,Post-scaler = 1/16 - // -> Freq = 1.22KHz * 4 = 4.84KHz. + T2CON = 0b01111000; // Pre-scaler=1/1,Post-scaler = 1/16 + // -> Freq = 2.44KHz * 16 = 39.4KHz. TMR2 = 0x00; T2CONbits.TMR2ON = 1; do { -- 2.11.0