Initial commit of OpenInterval.
[OpenInterval.git] / openinterval.asm
blob2cf78a5ce7e884de1da9b22a1ac0a9d31c7f8ad2
1 ; OpenInterval
3 ; Copyright 2007 Matthew F. Coates (mattjackets+openinterval at gmail.com)
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU General Public License as published by
7 ; the Free Software Foundation, either version 3 of the License, or
8 ; (at your option) any later version.
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU General Public License for more details.
15 ; You should have received a copy of the GNU General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 .include "include/tn12def.inc"
19 .EQU buttonPin = 1 ; button
20 .EQU syncPin = 3 ; sync LED port
21 .EQU irPort = PORTB; ir LED port
22 .EQU irPin = 4 ; ir LED pin
23 .equ FREQ = 0 ; start out with no interval
25 .def temp = r16
26 .def tcounter = r17
27 .def tcounter2 = r18
28 .def mode = r19
29 .def DelayReg2 = r24
31 .cseg
32 .org 0x0000
34 reset:
35 rjmp init ; Reset handler
36 rjmp INT0_hand ; INT0 handler
37 reti ; Pin change handler
38 rjmp TIM0_OVF ; Timer0 overflow handler
39 reti ; EEPROM Ready handler
40 reti ; Analog Comparator handler
42 ;camera include file goes here
43 .include "cameras/Nikon_OML-L3.inc"
45 init:
46 ; enable sleep mode and INT0 on falling edge
47 ldi temp, (1 << SE) | (1 << ISC01) & (0 << ISC00)
48 out MCUCR, temp
50 ; disable ACD
51 ldi temp, (1 << ACD)
52 out ACSR, temp
54 ; enable timer0
55 ; ldi temp, 0
56 ; out TCNT0, temp
58 ; set timer prescaler 1024
59 ldi temp, (1 << CS02) | (1 << CS00)
60 out TCCR0, temp
62 ; enable timer overflow
63 ldi temp, (1 << TOIE0)
64 out TIMSK, temp
66 ; enable INT0 interrupt
67 ldi temp, (1 << INT0)
68 out GIMSK, temp
70 ldi temp,0
71 ldi DelayReg,FREQ
72 ldi tcounter,FREQ
73 ldi mode,0
75 ; Set portB input
76 sbi PORTB,buttonPin ; set b4 config. to enable internal pull-up.
77 cbi DDRB,buttonPin
78 ; Set portB output
79 sbi DDRB,irPin
80 sbi DDRB,syncPin
82 sbi irPort,irPin ; LED off
83 rcall shutterrelease
84 sei
86 GoToSleep:
87 sleep
88 rjmp GoToSleep
90 TIM0_OVF: ; -- handle timer0 overflow, trigger shutter
91 cpi mode,1
92 breq TIMING
93 sbi portb,syncPin
94 cpi tcounter2, 0
95 brne SKIP
96 cpi tcounter,0
97 brne SKIP
98 cbi portb,syncPin
99 mov tcounter, DelayReg
100 rcall shutterrelease
101 skip:
102 dec tcounter
103 cpi tcounter,0
104 breq dectcounter2
105 reti
106 DecTCounter2:
107 dec tcounter2
108 reti
109 Timing:
110 inc DelayReg
111 cpi DelayReg,0
112 breq INCDelayReg2
113 reti
115 INCDelayReg2:
116 inc DelayReg2
117 reti
119 INT0_hand:
120 ldi Counter,255
121 intpause:
122 rcall delay130
123 rcall delay130
124 rcall delay130
125 rcall delay130
126 rcall delay130
127 rcall delay130
128 rcall delay130
129 rcall delay130
130 rcall delay130
131 rcall delay130
132 rcall delay130
133 rcall delay130
134 rcall delay130
135 rcall delay130
136 rcall delay130
137 rcall delay130
138 rcall delay130
139 rcall delay130
140 rcall delay130
141 rcall delay130
142 rcall delay130
143 rcall delay130
144 rcall delay130
145 rcall delay130
146 rcall delay130
147 dec Counter
148 brne intpause
150 cpi mode,1
151 breq setdelay
153 ; enable timer0
154 ldi temp, 0
155 out TCNT0, temp
156 cbi portb,SyncPin
157 ldi mode,1 ; timing mode
158 reti
160 SetDelay:
161 sbi portb,syncPin
162 mov tcounter,DelayReg
163 mov tcounter2,DelayReg2
164 ldi mode,2 ; running mode
166 reti