Quote Originally Posted by pescador View Post
'12f683

' ======= config SETUP =================================

#CONFIG
cfg = _INTOSCIO
cfg&= _WDT_ON
cfg&= _PWRTE_OFF
cfg&= _MCLRE_OFF
cfg&= _CP_OFF
cfg&= _CPD_OFF
cfg&= _BOD_ON
cfg&= _IESO_ON
cfg&= _FCMEN_ON
__CONFIG cfg
#ENDCONFIG

' ======= Common Settings =================================

OSCCON = %01110001 ' Internal 8MHz osc.
DEFINE OSC 8
CMCON0 = 7
ANSEL = 0
OUTPUT GPIO.1
INPUT GPIO.4

PLEDOUT var GPIO.2 ' PWM output
BUTTEN var GPIO.4 ' BUTTON IN

HERTZ VAR byte
DUTY VAR byte

' DUTY = 128 ' this is not needed any longer
HERTZ = 50



read EE_Duty, Duty ' read from EEPROM address EE_Duty to Duty variable
if Duty > 128 then Duty = 128 ' limit the duty to 128 if it is > 128

MAIN:

pwm pledout,duty,HERTZ ' PLM output

IF BUTTEN = 0 THEN
DUTY = DUTY - 2
IF DUTY < 10 THEN
DUTY = 128
ENDIF

' save the new duty to eeprom
write EE_Duty, Duty
ENDIF

GOTO MAIN
END
Hope this helps