VOC, Programmer with 4MHz (posible)
[owSlave2.git] / common / 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                 rjmp h_convert_run
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 #define OW_CONVERT_RUN  OW_FIRST_COMMAND+2
75
76
77 ;---------------------------------------------------
78 ;       READ COMMAND and start operation
79 ;---------------------------------------------------
80
81
82 h_readcommand:
83         clr r_bytep
84 #ifndef _DIS_FLASH_
85         FLASH_COMMANDS ; muss zu erst sein....
86 #endif
87         cjmp 0xBE,hrc_set_readscratchpad
88         cjmp 0x4E,hrc_set_writescratchpad
89         cjmp 0x44,hrc_set_convertT
90         cjmp 0x48,hrc_copy_scratchpad
91         cjmp 0xB8,hrc_recall_eeprom
92         FW_CONFIG_INFO
93 #ifdef _CHANGEABLE_ID_
94         CHANGE_ID_COMMANDS
95 #endif
96         //ldi r_mode,OW_SLEEP
97         rjmp handle_end_sleep
98
99 hrc_set_readscratchpad:
100         ldi r_mode,OW_READ_SCRATCHPAD
101         ldi r_sendflag,1
102         CRCInit2
103         rjmp h_readscratchpad
104
105 hrc_set_writescratchpad:
106         ldi r_mode,OW_WRITE_SCRATCHPAD
107         ldi r_bytep,2 ;start to write in 2
108         rjmp handle_end
109
110 hrc_recall_eeprom:
111         rcall hrc_recall_eeprom_func
112         rjmp handle_end
113
114
115
116 hrc_set_convertT:
117         ldi r_temp,1
118         sts gcontrol,r_temp
119         ldi r_mode,OW_CONVERT_RUN
120         ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
121 h_convert_run:
122         ldi r_bcount,0
123         ldi r_rwbyte,0
124         rjmp handle_end_no_bcount       
125
126 hrc_copy_scratchpad:
127         ldi r_bytep,2
128         configZ pack,r_bytep
129         clr r_bytep
130 hrc_copy_scratchpad_EEPROM_write:
131         sbic _SFR_IO_ADDR(EECR), EEPE   
132         rjmp hrc_copy_scratchpad_EEPROM_write
133         ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
134         out _SFR_IO_ADDR(EECR), r_temp
135         ldi r_temp,0
136         out _SFR_IO_ADDR(EEARH),r_temp
137         out _SFR_IO_ADDR(EEARL), r_bytep
138         ld  r_rwbyte,Z+
139         out _SFR_IO_ADDR(EEDR), r_rwbyte
140         sbi _SFR_IO_ADDR(EECR), EEMPE
141         sbi _SFR_IO_ADDR(EECR), EEPE
142         inc r_bytep
143         cpi r_bytep,3
144         brne hrc_copy_scratchpad_EEPROM_write
145         rjmp handle_end
146
147
148 hrc_recall_eeprom_func:
149         ldi r_bytep,2
150         configZ pack,r_bytep
151         clr r_bytep
152         clr r_temp
153 hrc_recall_eeprom_EEPROM_read:
154         sbic _SFR_IO_ADDR(EECR), EEPE
155         rjmp hrc_recall_eeprom_EEPROM_read
156         out _SFR_IO_ADDR(EEARH), r_temp
157         out _SFR_IO_ADDR(EEARL), r_bytep
158         sbi _SFR_IO_ADDR(EECR), EERE
159         in r_rwbyte,_SFR_IO_ADDR(EEDR)
160         st Z+,r_rwbyte
161         inc r_bytep
162         cpi r_bytep,3
163         brne hrc_recall_eeprom_EEPROM_read
164         ret
165
166
167
168
169
170
171 ;---------------------------------------------------
172 ;   READ SCRATCHPAD
173 ;---------------------------------------------------
174
175 h_readscratchpad:
176         cpi  r_bytep,8
177         breq h_readscratchpad_crc
178         cpi  r_bytep,9
179         breq h_readscratchpad_all
180         configZ pack,r_bytep
181         ld   r_rwbyte,Z
182         rjmp h_readscratchpad_endc
183 h_readscratchpad_crc:
184         lds  r_rwbyte,crc
185 h_readscratchpad_endc:
186         inc  r_bytep
187         ldi  r_bcount,1 
188         rjmp handle_end
189 h_readscratchpad_all:
190         rjmp handle_end_sleep
191
192
193
194
195
196 ;---------------------------------------------------
197 ;   WRITE SCRATCHPAD
198 ;---------------------------------------------------
199
200 h_writescratchpad:
201         configZ pack,r_bytep
202         inc  r_bytep
203         cpi  r_bytep,5
204         breq h_writescratchpad_all
205         st   Z,r_rwbyte
206         rjmp handle_end
207 h_writescratchpad_all:
208         ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
209         st   Z,r_rwbyte
210         rjmp handle_end_sleep
211
212
213
214
215
216 #include "../common/OWPinInterrupt.s"
217 .end