Change Time Values so it works for all Adapters
[owSlave2.git] / DS18B20_DS2438 / 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        
56 Init_EEPROM_read:
57         sbic _SFR_IO_ADDR(EECR), EEPE
58         rjmp Init_EEPROM_read
59         ldi r_temp,0
60         out _SFR_IO_ADDR(EEARH), r_temp
61         ldi r_temp,2
62         out _SFR_IO_ADDR(EEARL), r_temp
63         sbi _SFR_IO_ADDR(EECR), EERE
64         in r_temp,_SFR_IO_ADDR(EEDR)
65         sbrs r_temp,7
66         rcall hrc_recall_eeprom_func1
67 .endm
68
69 .macro COMMAND_TABLE
70                 rjmp h_readscratchpad1
71                 rjmp h_writescratchpad1
72                 rjmp h_readscratchpad_adr2
73                 rjmp h_readscratchpad2
74                 rjmp h_writescratchpad_adr2
75                 rjmp h_writescratchpad2
76 .endm
77
78 #include "../common/OWRomFunctionsDual.s"
79 #include "../common/OWTimerInterrupt.s"
80
81
82
83 ; Ab hier Geraeteabhaenging
84 #define OW_READ_SCRATCHPAD1 OW_FIRST_COMMAND+0
85 #define OW_WRITE_SCRATCHPAD1 OW_FIRST_COMMAND+1
86 #define OW_READ_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+2
87 #define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+3
88 #define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+4
89 #define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+5
90
91
92 ;---------------------------------------------------
93 ;       READ COMMAND and start operation
94 ;---------------------------------------------------
95
96
97 h_readcommand1:
98         clr r_bytep
99 #ifndef _DIS_FLASH_
100         FLASH_COMMANDS ; muss zu erst sein....
101 #endif
102         cjmp 0xBE,hrc_set_readscratchpad1
103         cjmp 0x4E,hrc_set_writescratchpad1
104         cjmp 0x44,hrc_set_convertT1
105         cjmp 0x48,hrc_copy_scratchpad1
106         cjmp 0xB8,hrc_recall_eeprom1
107 #ifdef _CHANGEABLE_ID_
108         CHANGE_ID_COMMANDS
109 #endif
110         ldi r_mode,OW_SLEEP
111         rjmp handle_end
112
113 hrc_set_readscratchpad1:
114         ldi r_mode,OW_READ_SCRATCHPAD1
115         ldi r_sendflag,1
116         CRCInit2
117         rjmp h_readscratchpad1
118
119 hrc_set_writescratchpad1:
120         ldi r_mode,OW_WRITE_SCRATCHPAD1
121         ldi r_bytep,2 ;start to write in 2
122         rjmp handle_end
123
124 hrc_recall_eeprom1:
125         rcall hrc_recall_eeprom_func1
126         rjmp handle_end
127
128
129
130 hrc_set_convertT1:
131         ldi r_temp,1
132         sts gcontrol,r_temp
133
134         rjmp handle_end_sleep
135
136
137 hrc_copy_scratchpad1:
138         ldi r_bytep,2
139         configZ pack1,r_bytep
140         clr r_bytep
141 hrc_copy_scratchpad_EEPROM_write1:
142         sbic _SFR_IO_ADDR(EECR), EEPE   
143         rjmp hrc_copy_scratchpad_EEPROM_write1
144         ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
145         out _SFR_IO_ADDR(EECR), r_temp
146         ldi r_temp,0
147         out _SFR_IO_ADDR(EEARH),r_temp
148         out _SFR_IO_ADDR(EEARL), r_bytep
149         ld  r_rwbyte,Z+
150         out _SFR_IO_ADDR(EEDR), r_rwbyte
151         sbi _SFR_IO_ADDR(EECR), EEMPE
152         sbi _SFR_IO_ADDR(EECR), EEPE
153         inc r_bytep
154         cpi r_bytep,3
155         brne hrc_copy_scratchpad_EEPROM_write1
156         rjmp handle_end
157
158
159 hrc_recall_eeprom_func1:
160         ldi r_bytep,2
161         configZ pack1,r_bytep
162         clr r_bytep
163         clr r_temp
164 hrc_recall_eeprom_EEPROM_read1:
165         sbic _SFR_IO_ADDR(EECR), EEPE
166         rjmp hrc_recall_eeprom_EEPROM_read1
167         out _SFR_IO_ADDR(EEARH), r_temp
168         out _SFR_IO_ADDR(EEARL), r_bytep
169         sbi _SFR_IO_ADDR(EECR), EERE
170         in r_rwbyte,_SFR_IO_ADDR(EEDR)
171         st Z+,r_rwbyte
172         inc r_bytep
173         cpi r_bytep,3
174         brne hrc_recall_eeprom_EEPROM_read1
175         ret
176
177
178
179
180
181
182 ;---------------------------------------------------
183 ;   READ SCRATCHPAD
184 ;---------------------------------------------------
185
186 h_readscratchpad1:
187         cpi  r_bytep,8
188         breq h_readscratchpad_crc1
189         cpi  r_bytep,9
190         breq h_readscratchpad_all1
191         configZ pack1,r_bytep
192         ld   r_rwbyte,Z
193         rjmp h_readscratchpad_endc1
194 h_readscratchpad_crc1:
195         lds  r_rwbyte,crc
196 h_readscratchpad_endc1:
197         inc  r_bytep
198         ldi  r_bcount,1 
199         rjmp handle_end
200 h_readscratchpad_all1:
201         rjmp handle_end_sleep
202
203
204
205
206
207 ;---------------------------------------------------
208 ;   WRITE SCRATCHPAD
209 ;---------------------------------------------------
210
211 h_writescratchpad1:
212         configZ pack1,r_bytep
213         inc  r_bytep
214         cpi  r_bytep,5
215         breq h_writescratchpad_all1
216         st   Z,r_rwbyte
217         rjmp handle_end
218 h_writescratchpad_all1:
219         ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
220         st   Z,r_rwbyte
221         rjmp handle_end_sleep
222
223 ;*****************************************************************************************************************************************************************************************
224 ;*****************************************************************************************************************************************************************************************
225 ;*****************************************************************************************************************************************************************************************
226 ;*****************************************************************************************************************************************************************************************
227 ;*****************************************************************************************************************************************************************************************
228
229
230
231
232
233 h_readcommand2:
234         clr r_bytep
235 #ifndef _DIS_FLASH_
236         FLASH_COMMANDS ; muss zu erst sein....
237 #endif
238         cset 0xBE,OW_READ_SCRATCHPAD_ADR2
239         cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2
240         cjmp 0x44,hrc_set_convertT2
241         cjmp 0xB4,hrc_set_convertV2
242 #ifdef _CHANGEABLE_ID_
243         CHANGE_ID_COMMANDS
244 #endif
245         rjmp handle_end_sleep
246
247
248 hrc_set_convertT2:
249         ldi r_temp,2
250         sts gcontrol,r_temp
251         lds r_temp,am2302_temp
252         sts pack2+1,r_temp
253         lds r_temp,am2302_temp+1
254         sts pack2+2,r_temp
255         rjmp handle_end_sleep
256 hrc_set_convertV2:
257         lds r_temp,pack2
258         sbrs r_temp,3
259         rjmp hrc_set_convertVV2
260         ldi r_temp,0xF4
261         sts pack2+3,r_temp
262         ldi r_temp,0x01
263         sts pack2+4,r_temp
264         rjmp hrc_set_convertend2
265 hrc_set_convertVV2:
266         ldi r_temp,3
267         sts gcontrol,r_temp
268         lds r_temp,am2302_hum
269         sts pack2+3,r_temp
270         lds r_temp,am2302_hum+1
271         sts pack2+4,r_temp
272 hrc_set_convertend2:
273         rjmp handle_end_sleep
274
275
276
277 ;---------------------------------------------------
278 ;   READ SCRATCHPAD
279 ;---------------------------------------------------
280
281 h_readscratchpad_adr2:
282         lsl r_rwbyte
283         lsl r_rwbyte
284         lsl r_rwbyte
285 #if  defined(__AVR_ATtiny25__)
286         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
287 #endif
288         sts block,r_rwbyte
289         ldi r_sendflag,1
290         ldi r_mode,OW_READ_SCRATCHPAD2
291         CRCInit2
292 h_readscratchpad2:
293         cpi  r_bytep,8
294         breq h_readscratchpad_crc2
295         cpi  r_bytep,9
296         breq h_readscratchpad_all2
297         lds  r_temp,block
298         add  r_temp,r_bytep
299         configZ pack2,r_temp
300         ld   r_rwbyte,Z
301         rjmp handle_end_inc
302 h_readscratchpad_crc2:
303         lds  r_rwbyte,crc
304         rjmp handle_end_inc
305 h_readscratchpad_all2:
306         rjmp handle_end_sleep
307
308
309
310
311 ;---------------------------------------------------
312 ;   WRITE SCRATCHPAD
313 ;---------------------------------------------------
314 h_writescratchpad_adr2:
315         lsl r_rwbyte
316         lsl r_rwbyte
317         lsl r_rwbyte
318 #if  defined(__AVR_ATtiny25__)
319         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
320 #endif
321         sts block,r_rwbyte
322         ldi r_mode,OW_WRITE_SCRATCHPAD2
323         ldi  r_bcount,1 
324         rjmp handle_end 
325 h_writescratchpad2:
326         cpi  r_bytep,8
327         breq h_writescratchpad_all2
328         lds  r_temp,block
329         add  r_temp,r_bytep
330         configZ pack2,r_temp
331         st   Z,r_rwbyte
332         rjmp handle_end_inc
333 h_writescratchpad_all2:
334         rjmp handle_end_sleep
335
336
337
338
339
340
341
342
343
344 #include "../common/OWPinInterrupt.s"
345 .end