walumbe
Junior Member level 2
- Joined
- Oct 15, 2013
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 174
Hi,
I am using MikroBasic Pro to program a PIC12F683 to turn on an output(GP2) for a given time (T) when two inputs(GP0 and GP1) both high. I would like to reset the time (T) when there is a positive going trigger at GP1 that is tied to a vibration switch and GP0 is high. Is there a function that handles this? I have tried using a counter variable with a time delay but that does not seem to work. The output LED turns off aftere time (T). Below is the code that I have so far.
I am using MikroBasic Pro to program a PIC12F683 to turn on an output(GP2) for a given time (T) when two inputs(GP0 and GP1) both high. I would like to reset the time (T) when there is a positive going trigger at GP1 that is tied to a vibration switch and GP0 is high. Is there a function that handles this? I have tried using a counter variable with a time delay but that does not seem to work. The output LED turns off aftere time (T). Below is the code that I have so far.
Code:
dim count as byte 'define variable count as byte
sub procedure Led_On
if Button(GPIO, 1, 10, 1) then 'detect HIGH on GP1
GPIO.B2 = 1
Delay_ms(10000)
else
end if
end sub
sub procedure Check_Vibration 'If GP1 is high reset counter
if Button(GPIO, 1, 10, 1) then
count = 0
else
end if
end sub
main:
ANSEL = 0
ADCON0 = 0
CMCON0 = 7
TRISIO = %00000011 'Set GP0 and GP1 as inputs , GP2 as output
GPIO.B0 = 0 'Initial GP0 value -> Input Dark Sensor
GPIO.B1 = 0 'Initial GP1 value -> Input Vibration Sensor
GPIO.B2 = 0 'Initial GP2 value -> Output LED
count = 0 'Initialize count
TestPin = 0 'Initialize value of Pin6
while True
do
if Button(GPIO, 0, 1, 1) then 'detect HIGH on GP0
Led_On
GPIO.B1 = 0
Check_Vibration
end if
count = count + 1
loop until count = 12
GPIO.B2 = 0
wend
end.