' Name : cam_switch_keep_alive.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2006 ' : All Rights Reserved ' Date : 3/2/2006 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' This version does not monitor awake line; it takes a picture every 30 seconds to keep camera alive. ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - not used ' Pin6 = GPIO.1 - i/o - LED - tie pin 6 to high side (anode) of led, tie led low side (cathode) through resistor to ground ' Pin5 = GPIO.2 - i/o - shutter - drive to ground to close shutter - connect to shutter switch ' Pin4 = GPIO.3 - input only - RC PWM signal - tie to RC signal via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - not used ' Pin2 = GPIO.5 - i/o - not used ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal Dim Pulselen As Byte ' Pulselen can be 0 - 255, 100 = 1 ms, 200 = 2 ms Dim Init As Byte ' Init used to flash LED Dim Waittime As Word ' Waittime can be 0 - 32767 Dim State As Byte ' State can be 0 - 4 Clear ' set all variables = 0 Blink: For Init = 1 To 3 ' blink led 3 times High GPIO.1 ' pin 6 - turn led on DelayMS 200 ' wait 0.2 seconds Low GPIO.1 ' pin 6 - turn led off DelayMS 200 ' wait 0.2 seconds Next ReadPWM: Pulselen = PulsIn GPIO.3, High ' pin 4 - read high pulse length, times out after .65535 seconds DelayMS 15 ' delay 15 ms If Pulselen < 50 Then GoTo Blink ' no signal -> blink led again If State = 0 And Pulselen > 75 And Pulselen < 125 Then State = 1 ' state 0 , low pulse -> go to state 1 If State = 1 And Pulselen > 175 And Pulselen < 225 Then State = 2 ' state 1 , high pulse -> go to state 2 If State = 2 And Pulselen > 75 And Pulselen < 125 Then State = 3 ' state 2 , low pulse -> go to state 3 If State = 3 And Pulselen > 75 And Pulselen < 125 Then GoTo waitcounter ' state 3 , low pulse -> waiting, increment wait counter If State = 3 And Pulselen > 175 And Pulselen < 225 Then GoTo takepicture ' state 3 , high pulse -> take a picture If State = 4 And Pulselen > 75 And Pulselen < 125 Then State = 3 ' state 4 , low pulse -> stick has toggled low, go to state 3 If State = 4 And Pulselen > 175 And Pulselen < 225 Then GoTo waitcounter ' state 4 , high pulse -> stick has not toggled low, increment wait counter GoTo ReadPWM ' restart loop for all other possibilities waitcounter: ' increment wait counter Waittime = Waittime + 1 ' + 1 If Waittime > 900 Then GoTo takepicture ' if wait couter > timeout then take a picture to keep camera awake GoTo ReadPWM takepicture: ' take a picture Low GPIO.2 ' pin 5 - drive it low - close the shutter High GPIO.1 ' pin 6 - turn led on DelayMS 250 ' keep shutter closed and LED on for 0.25 seconds Input GPIO.2 ' pin 5 - set to tristate - high impedance Low GPIO.1 ' pin 6 - turn led off Waittime = 0 ' reset wait counter State = 4 ' set state as picture taken DelayMS 3000 ' wait 3 seconds for camera to store picture GoTo ReadPWM ' start it all again