Thank you all.
I followed your directions Acetronics but and coded above. Maybe it work, maybe they need some fixes.
Simulating (no development board in class yet) in proteus, an strange behavior occurs on GPIO.0 they always stays up, even Iīve (I think at least) disabled pullup for them. Other pins appears ok.
What Iīve missed??
BTW, Perides, not Pericles. But no problem, common misspelling. :-)
Code:
' Pinout *
' 1 vdd vss 8 *
' 2 gp5/t1cki/osc1/clkin gp0/an0/cin+/icspdat 7 *
' 3 gp4/an3/t1g/osc2/clkout gp1/an1/cin-/vref/icspclk 6 *
' 4 gp3/mclr/vpp gp2/an2/tockin/int/cout 5 *
' *
'****************************************************************
@ device pic12F675, WDT_OFF, PWRT_ON, MCLR_OFF, INTRC_OSC_NOCLKOUT
define osc 4
CMCON = 7 'comparator off
ANSEL = 0 'all digital
'VRCON = 0 'comparator off
TRISIO= %000011 '1=in 0=out
'Enable PULL-UPS
OPTION_REG.7 = 0 'enable pullu-ps (0 enable/1 disable)
WPU = %000010 '1=on/0=off each pullup - enable pull-up only TK
L15 var GPIO.0 'line 15
TK VAR GPIO.1 'door sensor
LAMP VAR GPIO.2 'bulb
myPWM VAR word
main:
If TK = 0 Then LAMP = 1 'if TK goes down so LAMP goes UP
IF TK = 1 and LAMP = 1 then 'if TK goes down and LAMP is yet on
IF L15 = 1 THEN 'and we have canceled delay
goto justfade 'so go to fade lamp
else
GOTO delay 'and if delay was not canceled go to delay+fade
endif
ENDIF
GoTo main
delay:
FOR myPWM = 1 to 500 '500 loops for 5 second of 10ms delay
if L15 = 1 then justfade 'if L15 goes up so end delay
pause 10 'wait 10ms
next myPWM
justfade:
for mypwm = 255 to 1 step -1
PWM LAMP, myPWM, 255 'pwm bulp
if TK = 0 then GOTO main 'if TK goes down
NEXT myPWM
goto main
Bookmarks