📄 owihighlevelfunctions.lst
字号:
162 * the array, or the search will fail.
163 *
164 * \param lastDeviation The bit position where the algorithm made a
165 * choice the last time it was run. This argument
166 * should be 0 when a search is initiated. Supplying
167 * the return argument of this function when calling
168 * repeatedly will go through the complete slave
169 * search.
170 *
171 * \param pin A bit-mask of the bus to perform a ROM search on.
172 *
173 * \return The last bit position where there was a discrepancy between slave addresses the last time this function was run. Returns OWI_ROM_SEARCH_FAILED if an error was detected (e.g. a device was connected to the bus during the search), or OWI_ROM_SEARCH_FINISHED when there are no more devices to be discovered.
174 *
175 * \note See main.c for an example of how to utilize this function.
176 */
\ In segment CODE, align 2, keep-with-next
177 unsigned char OWI_SearchRom(unsigned char * bitPattern, unsigned char lastDeviation, unsigned char pin)
\ OWI_SearchRom:
178 {
\ 00000000 ........ CALL ?PROLOGUE9_L09
\ 00000004 REQUIRE ?Register_R4_is_cg_reg
\ 00000004 REQUIRE ?Register_R5_is_cg_reg
\ 00000004 REQUIRE ?Register_R6_is_cg_reg
\ 00000004 REQUIRE ?Register_R7_is_cg_reg
\ 00000004 REQUIRE ?Register_R8_is_cg_reg
\ 00000004 0128 MOVW R5 : R4,R17 : R16
\ 00000006 2E72 MOV R7,R18
\ 00000008 2FA3 MOV R26,R19
179 unsigned char currentBit = 1;
\ 0000000A E091 LDI R25,1
180 unsigned char newDeviation = 0;
\ 0000000C E0B0 LDI R27,0
181 unsigned char bitMask = 0x01;
\ 0000000E E081 LDI R24,1
182 unsigned char bitA;
183 unsigned char bitB;
184
185 // Send SEARCH ROM command on the bus.
186 OWI_SendByte(OWI_ROM_SEARCH, pin);
\ 00000010 2F1A MOV R17,R26
\ 00000012 EF00 LDI R16,240
\ 00000014 .... RCALL OWI_SendByte
187
188 // Walk through all 64 bits.
189 while (currentBit <= 64)
\ ??OWI_SearchRom_0:
\ 00000016 3491 CPI R25,65
\ 00000018 F008 BRCS $+2+2
\ 0000001A C04D RJMP ??OWI_SearchRom_1
190 {
191 // Read bit from bus twice.
192 bitA = OWI_ReadBit(pin);
\ 0000001C 2F0A MOV R16,R26
\ 0000001E ........ CALL OWI_ReadBit
\ 00000022 2E60 MOV R6,R16
193 bitB = OWI_ReadBit(pin);
\ 00000024 2F0A MOV R16,R26
\ 00000026 ........ CALL OWI_ReadBit
\ 0000002A 2E80 MOV R8,R16
194
195 if (bitA && bitB)
\ 0000002C 2066 TST R6
\ 0000002E F019 BREQ ??OWI_SearchRom_2
\ 00000030 2088 TST R8
\ 00000032 F009 BREQ $+2+2
\ 00000034 C041 RJMP ??OWI_SearchRom_3
196 {
197 // Both bits 1 (Error).
198 newDeviation = OWI_ROM_SEARCH_FAILED;
199 return;
200 }
201 else if (bitA ^ bitB)
\ ??OWI_SearchRom_2:
\ 00000036 2D08 MOV R16,R8
\ 00000038 2506 EOR R16,R6
\ 0000003A 2300 TST R16
\ 0000003C F071 BREQ ??OWI_SearchRom_4
202 {
203 // Bits A and B are different. All devices have the same bit here.
204 // Set the bit in bitPattern to this value.
205 if (bitA)
\ 0000003E 2066 TST R6
\ 00000040 F029 BREQ ??OWI_SearchRom_5
206 {
207 (*bitPattern) |= bitMask;
\ 00000042 01F2 MOVW R31 : R30,R5 : R4
\ 00000044 8100 LD R16,Z
\ 00000046 2B08 OR R16,R24
\ 00000048 8300 ST Z,R16
\ 0000004A C01E RJMP ??OWI_SearchRom_6
208 }
209 else
210 {
211 (*bitPattern) &= ~bitMask;
\ ??OWI_SearchRom_5:
\ 0000004C 2F08 MOV R16,R24
\ 0000004E 9500 COM R16
\ 00000050 01F2 MOVW R31 : R30,R5 : R4
\ 00000052 8110 LD R17,Z
\ 00000054 2310 AND R17,R16
\ 00000056 8310 ST Z,R17
\ 00000058 C017 RJMP ??OWI_SearchRom_6
212 }
213 }
214 else // Both bits 0
215 {
216 // If this is where a choice was made the last time,
217 // a '1' bit is selected this time.
218 if (currentBit == lastDeviation)
\ ??OWI_SearchRom_4:
\ 0000005A 1597 CP R25,R7
\ 0000005C F429 BRNE ??OWI_SearchRom_7
219 {
220 (*bitPattern) |= bitMask;
\ 0000005E 01F2 MOVW R31 : R30,R5 : R4
\ 00000060 8100 LD R16,Z
\ 00000062 2B08 OR R16,R24
\ 00000064 8300 ST Z,R16
\ 00000066 C010 RJMP ??OWI_SearchRom_6
221 }
222 // For the rest of the id, '0' bits are selected when
223 // discrepancies occur.
224 else if (currentBit > lastDeviation)
\ ??OWI_SearchRom_7:
\ 00000068 1679 CP R7,R25
\ 0000006A F440 BRCC ??OWI_SearchRom_8
225 {
226 (*bitPattern) &= ~bitMask;
\ 0000006C 2F08 MOV R16,R24
\ 0000006E 9500 COM R16
\ 00000070 01F2 MOVW R31 : R30,R5 : R4
\ 00000072 8110 LD R17,Z
\ 00000074 2310 AND R17,R16
\ 00000076 8310 ST Z,R17
227 newDeviation = currentBit;
\ 00000078 2FB9 MOV R27,R25
\ 0000007A C006 RJMP ??OWI_SearchRom_6
228 }
229 // If current bit in bit pattern = 0, then this is
230 // out new deviation.
231 else if ( !(*bitPattern & bitMask))
\ ??OWI_SearchRom_8:
\ 0000007C 01F2 MOVW R31 : R30,R5 : R4
\ 0000007E 8100 LD R16,Z
\ 00000080 2308 AND R16,R24
\ 00000082 2300 TST R16
\ 00000084 F409 BRNE ??OWI_SearchRom_6
232 {
233 newDeviation = currentBit;
\ 00000086 2FB9 MOV R27,R25
234 }
235 // IF the bit is already 1, do nothing.
236 else
237 {
238
239 }
240 }
241
242
243 // Send the selected bit to the bus.
244 if ((*bitPattern) & bitMask)
\ ??OWI_SearchRom_6:
\ 00000088 01F2 MOVW R31 : R30,R5 : R4
\ 0000008A 8100 LD R16,Z
\ 0000008C 2308 AND R16,R24
\ 0000008E 2300 TST R16
\ 00000090 F021 BREQ ??OWI_SearchRom_9
245 {
246 OWI_WriteBit1(pin);
\ 00000092 2F0A MOV R16,R26
\ 00000094 ........ CALL OWI_WriteBit1
\ 00000098 C003 RJMP ??OWI_SearchRom_10
247 }
248 else
249 {
250 OWI_WriteBit0(pin);
\ ??OWI_SearchRom_9:
\ 0000009A 2F0A MOV R16,R26
\ 0000009C ........ CALL OWI_WriteBit0
251 }
252
253 // Increment current bit.
254 currentBit++;
\ ??OWI_SearchRom_10:
\ 000000A0 9593 INC R25
255
256 // Adjust bitMask and bitPattern pointer.
257 bitMask <<= 1;
\ 000000A2 0F88 LSL R24
258 if (!bitMask)
\ 000000A4 2388 TST R24
\ 000000A6 F009 BREQ $+2+2
\ 000000A8 CFB6 RJMP ??OWI_SearchRom_0
259 {
260 bitMask = 0x01;
\ 000000AA E081 LDI R24,1
261 bitPattern++;
\ 000000AC E001 LDI R16,1
\ 000000AE 0E40 ADD R4,R16
\ 000000B0 E000 LDI R16,0
\ 000000B2 1E50 ADC R5,R16
\ 000000B4 CFB0 RJMP ??OWI_SearchRom_0
262 }
263 }
264 return newDeviation;
\ ??OWI_SearchRom_1:
\ 000000B6 2F0B MOV R16,R27
\ ??OWI_SearchRom_3:
\ 000000B8 E0E9 LDI R30,9
\ 000000BA ........ JMP ?EPILOGUE_B9_L09
265 }
\ In segment ABSOLUTE, at 0x3e, root
\ union <unnamed> volatile __io _A_EEAR
\ _A_EEAR:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x40, root
\ union <unnamed> volatile __io _A_UBRRH
\ _A_UBRRH:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x41, root
\ union <unnamed> volatile __io _A_WDTCR
\ _A_WDTCR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x42, root
\ union <unnamed> volatile __io _A_ASSR
\ _A_ASSR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x43, root
\ union <unnamed> volatile __io _A_OCR2
\ _A_OCR2:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x44, root
\ union <unnamed> volatile __io _A_TCNT2
\ _A_TCNT2:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x45, root
\ union <unnamed> volatile __io _A_TCCR2
\ _A_TCCR2:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x46, root
\ union <unnamed> volatile __io _A_ICR1
\ _A_ICR1:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x48, root
\ union <unnamed> volatile __io _A_OCR1B
\ _A_OCR1B:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x4a, root
\ union <unnamed> volatile __io _A_OCR1A
\ _A_OCR1A:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x4c, root
\ union <unnamed> volatile __io _A_TCNT1
\ _A_TCNT1:
\ 00000000 DS 2
\ In segment ABSOLUTE, at 0x4e, root
\ union <unnamed> volatile __io _A_TCCR1B
\ _A_TCCR1B:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x4f, root
\ union <unnamed> volatile __io _A_TCCR1A
\ _A_TCCR1A:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x50, root
\ union <unnamed> volatile __io _A_SFIOR
\ _A_SFIOR:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x51, root
\ union <unnamed> volatile __io _A_OSCCAL
\ _A_OSCCAL:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x52, root
\ union <unnamed> volatile __io _A_TCNT0
\ _A_TCNT0:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x53, root
\ union <unnamed> volatile __io _A_TCCR0
\ _A_TCCR0:
\ 00000000 DS 1
\ In segment ABSOLUTE, at 0x54, root
\ union <unnamed> volatile __io _A_MCUCSR
\ _A_MCUCSR:
\ 00000000 DS 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -