*** SET 1-Wire Flasher Address from 0x0EE0 to 0x0EC0 **** for more freedom to impleme...
[owSlave2.git] / DS18B20_BMP280 / OWDS18B20.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 pack,8
42
43 //.extern  am2302_temp,2
44
45
46
47 .macro CHIP_INIT        
48 Init_EEPROM_read:
49         sbic _SFR_IO_ADDR(EECR), EEPE
50         rjmp Init_EEPROM_read
51         ldi r_temp,0
52         out _SFR_IO_ADDR(EEARH), r_temp
53         ldi r_temp,2
54         out _SFR_IO_ADDR(EEARL), r_temp
55         sbi _SFR_IO_ADDR(EECR), EERE
56         in r_temp,_SFR_IO_ADDR(EEDR)
57         sbrs r_temp,7
58         rcall hrc_recall_eeprom_func
59 .endm
60
61 .macro COMMAND_TABLE
62                 rjmp h_readscratchpad
63                 rjmp h_writescratchpad
64 .endm
65
66 #include "../common/OWRomFunctions.s"
67 #include "../common/OWTimerInterrupt.s"
68
69
70
71 ; Ab hier Geraeteabhaenging
72 #define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+0
73 #define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+1
74
75
76 ;---------------------------------------------------
77 ;       READ COMMAND and start operation
78 ;---------------------------------------------------
79
80
81 h_readcommand:
82         clr r_bytep
83 #ifndef _DIS_FLASH_
84         FLASH_COMMANDS ; muss zu erst sein....
85 #endif
86         cjmp 0xBE,hrc_set_readscratchpad
87         cjmp 0x4E,hrc_set_writescratchpad
88         cjmp 0x44,hrc_set_convertT
89         cjmp 0x48,hrc_copy_scratchpad
90         cjmp 0xB8,hrc_recall_eeprom
91         FW_CONFIG_INFO
92 #ifdef _CHANGEABLE_ID_
93         CHANGE_ID_COMMANDS
94 #endif
95         //ldi r_mode,OW_SLEEP
96         rjmp handle_end_sleep
97
98 hrc_set_readscratchpad:
99         ldi r_mode,OW_READ_SCRATCHPAD
100         ldi r_sendflag,1
101         CRCInit2
102         rjmp h_readscratchpad
103
104 hrc_set_writescratchpad:
105         ldi r_mode,OW_WRITE_SCRATCHPAD
106         ldi r_bytep,2 ;start to write in 2
107         rjmp handle_end
108
109 hrc_recall_eeprom:
110         rcall hrc_recall_eeprom_func
111         rjmp handle_end
112
113
114
115 hrc_set_convertT:
116         ldi r_temp,1
117         sts gcontrol,r_temp
118         ;lds temp,am2302_temp
119         //sts pack+1,temp
120         ;lds temp,am2302_temp+1
121         //sts pack+2,temp
122 ;       ldi r_rwbyte,0
123 ;       lds r_temp,pack
124 ;       swap r_temp
125 ;       andi r_temp,0x0F
126 ;       lds r_temp2,pack+1
127 ;       swap r_temp2
128 ;       andi r_temp2,0xF0
129 ;       or r_temp,r_temp2
130 ;       lds r_temp2,pack+2
131 ;       cp r_temp,r_temp2  ;higher than or equal to TH
132 ;       brge hrc_set_convertT_set_arlarm
133 ;       lds r_temp2,pack+3 
134 ;       cp r_temp,r_temp2 ;lower than or equal to TL
135 ;       brlt hrc_set_convertT_set_arlarm
136 ;       breq hrc_set_convertT_set_arlarm
137 ;       rjmp hrc_set_convertT_end
138 ;hrc_set_convertT_set_arlarm:
139 ;       ldi r_rwbyte,1
140 ;hrc_set_convertT_end:
141 ;       sts alarmflag,r_rwbyte
142         rjmp handle_end_sleep
143
144
145 hrc_copy_scratchpad:
146         ldi r_bytep,2
147         configZ pack,r_bytep
148         clr r_bytep
149 hrc_copy_scratchpad_EEPROM_write:
150         sbic _SFR_IO_ADDR(EECR), EEPE   
151         rjmp hrc_copy_scratchpad_EEPROM_write
152         ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
153         out _SFR_IO_ADDR(EECR), r_temp
154         ldi r_temp,0
155         out _SFR_IO_ADDR(EEARH),r_temp
156         out _SFR_IO_ADDR(EEARL), r_bytep
157         ld  r_rwbyte,Z+
158         out _SFR_IO_ADDR(EEDR), r_rwbyte
159         sbi _SFR_IO_ADDR(EECR), EEMPE
160         sbi _SFR_IO_ADDR(EECR), EEPE
161         inc r_bytep
162         cpi r_bytep,3
163         brne hrc_copy_scratchpad_EEPROM_write
164         rjmp handle_end
165
166
167 hrc_recall_eeprom_func:
168         ldi r_bytep,2
169         configZ pack,r_bytep
170         clr r_bytep
171         clr r_temp
172 hrc_recall_eeprom_EEPROM_read:
173         sbic _SFR_IO_ADDR(EECR), EEPE
174         rjmp hrc_recall_eeprom_EEPROM_read
175         out _SFR_IO_ADDR(EEARH), r_temp
176         out _SFR_IO_ADDR(EEARL), r_bytep
177         sbi _SFR_IO_ADDR(EECR), EERE
178         in r_rwbyte,_SFR_IO_ADDR(EEDR)
179         st Z+,r_rwbyte
180         inc r_bytep
181         cpi r_bytep,3
182         brne hrc_recall_eeprom_EEPROM_read
183         ret
184
185
186
187
188
189
190 ;---------------------------------------------------
191 ;   READ SCRATCHPAD
192 ;---------------------------------------------------
193
194 h_readscratchpad:
195         cpi  r_bytep,8
196         breq h_readscratchpad_crc
197         cpi  r_bytep,9
198         breq h_readscratchpad_all
199         configZ pack,r_bytep
200         ld   r_rwbyte,Z
201         rjmp h_readscratchpad_endc
202 h_readscratchpad_crc:
203         lds  r_rwbyte,crc
204 h_readscratchpad_endc:
205         inc  r_bytep
206         ldi  r_bcount,1 
207         rjmp handle_end
208 h_readscratchpad_all:
209         rjmp handle_end_sleep
210
211
212
213
214
215 ;---------------------------------------------------
216 ;   WRITE SCRATCHPAD
217 ;---------------------------------------------------
218
219 h_writescratchpad:
220         configZ pack,r_bytep
221         inc  r_bytep
222         cpi  r_bytep,5
223         breq h_writescratchpad_all
224         st   Z,r_rwbyte
225         rjmp handle_end
226 h_writescratchpad_all:
227         ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
228         st   Z,r_rwbyte
229         rjmp handle_end_sleep
230
231
232
233
234
235
236 #include "../common/OWPinInterrupt.s"
237 .end