;****************************************************************************** ;Notes: Code by Greg Lipscomb of DIY Live ; www.diylive.net ;****************************************************************************** ; A flash sensed will cause a 1/2 second High output that will ; allow the RLY2 to connect the flash switch. Following this ; the program will ouptut a Low to GP0 that will activate RLY1 ; for 16 seconds, and recharge the camera. This number can be ; changed under the "Defines" section under the variable name ; "Numsec". ; A PIC12F675 has two banks for the function registers. If you ; are accessing a function register, you have to be in the right bank. ; TRISIO register is where you set the pin inputs or outputs, and is ; in Bank1. Ths GPIO register is in Bank2. ; This program demonstrates a simple brute force polled switch ; debounce routine. Toggle action is initiated immediately on switch ; closure. Further action is inhibited until the switch is ; released and fully debounced. ; ; It is guaranteed that the timing will be off for your flash. You will have to ; adjust it to fit your own needs. Set your camera on a long exposure, ; Like 1/2 second, and see if you can get it to flash. If you don't see ; it, and you have a preflash, it is firing too quickly. Add more time ; between the switch sensed, adn the togglerly. Ideally, you should be ; able to see the flash from 1/60 to 1/200 of a second. ; ;****************************************************************************** list p=12F675 ; list directive to define processor #include ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The labels following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;****************************************************************************** ;Defines ;****************************************************************************** #define Bank0 0x00 ; Defines memory address for Bank0 #define Bank1 0x80 ; Defines memory address for Bank1 #define SWITCH GPIO,3 ; This defines GP3 as variable Switch #define D0_1Tris B'11001110' ; This tells GPIO-0,4, and 5 to be outputs, and the others are inputs #define Numsec D'16' ; Set this to the number of seconds to charge flash ;****************************************************************************** ;General Purpose Registers (GPR's) ;****************************************************************************** cblock 0x20 State ; State of Flash trigger, either on (1) or off (0) Flags ; LED flags CountH ; Tenms counter - MS Byte CountL ; Tenms counter - LS Byte Sec_counter ; Counter used for Numsec endc ;****************************************************************************** ;Reset Vector ;****************************************************************************** ORG 0x000 ; processor reset vector nop ; required by in circuit debugger goto Init ; go to beginning of program ;****************************************************************************** ;Interrupt Vector ;****************************************************************************** ORG 0x004 return ; interrupt trap - returns without re-enabling ;****************************************************************************** ;Initialization ;****************************************************************************** Init ;call 0x3FF ; retrieve factory calibration value ; comment instruction if using simulator, ICD2, or ICE2000 BANKSEL Bank1 ; BANK1 movwf OSCCAL ; update register with factory cal value movlw D0_1Tris ; set direction so GPIO pins 0,4,5 are outputs movwf TRISIO ; all others are inputs (high-z) clrf ANSEL ; configure A/D I/O as digital banksel Bank0 ; change back to PORT memory bank movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O movwf CMCON ; clrf Flags ; set initial LED state as off clrf State ; set initial state as off bsf GPIO,4 ; set ready LED off at beginning by setting High bcf GPIO,5 ; initialize flash output pin as off call powerflash ; call powerflash subroutine bcf GPIO,4 ; set ready LED on by setting GPIO4 Low ;****************************************************************************** ;Main ;****************************************************************************** Main btfsc SWITCH ; wait in loop until SWITCH, closure, or flash is sensed goto Main ; SWITCH closure grounds input pin, or flash sensed call onehundredms; wait 100 ms between preflash, and firing flash - remove if no preflash ; You may need to call tenms here to add time, or if it is too long of a ; delay, you may need to call tenms 9 times, instead of calling onehundredms call ToggleRLY ; SWITCH closure sensed - toggle LED goto Main ;****************************************************************************** ;Subroutines & Functions ;****************************************************************************** ;****************************************************************************** ;ToggleRLY - Toggles Flash states, State0 turns LED on, and Relay off, ;State1 turns off LED, and turns on RLY2. It also has a 400 ms delay for ;leaving on the RLY2. It then turns off GP5. Powerflash is a subroutine ;that turns on RLY1 for 16 seconds so that it can recharge the camera. ;After powerflash, it resets the state to State0 ;****************************************************************************** ToggleRLY btfss State,0 ; test flag of present LED condition goto State0 ; the LED is presently off - go turn it on goto State1 ; the LED is on, so go to turn it off State0 bsf State,0 ; Bit set F, or set the State to State1 bcf GPIO,4 ; Ground GPIO 4 to turn LED on bcf GPIO,5 ; Ground GPIO 5 to turn flash_trigger off return ; return to calling routine State1 bcf State,0 bsf GPIO,4 ; Set GPIO 4 high to turn LED off bsf GPIO,5 ; Set GPIO 5 high to turn on flash trigger call onehundredms ; Leave Flash relay trigger on for 400 microseconds call onehundredms call onehundredms call onehundredms bcf GPIO,5 ; Turn off flash trigger relay. call powerflash call State0 return ; return to calling routine return ; return to calling routine ;****************************************************************************** ;Ten millisecond delay ;****************************************************************************** Tenms ; Timer constants (TenMSH and TenMSL) are a function of the ; instruction execution time and number of instructions in each loop. Debounce ; time for this example is: ; Timer overhead + TenMSH * [outer loop time + (TenMSL * inner loop time)] ; or [2 + TenMSH * (5 + (TenMSL * 5))]*(4/fosc)= .010 ; ; Arbitrarily choosing 99 for TenMSL we solve for TenMSH ; 2 + TenMSH * (5 + (99 * 5)) = 10,000 ; TenMSH = 9998/500 ~ 20 #define TenMSH D'20' #define TenMSL D'99' movlw TenMSH ; set outer timer loop count movwf CountH ; outer loop overhead is 2 instructions ;========== outer loop [TenMSH * 5 instruction cycles*(Inner loop time)] ====== SD10 movlw TenMSL ; set inner timer loop movwf CountL ;----------------- inner loop (TenMSL * 5 instruction cycles) ----------------- SD20 decfsz CountL,f ; inner loop countdown goto SD20 ; test SWITCH while counting ;-------------------------------- inner loop ---------------------------------- decfsz CountH,f ; outer loop countdown goto SD10 ; reset inner loop after each outer loop count ;================================ outer loop ================================== return ; full countdown and no bounces achieved - exit ;****************************************************************************** ;Power Flash - This function will start the RLY1, and will then pause for ;16 seconds. It will then turn off the RLY1. This can be used to charge ;a flash that is not automatic chargine. It will also work with a flash that ;is an automatic charging flash. RLY1 is controlled by GP0, and is set to ;work on a grounded pin. This is done by "bcf" - or bit clear f. ;****************************************************************************** powerflash bcf GPIO,0 ; Turn on Powerflash relay by grounding GPIO 0 call numsecdelay ; Call 16 second delay, keeps flash from going off while charging bsf GPIO,0 ; Turn off powerflash relay by Setting GPIO 0 high return ;****************************************************************************** ;One hundred millisecond delay ;****************************************************************************** onehundredms call Tenms call Tenms call Tenms call Tenms call Tenms call Tenms call Tenms call Tenms call Tenms call Tenms return ;****************************************************************************** ;One Second delay ;****************************************************************************** onesec call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms call onehundredms return ;****************************************************************************** ;Variable Seconds Dalay ;This value can be changed by defining Numsec at the top. The default value is ;16 Seconds. ;****************************************************************************** numsecdelay movlw Numsec movwf Sec_counter num_sec_loop call onesec decfsz Sec_counter,1 goto num_sec_loop return END ; directive 'end of program'