Try this one. I don't use LCD but echo the results to the PC.
Code:
@ __CONFIG _HS_OSC & _MCLRE_ON & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
DEFINE OSC 10
CMCON = 7
PORTA = 0
PORTB = 0
TRISA = 0
TRISB = %00000010
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 64 ' 9600 Baud @ 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
Duty VAR WORD ' Duty cycle value (CCPR1L:CCP1CON<5:4>)
CCP1CON = %00001100 ' PWM mode
T2CON = %00000110 ' Turn on Timer2, Prescale=1:16
PR2 = 155 ' Set PR2 to get 1KHz out
duty = 125 ' Set duty cycle to 20%
GOSUB ChangeDuty
Loop:
HSerIn [DEC Duty]
IF Duty > 625 THEN
HSEROUT ["Duty too high... MAX = 625",13,10]
ELSE
GOSUB ChangeDuty
HSEROUT ["Duty=",DEC Duty,13,10]
ENDIF
GOTO Loop
ChangeDuty:
CCP1CON.4 = Duty.0 ' Store duty to registers as
CCP1CON.5 = Duty.1 ' a 10-bit word
CCPR1L = Duty >> 2
RETURN
and read the FAQ about the fuse config... i think it's your main problem.
So far, it's working here.
Bookmarks