📄 owihighlevelfunctions.s90
字号:
// 89 {
// 90 // Set msb
// 91 data |= 0x80;
ORI R25,0x80
// 92 }
// 93 }
??OWI_ReceiveByte_2:
INC R24
RJMP ??OWI_ReceiveByte_0
// 94 return data;
??OWI_ReceiveByte_1:
MOV R16,R25
LDI R30,3
JMP ?EPILOGUE_B3_L09
CFI EndBlock cfiBlock1
// 95 }
// 96
// 97
// 98 /*! \brief Sends the SKIP ROM command to the 1-Wire bus(es).
// 99 *
// 100 * \param pins A bitmask of the buses to send the SKIP ROM command to.
// 101 */
RSEG CODE:CODE:NOROOT(1)
// 102 void OWI_SkipRom(unsigned char pins)
OWI_SkipRom:
CFI Block cfiBlock2 Using cfiCommon0
CFI Function OWI_SkipRom
// 103 {
FUNCALL OWI_SkipRom, OWI_SendByte
LOCFRAME CSTACK, 1, STACK
LOCFRAME RSTACK, 2, STACK
ST -Y,R24
CFI R24 Frame(CFA_Y, -1)
CFI CFA_Y Y+1
MOV R24,R16
// 104 // Send the SKIP ROM command on the bus.
// 105 OWI_SendByte(OWI_ROM_SKIP, pins);
MOV R17,R24
LDI R16,204
RCALL OWI_SendByte
// 106 }
LD R24,Y+
CFI R24 SameValue
CFI CFA_Y Y+0
RET
CFI EndBlock cfiBlock2
// 107
// 108
// 109 /*! \brief Sends the READ ROM command and reads back the ROM id.
// 110 *
// 111 * \param romValue A pointer where the id will be placed.
// 112 *
// 113 * \param pin A bitmask of the bus to read from.
// 114 */
RSEG CODE:CODE:NOROOT(1)
// 115 void OWI_ReadRom(unsigned char * romValue, unsigned char pin)
OWI_ReadRom:
CFI Block cfiBlock3 Using cfiCommon0
CFI Function OWI_ReadRom
// 116 {
FUNCALL OWI_ReadRom, OWI_SendByte
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_ReadRom, OWI_ReceiveByte
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
CALL ?PROLOGUE4_L09
CFI R27 Frame(CFA_Y, -1)
CFI R26 Frame(CFA_Y, -2)
CFI R25 Frame(CFA_Y, -3)
CFI R24 Frame(CFA_Y, -4)
CFI CFA_Y Y+4
MOVW R27 : R26,R17 : R16
MOV R25,R18
// 117 unsigned char bytesLeft = 8;
LDI R24,8
// 118
// 119 // Send the READ ROM command on the bus.
// 120 OWI_SendByte(OWI_ROM_READ, pin);
MOV R17,R25
LDI R16,51
RCALL OWI_SendByte
// 121
// 122 // Do 8 times.
// 123 while (bytesLeft > 0)
??OWI_ReadRom_0:
CPI R24,1
BRCS ??OWI_ReadRom_1
// 124 {
// 125 // Place the received data in memory.
// 126 *romValue++ = OWI_ReceiveByte(pin);
MOV R16,R25
RCALL OWI_ReceiveByte
MOVW R31 : R30,R27 : R26
ST Z,R16
ADIW R27 : R26,1
// 127 bytesLeft--;
DEC R24
RJMP ??OWI_ReadRom_0
// 128 }
// 129 }
??OWI_ReadRom_1:
LDI R30,4
JMP ?EPILOGUE_B4_L09
CFI EndBlock cfiBlock3
// 130
// 131
// 132 /*! \brief Sends the MATCH ROM command and the ROM id to match against.
// 133 *
// 134 * \param romValue A pointer to the ID to match against.
// 135 *
// 136 * \param pins A bitmask of the buses to perform the MATCH ROM command on.
// 137 */
RSEG CODE:CODE:NOROOT(1)
// 138 void OWI_MatchRom(unsigned char * romValue, unsigned char pins)
OWI_MatchRom:
CFI Block cfiBlock4 Using cfiCommon0
CFI Function OWI_MatchRom
// 139 {
FUNCALL OWI_MatchRom, OWI_SendByte
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_MatchRom, OWI_SendByte
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
CALL ?PROLOGUE4_L09
CFI R27 Frame(CFA_Y, -1)
CFI R26 Frame(CFA_Y, -2)
CFI R25 Frame(CFA_Y, -3)
CFI R24 Frame(CFA_Y, -4)
CFI CFA_Y Y+4
MOVW R27 : R26,R17 : R16
MOV R25,R18
// 140 unsigned char bytesLeft = 8;
LDI R24,8
// 141
// 142 // Send the MATCH ROM command.
// 143 OWI_SendByte(OWI_ROM_MATCH, pins);
MOV R17,R25
LDI R16,85
RCALL OWI_SendByte
// 144
// 145 // Do once for each byte.
// 146 while (bytesLeft > 0)
??OWI_MatchRom_0:
CPI R24,1
BRCS ??OWI_MatchRom_1
// 147 {
// 148 // Transmit 1 byte of the ID to match.
// 149 OWI_SendByte(*romValue++, pins);
MOV R17,R25
MOVW R31 : R30,R27 : R26
LD R16,Z
RCALL OWI_SendByte
ADIW R27 : R26,1
// 150 bytesLeft--;
DEC R24
RJMP ??OWI_MatchRom_0
// 151 }
// 152 }
??OWI_MatchRom_1:
LDI R30,4
JMP ?EPILOGUE_B4_L09
CFI EndBlock cfiBlock4
// 153
// 154
// 155 /*! \brief Sends the SEARCH ROM command and returns 1 id found on the
// 156 * 1-Wire(R) bus.
// 157 *
// 158 * \param bitPattern A pointer to an 8 byte char array where the
// 159 * discovered identifier will be placed. When
// 160 * searching for several slaves, a copy of the
// 161 * last found identifier should be supplied in
// 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 */
RSEG CODE:CODE:NOROOT(1)
// 177 unsigned char OWI_SearchRom(unsigned char * bitPattern, unsigned char lastDeviation, unsigned char pin)
OWI_SearchRom:
CFI Block cfiBlock5 Using cfiCommon0
CFI Function OWI_SearchRom
// 178 {
FUNCALL OWI_SearchRom, OWI_SendByte
LOCFRAME CSTACK, 9, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_SearchRom, OWI_ReadBit
LOCFRAME CSTACK, 9, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_SearchRom, OWI_ReadBit
LOCFRAME CSTACK, 9, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_SearchRom, OWI_WriteBit1
LOCFRAME CSTACK, 9, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL OWI_SearchRom, OWI_WriteBit0
LOCFRAME CSTACK, 9, STACK
LOCFRAME RSTACK, 2, STACK
CALL ?PROLOGUE9_L09
CFI R8 Frame(CFA_Y, -1)
CFI R7 Frame(CFA_Y, -2)
CFI R6 Frame(CFA_Y, -3)
CFI R5 Frame(CFA_Y, -4)
CFI R4 Frame(CFA_Y, -5)
CFI R27 Frame(CFA_Y, -6)
CFI R26 Frame(CFA_Y, -7)
CFI R25 Frame(CFA_Y, -8)
CFI R24 Frame(CFA_Y, -9)
CFI CFA_Y Y+9
REQUIRE ?Register_R4_is_cg_reg
REQUIRE ?Register_R5_is_cg_reg
REQUIRE ?Register_R6_is_cg_reg
REQUIRE ?Register_R7_is_cg_reg
REQUIRE ?Register_R8_is_cg_reg
MOVW R5 : R4,R17 : R16
MOV R7,R18
MOV R26,R19
// 179 unsigned char currentBit = 1;
LDI R25,1
// 180 unsigned char newDeviation = 0;
LDI R27,0
// 181 unsigned char bitMask = 0x01;
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);
MOV R17,R26
LDI R16,240
RCALL OWI_SendByte
// 187
// 188 // Walk through all 64 bits.
// 189 while (currentBit <= 64)
??OWI_SearchRom_0:
CPI R25,65
BRCS $+2+2
RJMP ??OWI_SearchRom_1
// 190 {
// 191 // Read bit from bus twice.
// 192 bitA = OWI_ReadBit(pin);
MOV R16,R26
CALL OWI_ReadBit
MOV R6,R16
// 193 bitB = OWI_ReadBit(pin);
MOV R16,R26
CALL OWI_ReadBit
MOV R8,R16
// 194
// 195 if (bitA && bitB)
TST R6
BREQ ??OWI_SearchRom_2
TST R8
BREQ $+2+2
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:
MOV R16,R8
EOR R16,R6
TST R16
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)
TST R6
BREQ ??OWI_SearchRom_5
// 206 {
// 207 (*bitPattern) |= bitMask;
MOVW R31 : R30,R5 : R4
LD R16,Z
OR R16,R24
ST Z,R16
RJMP ??OWI_SearchRom_6
// 208 }
// 209 else
// 210 {
// 211 (*bitPattern) &= ~bitMask;
??OWI_SearchRom_5:
MOV R16,R24
COM R16
MOVW R31 : R30,R5 : R4
LD R17,Z
AND R17,R16
ST Z,R17
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:
CP R25,R7
BRNE ??OWI_SearchRom_7
// 219 {
// 220 (*bitPattern) |= bitMask;
MOVW R31 : R30,R5 : R4
LD R16,Z
OR R16,R24
ST Z,R16
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:
CP R7,R25
BRCC ??OWI_SearchRom_8
// 225 {
// 226 (*bitPattern) &= ~bitMask;
MOV R16,R24
COM R16
MOVW R31 : R30,R5 : R4
LD R17,Z
AND R17,R16
ST Z,R17
// 227 newDeviation = currentBit;
MOV R27,R25
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:
MOVW R31 : R30,R5 : R4
LD R16,Z
AND R16,R24
TST R16
BRNE ??OWI_SearchRom_6
// 232 {
// 233 newDeviation = currentBit;
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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -