Try this code.
LED is on GPIO.2
Button must be pulled down to GND by a resisitor (10K).
And must be pulled high by the button (to Vdd).
Code:@ DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF OSCCON = %01110001 ' Internal 8MHz osc. DEFINE OSC 8 ' ======= Common Settings ================================= ADCON0 = 0 ANSEL = 0 CMCON0 = 7 ' Comparators off. TRISIO = 0 GPIO = 0 ' ============= PWM Settings ========= CCP1CON = %00001100 ' CCP1, PWM mode PR2 = 250 ' T2CON = %00000101 ' TMR2 on, prescaler 1:4 CCPR1L = 0 Speed var CCPR1L Btn Var GPIO.3 ' Assuming ; the pin is pulled down to GND by 10K resistor, and button pulls it high to Vdd. ' LED is connected to GPIO.2 (on board PWM module) pause 10 Start: if btn then if speed + 85 < 256 then ' 0, 85, 170, 255, 0 speed = speed + 85 else speed = 0 endif while btn : pause 20 : wend endif pause 2 goto Start end




Bookmarks