Better debounce. High current output pin.
[OpenInterval.git] / openinterval.asm
blob70d6b3a0492d46d28304c3ce9c006ab331f15b3b
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/tn13def.inc"
19 .EQU buttonPin = 1 ; button
20 .EQU syncPin = 3 ; sync LED port
21 .EQU irPort = PORTB; ir LED port
22 .EQU irPin = 0 ; ir LED pin
24 .def mode = r16
25 .def tcounter = r17
26 .def tcounter2 = r18
27 .def Idelay = r19
28 .def Idelay2 = r20
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 ; Timer overflow handler
39 reti ; EEPROM Ready handler
40 reti ; Analog Comparator handler
41 reti ; Timer/Counter Compare Match A handler
42 reti ; Timer/Counter Compare Match B handler
43 reti ; Watchdog Time-out handler
44 reti ; ADC Conversion Complete handler
47 ;camera include file goes here
48 .include "cameras/Nikon_OML-L3.inc"
50 init:
51 ldi mode, low(ramend)
52 out spl, mode
53 ; enable sleep mode and INT0 on falling edge
54 ldi mode, (1 << SE) | (1 << ISC01)
55 out MCUCR, mode
57 ; disable ACD
58 ldi mode, (1 << ACD)
59 out ACSR, mode
61 ; set timer prescaler 1024
62 ; ldi mode, (1 << CS02) | (1 << CS00)
63 ; out TCCR0B, mode
65 ; reset timer
66 ldi mode, 0
67 out TCNT0, mode
69 ; enable INT0 interrupt
70 ldi mode, (1 << INT0)
71 out GIMSK, mode
73 ; Set portB input
74 sbi PORTB,buttonPin ; set b4 config. to enable internal pull-up.
75 cbi DDRB,buttonPin
76 ; Set portB output
77 sbi DDRB,irPin
78 sbi DDRB,syncPin
79 sbi DDRB,2
81 sbi irPort,irPin ; LED off
82 ldi tcounter,0
83 ldi tcounter2,1
84 ldi Idelay,0
85 ldi Idelay2,1
86 ldi mode,0
88 sei
91 testloop:
92 sbi irPort,syncPin
93 rcall shutterrelease
94 cbi irPort,syncPin
95 ; rcall longdelay
96 ; rjmp testloop
99 GoToSleep:
100 sleep
101 rjmp GoToSleep
103 TIM0_OVF:
105 cpi mode,0
106 breq ReturnFI
107 cpi mode,1
108 breq Timing
109 cbi irport,syncPin
110 cpi tcounter, 0
111 brne SKIP
112 cpi tcounter2,0
113 brne SKIP
114 sbi irport,syncPin
115 mov tcounter, Idelay
116 mov tcounter2, Idelay2
117 rcall shutterrelease
118 SKIP:
119 dec tcounter
120 brne ReturnFI
121 dec tcounter2
122 reti
123 Timing:
124 inc Idelay
125 brne ReturnFI
126 inc Idelay2
127 reti
129 ReturnFI:
130 push mode
131 in mode,GIFR
132 cbr mode,6
133 out GIFR,mode ; clear interrupt flags
134 pop mode
135 reti
136 LongDelay:
137 ldi Counter,255
138 intpause:
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 rcall delay130
148 rcall delay130
149 rcall delay130
150 rcall delay130
151 rcall delay130
152 rcall delay130
153 rcall delay130
154 rcall delay130
155 rcall delay130
156 rcall delay130
157 rcall delay130
158 rcall delay130
159 rcall delay130
160 rcall delay130
161 rcall delay130
162 rcall delay130
163 rcall delay130
164 dec Counter
165 brne intpause
168 INT0_hand:
169 rcall longdelay
170 rcall longdelay
171 rcall longdelay
172 rcall longdelay
173 rcall longdelay
174 cpi mode,2
175 breq BackToSleep
176 cpi mode,1
177 breq setDelay
178 ; reset timer0
179 ldi mode, 0
180 out TCNT0, mode
182 ; set timer prescaler 1024, turn on timer
183 ldi mode, (1 << CS02) | (1 << CS00)
184 out TCCR0B, mode
186 ; enable timer overflow
187 ldi mode, (1 << TOIE0)
188 out TIMSK0, mode
190 ldi mode,1 ; set timing mode
191 sbi irport,syncpin
192 rjmp ReturnFI
193 setDelay:
194 cbi irport,syncpin
195 ldi mode,2 ; set running mode
196 ldi tcounter,0
197 ldi tcounter2,0
198 rjmp ReturnFI
199 BackToSleep:
200 ldi mode,0
201 out TCCR0B, mode ; turn off timer0
202 ldi tcounter,0
203 ldi tcounter2,1
204 ldi Idelay,0
205 ldi Idelay2,1
206 rjmp ReturnFI