#include <htc.h>
-#define PINS_PORTA 0b10011000
-#define PINS_PORTB 0b00001000
+#define PINS_PORTB 0b00101001
+#define PINS_PORTC 0b00000100
void rgb_init()
{
/* Initialize rgb
- * CCP1 on RB3, CCP2 on RA7, CCP3 on RA3, CCP4 on RA4
+ * CCP1 on RC2, CCP2 on RB3, CCP3 on RB5, CCP4 on RB0
* - Fosc = 8 MHz, 4 MHz, 2 MHz
- * - Prescale = 4, 4, 1
+ * - Prescale = 4, 1, 1
* - PRx value = 0xff
- * = f(rgb) = 1.95 kHz, 0.98 kHz, 1.95 kHz
+ * = f(rgb) = 1.95 kHz, 3.90 kHz, 1.95 kHz
*/
/* Set rgb Rxn pins as outputs. */
- PORTA &= ~PINS_PORTA;
- TRISA &= ~PINS_PORTA;
PORTB &= ~PINS_PORTB;
TRISB &= ~PINS_PORTB;
+ PORTC &= ~PINS_PORTC;
+ TRISC &= ~PINS_PORTC;
- /* Configure ECCP1 */
+ /* Configure CCP1 */
CCP1CON = 0b00001100;
- CCPR1L = 0; /* Initial rgb value; only using 8 LSBs */
+ CCPR1L = 0; /* Initial red value; only using 8 LSBs */
- /* Configure ECCP2 */
- APFCON0 |= 0b00001000; /* Use alternate output pin RA7 */
+ /* Configure CCP2 */
+ CCP2SEL = 1; /* CCP2 is on RB3 */
CCP2CON = 0b00001100;
- CCPR2L = 0; /* Initial rgb value; only using 8 LSBs */
+ CCPR2L = 0; /* Initial grn value; only using 8 LSBs */
/* Configure CCP3 */
+ CCP3SEL = 1; /* CCP2 is on RB5 */
CCP3CON = 0b00001100;
- CCPR3L = 0; /* Initial rgb value; only using 8 LSBs */
+ CCPR3L = 0; /* Initial blu value; only using 8 LSBs */
/* Configure CCP4 */
CCP4CON = 0b00001100;
- CCPR4L = 0; /* Initial rgb value; only using 8 LSBs */
+ CCPR4L = 0; /* Initial wht value; only using 8 LSBs */
/* Configure Timer2. Start it to set 0 outputs, then stop it. */
- CCPTMRS = 0; /* All CCPx use Timer 2 */
+ CCPTMRS0 = 0; /* CCP[1-4] use Timer 2 */
TMR2IF = 0;
PR2 = 0xff;