OSDN Git Service

[LCD] Change IOPORT RC2 TO RC1 (PWM1 to PWM2) issue of ECCP, P1B-P1D is synced with...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 18:17:28 +0000 (03:17 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 18:17:28 +0000 (03:17 +0900)
iodef.h
ioports.c

diff --git a/iodef.h b/iodef.h
index 5a89569..699048e 100644 (file)
--- 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
index 1e22961..07fb764 100644 (file)
--- 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 {