I recently moved a project from a 16F88 to the 16F876A to gain more I/O. Previously the contrast of the LCD was controlled via PWM on CCP1, which worked perfectly. Since moving to the larger PIC I added PWM control of the backlight and can't get either to work.

I have set everything up the same way and have all the defines correct. I have reread Melanie's post about backlight and contrast control. I have no clue where I'm going wrong. Help?


; -----[ Fuses ]----------------------------------------------------------
@__config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF

; -----[ Setup ]----------------------------------------------------------
ADCON1=%10000110 ; Turn on A/D AN0 - Digital for the rest (16F876A specific)
CMCON=%00000111 ; Disable Comparators
TRISA=%11100001 ; PORTA Output/Input settings (1= Input 0=Output)
TRISB=%00000001 ; PORTB Output/Input settings (1= Input 0=Output)
TRISC=%10001000 ; PORTC Output/Input settings (1= Input 0=Output)
OPTION_REG.6=1 ; INTEDG rising edge=1 falling edge=0
T1CON.4=1
T1CON.5=1

; -----[ Defines ]----------------------------------------------------------
DEFINE OSC 20 ; 20 mhz XTAL (change notes above)
DEFINE I2C_SLOW 1

DEFINE HSER_BAUD 9600 ; 9600 Baud USART
DEFINE HSER_RCSTA 90h ; Enable USART RX
DEFINE HSER_TXSTA 24h ; Enable USART TX
DEFINE HSER_SPBRG 51 ; 9600 Bauds
DEFINE HSER_CLROERR 1 ; Clear all USART errors as they happen

DEFINE LCD_DREG PORTB ; LCD 20x2
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

DEFINE CCP1_REG PORTC ; HPWM 1 pin port
DEFINE CCP1_BIT 2 ; HPWM 1 pin bit
DEFINE CCP2_REG PORTC ; HPWM 2 pin port
DEFINE CCP2_BIT 1 ; HPWM 2 pin bit