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 have written code for a PIC12F683 using a 4.0Mhz crystal. The pins are configured as follows:
GP0 - Phototransistor tied to ground via a resistor. Another resistor tied from this pin to +5V
GP1 - a vibration sensor switch (Shot Circuit when there is no vibration) tied to ground with a resistor tied from this pin to +5V
GP2 - tied to a transistor that turns on an LED board when on.
I am trying to turn ON the LED board via GP2 when either GP0 AND GP1 are high for a given period. So far I have it working, but I'm unable to turn off GP2 when the program goes into the interrupt routine for sensing the vibration. I stays on as long as there is vibration even if there is light. Any suggestions on how I could do this would be appreciated.
I have written code for a PIC12F683 using a 4.0Mhz crystal. The pins are configured as follows:
GP0 - Phototransistor tied to ground via a resistor. Another resistor tied from this pin to +5V
GP1 - a vibration sensor switch (Shot Circuit when there is no vibration) tied to ground with a resistor tied from this pin to +5V
GP2 - tied to a transistor that turns on an LED board when on.
I am trying to turn ON the LED board via GP2 when either GP0 AND GP1 are high for a given period. So far I have it working, but I'm unable to turn off GP2 when the program goes into the interrupt routine for sensing the vibration. I stays on as long as there is vibration even if there is light. Any suggestions on how I could do this would be appreciated.
Code Basic4GL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 dim Count as word dim Temp as byte dim DarkValue as word sub procedure Interrupt if GPIF_bit = 1 then Temp = GPIO ' Any access to the GPIO register will reset the IOC Count = 0 ' Each time an edge is detected at GP1, reset the timer end if GPIF_bit = 0 ' Clear the Interrupt flag end sub main: ANSEL = %00000001 ' Set AN0 as analog and the rest digital ADCON0 = %00000001 CMCON0 = 7 IOC1_bit = 1 ' Enable Interrupt-on-change feature at GP1 GPIE_bit = 1 ' Enable peripheral interrupts 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 while TRUE DarkValue = ADC_read(0) if (DarkValue > 286) and (Button(GPIO, 1, 5, 1)) then ' Checks for voltage >1.4V at GP0 and a high at GP1 GPIO.B2 = 1 ' Turn on transistor to power the LED board GIE_bit = 1 ' Enable interrupts before entering the counter loop do Delay_ms(12) 'Delay for 12ms Inc(Count) loop until Count = 10000 GIE_bit = 0 ' And disable them after leaving Count = 0 ' Reset counter when the loop ends GPIO.B2 = 0 ' Turns off the LEDs end if wend end
Last edited by a moderator: