try this
PIC12F675
beware of high voltage
50Hz only
' 1MHz*64=64usec ca si tact
' 0.01/64usec=156,25 pasi
' deci Mindelay=0 si maxdelay=156 pentru 50Hz
' in acest caz prescallerul este 64 deci OPTION_REG=0x0x0101
' in acest caz bitul de overflow este INTCON.2 si se curata soft
' resetul TMR0 se face soft
' incarcarea TMR0 se face soft
' merge face sesizare intreruperi si tot restul! E FAIN!
' INITIALIZARE MCU
'
' initializare TS pe porturi
TRISIO = %00001111
'
OPTION_REG=%10000101 ' Enable pull-ups a fost 11000101
WPU=%00000111 ' Enable pull-ups on GP0, GP1
CMCON=7 ' Disable analog comparator
ANSEL=0 ' Disable analog converter
IOC.2=1
' initializare intreruperi la start numai cele pe GPIO2/INT
INTCON=%01011000
Pb_Inc var GPIO.0 ' Input for INCREMENT/ON push button
Pb_Dec var GPIO.1 ' Input for DECREMENT/OFF push button
ACline var GPIO.2 ' Input for the FullWave rectify AC line
Triac var GPIO.5 ' Output to TRIAC gate
Led var GPIO.4 ' Led output
delay var byte
onoff var bit
count_up var byte
count_dn var byte
maxbright var byte
minbright var byte
pas var byte
stare var bit
var1 var byte
prag var byte
pas1 var byte
maxbright=230
minbright=90 ' a fost 100
triac=0
delay=minbright
pas=20 ' a fost 25
pas1=2
onoff=0
count_up=0
count_dn=0
stare=0
var1=0
prag=6
on interrupt goto intrerupere
'
loop0:
gosub sunet1
triac=1
pause 500
triac=0
pause 500
triac=1
pause 500
triac=0
gosub sunet2
'
loop1:
' rutina de lighton
if pb_inc=0 or pb_dec=0 then
gosub sunet1
onoff=1
repeat
if stare=0 then
delay=delay+1
stare=1
endif
until delay=maxbright
else
goto loop1
endif
'
start:
' rutina de dimmon si dimmoff
if delay<=minbright then
onoff=0
'goto loop1
else
onoff=1
endif
if pb_inc=0 and delay<maxbright then
if stare=0 and count_up>=pas then
var1=var1+1
if var1=prag then
delay=delay+1
var1=0
endif
count_up=25
stare=1
else
endif
else
if count_up>pas1 and count_up<pas and delay<maxbright then
' count_up=0
goto lighton
else
endif
endif
if pb_dec=0 and delay>minbright then
if delay=(minbright+1) then
goto start
endif
if stare=0 and count_dn>=pas then
var1=var1+1
if var1=prag then
delay=delay-1
var1=0
endif
count_dn=25
stare=1
else
endif
else
if count_dn>pas1 and count_dn<pas and delay>minbright then
' count_dn=0
goto lightoff
else
endif
endif
goto start
'
'
'
lighton:
repeat
count_up=0
if stare=0 then
delay=delay+1
stare=1
endif
until delay=maxbright
goto start
'
lightoff:
repeat
count_dn=0
if stare=0 then
delay=delay-1
stare=1
endif
until delay=minbright
onoff=0
gosub sunet2
goto loop1
sunet1:
sound led,[102,5,104,5,106,5,108,5,110,5,112,5,114,5,116,5,118,5,120,5,122,5,124,5,126,5]
return
'
sunet2:
sound led,[126,5,124,5,122,5,120,5,118,5,116,5,114,5,112,5,110,5,108,5,106,5,104,5,102,5]
return
'
disable
intrerupere:
' pe acline
if INTCON.1=1 then
INTCON.7=0
INTCON.1=0
TMR0=delay
INTCON.5=1
INTCON.4=0
INTCON.7=1
stare=0
led=not onoff
else
endif
' pe TMR0
if INTCON.2=1 then
INTCON.7=0
INTCON.2=0
if onoff=1 then
triac=1
else
triac=0
endif
if pb_inc=0 then
count_up=count_up+1
else
endif
if pb_dec=0 then
count_dn=count_dn+1
else
endif
if pb_inc=1 and pb_dec=1 then
count_up=0
count_dn=0
endif
triac=0
else
endif
INTCON.7=1
resume
enable