- OWINIT save Register used in C
[owSlave2.git] / common / OWDS18B20_DS2438.S
1
2 // Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
3 // All rights reserved. 
4 // 
5 // Redistribution and use in source and binary forms, with or without 
6 // modification, are permitted provided that the following conditions are 
7 // met: 
8 // 
9 //  * Redistributions of source code must retain the above copyright 
10 //    notice, this list of conditions and the following disclaimer. 
11 //  * Redistributions in binary form must reproduce the above copyright 
12 //    notice, this list of conditions and the following disclaimer in the 
13 //    documentation and/or other materials provided with the 
14 //    distribution. 
15 //  * All advertising materials mentioning features or use of this 
16 //    software must display the following acknowledgement: This product 
17 //    includes software developed by tm3d.de and its contributors. 
18 //  * Neither the name of tm3d.de nor the names of its contributors may 
19 //    be used to endorse or promote products derived from this software 
20 //    without specific prior written permission. 
21 // 
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
33
34 #define _CHANGEABLE_ID_
35 #define _ZERO_POLLING_
36 //#define _DB_
37
38 #include "../common/OWConfig.s"
39 #include "../common/OWCRC8.s"
40
41 .extern pack1,8
42
43 //.extern  am2302_temp,2
44
45 #if  defined(__AVR_ATtiny25__)
46 .extern pack2,16
47 #else
48 .extern pack2,64
49 #endif
50 .extern  am2302_temp,2
51 .extern  am2302_hum,2
52 .comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
53
54
55 .macro CHIP_INIT        ;r_temp is pushed other Registers should be saved
56 Init_EEPROM_read:
57         push r_bytep
58         push r_rwbyte
59         sbic _SFR_IO_ADDR(EECR), EEPE
60         rjmp Init_EEPROM_read
61         ldi r_temp,0
62         out _SFR_IO_ADDR(EEARH), r_temp
63         ldi r_temp,2
64         out _SFR_IO_ADDR(EEARL), r_temp
65         sbi _SFR_IO_ADDR(EECR), EERE
66         in r_temp,_SFR_IO_ADDR(EEDR)
67         sbrs r_temp,7
68         rcall hrc_recall_eeprom_func1
69         pop r_rwbyte
70         pop r_bytep
71 .endm
72
73 .macro COMMAND_TABLE
74                 rjmp h_readscratchpad1
75                 rjmp h_writescratchpad1
76                 rjmp h_convert_run1
77                 rjmp h_readscratchpad_adr2
78                 rjmp h_readscratchpad2
79                 rjmp h_writescratchpad_adr2
80                 rjmp h_writescratchpad2
81 .endm
82
83 #include "../common/OWRomFunctionsDual.s"
84 #include "../common/OWTimerInterrupt.s"
85
86
87
88 ; Ab hier Geraeteabhaenging
89 #define OW_READ_SCRATCHPAD1 OW_FIRST_COMMAND+0
90 #define OW_WRITE_SCRATCHPAD1 OW_FIRST_COMMAND+1
91 #define OW_CONVERT_RUN1  OW_FIRST_COMMAND+2
92 #define OW_READ_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+3
93 #define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+4
94 #define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+5
95 #define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+6
96
97
98 ;---------------------------------------------------
99 ;       READ COMMAND and start operation
100 ;---------------------------------------------------
101
102
103 h_readcommand1:
104         clr r_bytep
105 #ifndef _DIS_FLASH_
106         FLASH_COMMANDS ; muss zu erst sein....
107 #endif
108         cjmp 0xBE,hrc_set_readscratchpad1
109         cjmp 0x4E,hrc_set_writescratchpad1
110         cjmp 0x44,hrc_set_convertT1
111         cjmp 0x48,hrc_copy_scratchpad1
112         cjmp 0xB8,hrc_recall_eeprom1
113         FW_CONFIG_INFO1
114 #ifdef _CHANGEABLE_ID_
115         CHANGE_ID_COMMANDS
116 #endif
117         ldi r_mode,OW_SLEEP
118         rjmp handle_end
119
120 hrc_set_readscratchpad1:
121         ldi r_mode,OW_READ_SCRATCHPAD1
122         ldi r_sendflag,1
123         CRCInit2
124         rjmp h_readscratchpad1
125
126 hrc_set_writescratchpad1:
127         ldi r_mode,OW_WRITE_SCRATCHPAD1
128         ldi r_bytep,2 ;start to write in 2
129         rjmp handle_end
130
131 hrc_recall_eeprom1:
132         rcall hrc_recall_eeprom_func1
133         rjmp handle_end
134
135
136
137 hrc_set_convertT1:
138         ldi r_temp,1
139         sts gcontrol,r_temp
140
141         ldi r_mode,OW_CONVERT_RUN1
142         ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
143 h_convert_run1:
144         ldi r_bcount,0
145         ldi r_rwbyte,0
146         rjmp handle_end_no_bcount       
147
148
149 hrc_copy_scratchpad1:
150         ldi r_bytep,2
151         configZ pack1,r_bytep
152         clr r_bytep
153 hrc_copy_scratchpad_EEPROM_write1:
154         sbic _SFR_IO_ADDR(EECR), EEPE   
155         rjmp hrc_copy_scratchpad_EEPROM_write1
156         ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
157         out _SFR_IO_ADDR(EECR), r_temp
158         ldi r_temp,0
159         out _SFR_IO_ADDR(EEARH),r_temp
160         out _SFR_IO_ADDR(EEARL), r_bytep
161         ld  r_rwbyte,Z+
162         out _SFR_IO_ADDR(EEDR), r_rwbyte
163         sbi _SFR_IO_ADDR(EECR), EEMPE
164         sbi _SFR_IO_ADDR(EECR), EEPE
165         inc r_bytep
166         cpi r_bytep,3
167         brne hrc_copy_scratchpad_EEPROM_write1
168         rjmp handle_end
169
170
171 hrc_recall_eeprom_func1:
172         ldi r_bytep,2
173         configZ pack1,r_bytep
174         clr r_bytep
175         clr r_temp
176 hrc_recall_eeprom_EEPROM_read1:
177         sbic _SFR_IO_ADDR(EECR), EEPE
178         rjmp hrc_recall_eeprom_EEPROM_read1
179         out _SFR_IO_ADDR(EEARH), r_temp
180         out _SFR_IO_ADDR(EEARL), r_bytep
181         sbi _SFR_IO_ADDR(EECR), EERE
182         in r_rwbyte,_SFR_IO_ADDR(EEDR)
183         st Z+,r_rwbyte
184         inc r_bytep
185         cpi r_bytep,3
186         brne hrc_recall_eeprom_EEPROM_read1
187         ret
188
189
190
191
192
193
194 ;---------------------------------------------------
195 ;   READ SCRATCHPAD
196 ;---------------------------------------------------
197
198 h_readscratchpad1:
199         cpi  r_bytep,8
200         breq h_readscratchpad_crc1
201         cpi  r_bytep,9
202         breq h_readscratchpad_all1
203         configZ pack1,r_bytep
204         ld   r_rwbyte,Z
205         rjmp h_readscratchpad_endc1
206 h_readscratchpad_crc1:
207         lds  r_rwbyte,crc
208 h_readscratchpad_endc1:
209         inc  r_bytep
210         ldi  r_bcount,1 
211         rjmp handle_end
212 h_readscratchpad_all1:
213         rjmp handle_end_sleep
214
215
216
217
218
219 ;---------------------------------------------------
220 ;   WRITE SCRATCHPAD
221 ;---------------------------------------------------
222
223 h_writescratchpad1:
224         configZ pack1,r_bytep
225         inc  r_bytep
226         cpi  r_bytep,5
227         breq h_writescratchpad_all1
228         st   Z,r_rwbyte
229         rjmp handle_end
230 h_writescratchpad_all1:
231         ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
232         st   Z,r_rwbyte
233         rjmp handle_end_sleep
234
235 ;*****************************************************************************************************************************************************************************************
236 ;*****************************************************************************************************************************************************************************************
237 ;*****************************************************************************************************************************************************************************************
238 ;*****************************************************************************************************************************************************************************************
239 ;*****************************************************************************************************************************************************************************************
240
241
242
243
244
245 h_readcommand2:
246         clr r_bytep
247 #ifndef _DIS_FLASH_
248         FLASH_COMMANDS ; muss zu erst sein....
249 #endif
250         cset 0xBE,OW_READ_SCRATCHPAD_ADR2
251         cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2
252         cjmp 0x44,hrc_set_convertT2
253         cjmp 0xB4,hrc_set_convertV2
254         FW_CONFIG_INFO2
255         //cljmp 0x85,hrc_fw_configinfo2
256 #ifdef _CHANGEABLE_ID_
257         CHANGE_ID_COMMANDS
258 #endif
259         rjmp handle_end_sleep
260
261
262 hrc_set_convertT2:
263         ldi r_temp,2
264         sts gcontrol,r_temp
265         lds r_temp,am2302_temp
266         sts pack2+1,r_temp
267         lds r_temp,am2302_temp+1
268         sts pack2+2,r_temp
269         rjmp handle_end_sleep
270 hrc_set_convertV2:
271         lds r_temp,pack2
272         sbrs r_temp,3
273         rjmp hrc_set_convertVV2
274         ldi r_temp,0xF4
275         sts pack2+3,r_temp
276         ldi r_temp,0x01
277         sts pack2+4,r_temp
278         rjmp hrc_set_convertend2
279 hrc_set_convertVV2:
280         ldi r_temp,3
281         sts gcontrol,r_temp
282         lds r_temp,am2302_hum
283         sts pack2+3,r_temp
284         lds r_temp,am2302_hum+1
285         sts pack2+4,r_temp
286 hrc_set_convertend2:
287         rjmp handle_end_sleep
288
289
290
291 ;---------------------------------------------------
292 ;   READ SCRATCHPAD
293 ;---------------------------------------------------
294
295 h_readscratchpad_adr2:
296         lsl r_rwbyte
297         lsl r_rwbyte
298         lsl r_rwbyte
299 #if  defined(__AVR_ATtiny25__)
300         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
301 #endif
302         sts block,r_rwbyte
303         ldi r_sendflag,1
304         ldi r_mode,OW_READ_SCRATCHPAD2
305         CRCInit2
306 h_readscratchpad2:
307         cpi  r_bytep,8
308         breq h_readscratchpad_crc2
309         cpi  r_bytep,9
310         breq h_readscratchpad_all2
311         lds  r_temp,block
312         add  r_temp,r_bytep
313         configZ pack2,r_temp
314         ld   r_rwbyte,Z
315         rjmp handle_end_inc
316 h_readscratchpad_crc2:
317         lds  r_rwbyte,crc
318         rjmp handle_end_inc
319 h_readscratchpad_all2:
320         rjmp handle_end_sleep
321
322
323
324
325 ;---------------------------------------------------
326 ;   WRITE SCRATCHPAD
327 ;---------------------------------------------------
328 h_writescratchpad_adr2:
329         lsl r_rwbyte
330         lsl r_rwbyte
331         lsl r_rwbyte
332 #if  defined(__AVR_ATtiny25__)
333         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
334 #endif
335         sts block,r_rwbyte
336         ldi r_mode,OW_WRITE_SCRATCHPAD2
337         ldi  r_bcount,1 
338         rjmp handle_end 
339 h_writescratchpad2:
340         cpi  r_bytep,8
341         breq h_writescratchpad_all2
342         lds  r_temp,block
343         add  r_temp,r_bytep
344         configZ pack2,r_temp
345         st   Z,r_rwbyte
346         rjmp handle_end_inc
347 h_writescratchpad_all2:
348         rjmp handle_end_sleep
349
350
351
352
353
354
355
356
357
358 #include "../common/OWPinInterrupt.s"
359 .end