Added unmodified code for Nikon signaling from BigMike's OML-L3 project.
[OpenInterval.git] / cameras / oml-l3.v2.0.0-8mhz.asm
blobf4317efd26648d3a0af09f799d123f9d1722486c
1 ; Infrared remote control for Nikon D70 with Atmel 8bit MCU
2 ;
3 ; Copyright (C) 2005, 2006 Michele Bighignoli - Laives (BZ) - ITALY # www.bigmike.it/ircontrol
5 ; Version 2.0.0 - 03/2006
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation; either version 2 of the License, or
11 ; (at your option) any later version.
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 ; Implementation note:
24 ; ---------------------------
25 ; IR led is controlled by PD0 (with NPN transistor).
26 ; Led is "on" when PD0 is high.
28 ; This code has tested with ATTiny2313 and ATMEGA8535 with 8.0 MHz Xtal
30 ; Should work with every Atmel 8bit MCU
33 ; Special thanks to:
34 ; ------------------
35 ; Gerhard Schmidt (DG4FAC) - http://www.avr-asm-tutorial.net/index.html
36 ; Brian Hammill - http://www.ipass.net/~hammill
39 ; WaveForm data (03/2006 version):
41 ; Infrared period = 26us (~38.4kHz)
43 ; Strart pulse: 2000us
44 ; pause: 27830us
45 ; 1st pulse: 390us
46 ; pause: 1580us
47 ; 2nd pulse: 410us
48 ; pause: 3580us
49 ; 3rd pulse: 400us
50 ; longpause: 63200us
52 ; REPEAT ONE TIME
55 .include "tn2313def.inc" ; ATTiny2313
56 ;.include "2313def.inc" ; AT90S2313
59 .DEF DelayReg = R23
60 .DEF MainLoopC = R22
61 .DEF Counter = R21
62 .DEF Counter2 = R20
65 reset:
66 rjmp startup
67 reti ; ext int 0 (not used)
68 reti ; ext int 1 (not used)
69 reti ; timer1 (not used)
70 reti ;
71 reti ;
72 reti ; timer0 (not used)
73 reti ; UART RRF Not Used
74 reti ; UART TRE Not Used
75 reti ; UART TRDE Not Used
76 reti ; analog comparator not used
79 delay130:
80 ; This is a 13.0 uS delay (104 cycles @ 8MHz)
82 ; sbi/cbi = 2 cycles
83 ; rcall = 3 cycles
85 nop
86 nop
88 delay130_led_on:
89 nop
90 nop
91 nop
93 delay130_led_off:
94 nop
95 nop
96 ldi DelayReg,30 ; 1 cycle
97 delay130_loop:
98 dec DelayReg ; 1 cycle
99 brne delay130_loop ; 2 cycle if jump to label, 1 if not
100 ret ; 4 cycles
103 ; Code executed at startup
105 startup:
106 ; stack is needed!
107 ; initialize the stack pointer
109 ; ENABLE IF "SPH" EXISTS
110 ; ldi R16,HIGH(RAMEND)
111 ; out SPH,R16
113 ldi R16,LOW(RAMEND)
114 out SPL,R16
116 ; Set PortD = OUT
117 ldi R16,0xFF
118 out DDRD,R16
121 ldi MainLoopC,2 ; Send a complete waveform 2 times
123 mainloop:
125 ; Send start pulse (2000 uS)
126 ldi Counter,77 ; (13 uS * 2 ) * 77 = 2002 uS
127 startpulse:
128 sbi PORTD,0 ; LED on
129 rcall delay130_led_on ; Wait 13.0 uS
130 cbi PORTD,0 ; LED off
131 rcall delay130_led_off ; wait 13.0 uS
132 dec Counter
133 brne startpulse
135 ; Pause (27830 uS)
136 ldi Counter,237
137 startpause:
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 startpause
150 rcall delay130_led_off
152 ; Send first pulse (390 uS)
153 ldi Counter,15
154 pulse1:
155 sbi PORTD,0 ; LED on
156 rcall delay130_led_on
157 cbi PORTD,0 ; LED off
158 rcall delay130_led_off
159 dec Counter
160 brne pulse1
162 ; Pause (1580 uS)
163 ldi Counter,118
164 pause1:
165 rcall delay130
166 dec Counter
167 brne pause1
169 ldi Counter,5
170 pause1b:
171 dec Counter
172 brne pause1b
175 ; Send 2nd pulse (410 uS)
177 ; NOTE: with Counter=16 the pulse width is 416 uS (counting the last "led off" time)
178 ; using Counter=15 and an additional "led on", it's possible to add the last 7 uS (led off) to the pause 2
180 ; Counter=15 = 390 uS +
181 ; "led on" = 13 uS =
182 ; TOTAL = 403 uS
185 ldi Counter,15
186 pulse2:
187 sbi PORTD,0 ; LED on
188 rcall delay130_led_on
189 cbi PORTD,0 ; LED off
190 rcall delay130_led_off
191 dec Counter
192 brne pulse2
194 sbi PORTD,0 ; LED on
195 rcall delay130_led_on
196 cbi PORTD,0 ; LED off
198 ; Pause (3580 uS + 7 uS from pulse2 = 3587 uS)
199 ldi Counter,136
200 pause2:
201 rcall delay130
202 rcall delay130
203 dec Counter
204 brne pause2
206 ; Send 3th pulse (400 uS) - (in real world = 403 uS)
207 ldi Counter,15
208 pulse3:
209 sbi PORTD,0 ; LED on
210 rcall delay130_led_on
211 cbi PORTD,0 ; LED off
212 rcall delay130_led_off
213 dec Counter
214 brne pulse3
216 sbi PORTD,0 ; LED on
217 rcall delay130_led_on
218 cbi PORTD,0 ; LED off
220 dec MainLoopC
221 ; No long pause before sleep
222 breq ContinueToSleep
225 ; Pause for 63200 uS
226 ldi Counter,239
227 longpause:
228 ldi Counter2,10
229 longpause1:
230 rcall delay130
231 rcall delay130
232 dec Counter2
233 brne longpause1
234 dec Counter
235 brne longpause
237 ; At moment : 63126 uS + 3 uS from pulse3 = 63129 uS
239 ldi Counter,5
240 longpause2:
241 rcall delay130
242 dec Counter
243 brne longpause2
245 ; At moment 63193 uS + 3 uS from pulse3 = 63196 uS
247 ldi Counter,10 ; 3,75 uS
248 longpause3:
249 dec Counter
250 brne longpause3
252 rjmp mainloop
254 ContinueToSleep:
255 sleep
256 rjmp ContinueToSleep