Rename Files of different Devices
[owSlave2.git] / DS2438_DHT22 / OWDS2438.S
1 // Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
2 // All rights reserved. 
3 // 
4 // Redistribution and use in source and binary forms, with or without 
5 // modification, are permitted provided that the following conditions are 
6 // met: 
7 // 
8 //  * Redistributions of source code must retain the above copyright 
9 //    notice, this list of conditions and the following disclaimer. 
10 //  * Redistributions in binary form must reproduce the above copyright 
11 //    notice, this list of conditions and the following disclaimer in the 
12 //    documentation and/or other materials provided with the 
13 //    distribution. 
14 //  * All advertising materials mentioning features or use of this 
15 //    software must display the following acknowledgement: This product 
16 //    includes software developed by tm3d.de and its contributors. 
17 //  * Neither the name of tm3d.de nor the names of its contributors may 
18 //    be used to endorse or promote products derived from this software 
19 //    without specific prior written permission. 
20 // 
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
32
33 #define _CHANGEABLE_ID_
34 //#define _DIS_FLASH_
35 #define _ZERO_POLLING_
36 //#define _DB_
37
38 #include "../common/OWConfig.s"
39 #include "../common/OWCRC8.s"
40
41 #if  defined(__AVR_ATtiny25__)
42 .extern pack,16
43 #else
44 .extern pack,64
45 #endif
46 .extern  am2302_temp,2
47 .extern  am2302_hum,2
48 .comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
49
50
51 .macro CHIP_INIT
52 .endm
53
54 ; Ab hier Geraeteabhaenging
55 #define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0
56 #define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1
57 #define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2
58 #define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3
59
60
61
62 .macro COMMAND_TABLE
63                 rjmp h_readscratchpad_adr
64                 rjmp h_readscratchpad
65                 rjmp h_writescratchpad_adr
66                 rjmp h_writescratchpad
67 .endm
68
69 #include "../common/OWRomFunctions.s"
70 #include "../common/OWTimerInterrupt.s"
71
72
73 ;---------------------------------------------------
74 ;       READ COMMAND and start operation
75 ;---------------------------------------------------
76
77
78 h_readcommand:
79         clr r_bytep
80 #ifndef _DIS_FLASH_
81         FLASH_COMMANDS ; muss zu erst sein....
82 #endif
83         cset 0xBE,OW_READ_SCRATCHPAD_ADR
84         cset 0x4E,OW_WRITE_SCRATCHPAD_ADR
85         cjmp 0x44,hrc_set_convertT
86         cjmp 0xB4,hrc_set_convertV
87         FW_CONFIG_INFO
88 #ifdef _CHANGEABLE_ID_
89         CHANGE_ID_COMMANDS
90 #endif
91         rjmp handle_end_sleep
92
93
94 hrc_set_convertT:
95         ldi r_temp,1
96         sts gcontrol,r_temp
97         lds r_temp,am2302_temp
98         sts pack+1,r_temp
99         lds r_temp,am2302_temp+1
100         sts pack+2,r_temp
101         rjmp handle_end_sleep
102 hrc_set_convertV:
103         ldi r_temp,2
104         sts gcontrol,r_temp
105         lds r_temp,pack
106         sbrs r_temp,3
107         rjmp hrc_set_convertVV
108         ldi r_temp,0xF4
109         sts pack+3,r_temp
110         ldi r_temp,0x01
111         sts pack+4,r_temp
112         rjmp hrc_set_convertend
113 hrc_set_convertVV:
114         lds r_temp,am2302_hum
115         sts pack+3,r_temp
116         lds r_temp,am2302_hum+1
117         sts pack+4,r_temp
118 hrc_set_convertend:
119         rjmp handle_end_sleep
120
121
122
123 ;---------------------------------------------------
124 ;   READ SCRATCHPAD
125 ;---------------------------------------------------
126
127 h_readscratchpad_adr:
128         lsl r_rwbyte
129         lsl r_rwbyte
130         lsl r_rwbyte
131 #if  defined(__AVR_ATtiny25__)
132         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
133 #endif
134         sts block,r_rwbyte
135         ldi r_sendflag,1
136         ldi r_mode,OW_READ_SCRATCHPAD
137         CRCInit2
138 h_readscratchpad:
139         cpi  r_bytep,8
140         breq h_readscratchpad_crc
141         cpi  r_bytep,9
142         breq h_readscratchpad_all
143         lds  r_temp,block
144         add  r_temp,r_bytep
145         configZ pack,r_temp
146         ld   r_rwbyte,Z
147         rjmp handle_end_inc
148 h_readscratchpad_crc:
149         lds  r_rwbyte,crc
150         rjmp handle_end_inc
151 h_readscratchpad_all:
152         rjmp handle_end_sleep
153
154
155
156
157 ;---------------------------------------------------
158 ;   WRITE SCRATCHPAD
159 ;---------------------------------------------------
160 h_writescratchpad_adr:
161         lsl r_rwbyte
162         lsl r_rwbyte
163         lsl r_rwbyte
164 #if  defined(__AVR_ATtiny25__)
165         andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
166 #endif
167         sts block,r_rwbyte
168         ldi r_mode,OW_WRITE_SCRATCHPAD
169         ldi  r_bcount,1 
170         rjmp handle_end 
171 h_writescratchpad:
172         cpi  r_bytep,8
173         breq h_writescratchpad_all
174         lds  r_temp,block
175         add  r_temp,r_bytep
176         configZ pack,r_temp
177         st   Z,r_rwbyte
178         rjmp handle_end_inc
179 h_writescratchpad_all:
180         rjmp handle_end_sleep
181
182
183
184
185
186 #include "../common/OWPinInterrupt.s"
187 .end