Hi all, no luck, Please gothru my code...Thanks.
Include "MODEDEFS.BAS" ' Include Shiftin/out modes
@ device PIC16F877A , xt_osc, wdt_on, pwrt_on, protect_on ,lvp_off
Define Osc 4 ' using a 4 MHz oscillator
; 76543210
TRISA = %00000000 ' ALL OUTPUTS
TRISB = %11111111 ' ALL INPUTS- KEYBRD
TRISC = %11110001 '
OPTION_REG.7=0 'Enable internal pull-ups
OPTION_REG = %11111000 ' Assign prescaller to WDT
TRISA = 0 ' Set PORTA as output
T1CON.1 = 0 ' Set TIMER1 clock source to internal clock
INTCON = %01000000 ' Enable peripheral interrupts
PIE1 = %00000001 ' Enable TMR1 overflow interrupt
CCP1CON=%00001100 ' PWM MODE
UpButton Var PORTB.0
DownButton var PORTB.1
PWMOut Var PORTC.1 ' PWM Output
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select
B0 var Byte
Vduty var Byte
Vduty=0
B0=1
pause 100
Main:
if UpButton =0 then
If Vduty<255 Then Vduty=Vduty+B0
Gosub HpwmSet
endif
if DownButton =0 then
If Vduty>0 then Vduty=Vduty-B0
Gosub HpwmSet
endif
goto Main
HpwmSet:
HPWM 1,25,1000 '4.00khz
'HPWM 1,25,250 '16.00khz. tried this also.
Return
Bookmarks