I try to make an intelligent timer. Schematic is attached ; I try to explain what I intend to do ...
Conect the PIC to power source. LED is OFF.
When press for the first time the button, the timer begin to counting seconds while GPIO.5 is "0" and the counted seconds becomes the wipe_time, in seconds, while LED is ON.
At next (second) press of button, LED is ON for wipe_time seconds (previously stored).
At next (third) press of button, the timer begin again to counting another value of wipe_time (while GPIO.5 is on).
And so on, and so on ...
Unfortunately the hardware not react as expected ; LED is always ON ...Can figure out what I do wrong... Thanks in advance for support !
Code:@ Device PIC12F675,INTRC_OSC_NOCLKOUT, WDT_OFF,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF Include "C:\WIPPER\Elapsed.bas" ' just wsave(s) removed CLEAR DEFINE OSC 4 ANSEL=0 CMCON=7 TRISIO=%00100000 LED VAR GPIO.0 ; sets the GPIO.0 port as LED wipp_time var byte ; number of seconds while LED=off nr var bit nr = 0 wipp_time = 2 Gosub ResetTime ' Reset Time to 0d-00:00:00.00 loop: led = 0 IF GPIO.5 = 0 THEN nr=nr+1 if nr=1 then ' Setting wipe_time for the first time gosub StartTimer ELSE GOSUB WIPPER ' use pre-setting of wipe_time ENDIF ENDIF GOSUB END_sett if nr = 2 then nr = 0 ' ready for another setting of wipe_time goto loop END_sett: gosub StopTimer wipp_time = seconds ' seconds counts from the beginning of gpio.5 = 0 NR=1 GOSUB WIPPER Gosub ResetTime RETURN wipper: LED = 1 PAUSE 1000 LED = 0 PAUSE (wipp_time * 1000) return END


... Thanks in advance for support !



Bookmarks