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