📄 main.s90
字号:
RSEG CODE:CODE:NOROOT(1)
// 148 unsigned char SearchBuses(OWI_device * devices, unsigned char len, unsigned char buses)
SearchBuses:
CFI Block cfiBlock1 Using cfiCommon0
CFI Function SearchBuses
// 149 {
FUNCALL SearchBuses, OWI_DetectPresence
LOCFRAME CSTACK, 15, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL SearchBuses, memcpy
LOCFRAME CSTACK, 15, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL SearchBuses, OWI_DetectPresence
LOCFRAME CSTACK, 15, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL SearchBuses, OWI_SearchRom
LOCFRAME CSTACK, 15, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL SearchBuses, OWI_CheckRomCRC
LOCFRAME CSTACK, 15, STACK
LOCFRAME RSTACK, 2, STACK
CALL ?PROLOGUE15_L09
CFI R14 Frame(CFA_Y, -1)
CFI R13 Frame(CFA_Y, -2)
CFI R12 Frame(CFA_Y, -3)
CFI R11 Frame(CFA_Y, -4)
CFI R10 Frame(CFA_Y, -5)
CFI R9 Frame(CFA_Y, -6)
CFI R8 Frame(CFA_Y, -7)
CFI R7 Frame(CFA_Y, -8)
CFI R6 Frame(CFA_Y, -9)
CFI R5 Frame(CFA_Y, -10)
CFI R4 Frame(CFA_Y, -11)
CFI R27 Frame(CFA_Y, -12)
CFI R26 Frame(CFA_Y, -13)
CFI R25 Frame(CFA_Y, -14)
CFI R24 Frame(CFA_Y, -15)
CFI CFA_Y Y+15
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
REQUIRE ?Register_R9_is_cg_reg
REQUIRE ?Register_R10_is_cg_reg
REQUIRE ?Register_R11_is_cg_reg
REQUIRE ?Register_R12_is_cg_reg
REQUIRE ?Register_R13_is_cg_reg
REQUIRE ?Register_R14_is_cg_reg
MOVW R25 : R24,R17 : R16
MOV R13,R18
// 150 unsigned char i, j;
// 151 unsigned char presence;
// 152 unsigned char * newID;
// 153 unsigned char * currentID;
// 154 unsigned char currentBus;
// 155 unsigned char lastDeviation;
// 156 unsigned char numDevices;
// 157
// 158 // Initialize all addresses as zero, on bus 0 (does not exist).
// 159 // Do a search on the bus to discover all addresses.
// 160 for (i = 0; i < len; i++)
LDI R27,0
??SearchBuses_0:
CP R27,R13
BRCC ??SearchBuses_1
// 161 {
// 162 devices[i].bus = 0x00;
LDI R16,0
MOV R9,R16
MOV R20,R27
LDI R21,0
LDI R16,9
LDI R17,0
CALL ?S_EC_MUL_L02
MOVW R31 : R30,R25 : R24
ADD R30,R16
ADC R31,R17
ST Z,R9
// 163 for (j = 0; j < 8; j++)
CLR R6
??SearchBuses_2:
LDI R16,8
CP R6,R16
BRCC ??SearchBuses_3
// 164 {
// 165 devices[i].id[j] = 0x00;
LDI R16,0
MOV R9,R16
MOV R20,R27
LDI R21,0
LDI R16,9
LDI R17,0
CALL ?S_EC_MUL_L02
MOVW R31 : R30,R25 : R24
ADD R30,R16
ADC R31,R17
MOV R16,R6
LDI R17,0
ADD R30,R16
ADC R31,R17
STD Z+1,R9
// 166 }
INC R6
RJMP ??SearchBuses_2
// 167 }
??SearchBuses_3:
INC R27
RJMP ??SearchBuses_0
// 168
// 169 // Find the buses with slave devices.
// 170 presence = OWI_DetectPresence(BUSES);
??SearchBuses_1:
LDI R16,3
CALL OWI_DetectPresence
MOV R12,R16
// 171
// 172 numDevices = 0;
CLR R7
// 173 newID = devices[0].id;
MOVW R17 : R16,R25 : R24
SUBI R16,255
SBCI R17,255
MOVW R5 : R4,R17 : R16
// 174
// 175 // Go through all buses with slave devices.
// 176 for (currentBus = 0x01; currentBus; currentBus <<= 1)
LDI R26,1
??SearchBuses_4:
TST R26
BREQ ??SearchBuses_5
// 177 {
// 178 lastDeviation = 0;
CLR R8
// 179 currentID = newID;
MOVW R11 : R10,R5 : R4
// 180 if (currentBus & presence) // Devices available on this bus.
MOV R16,R12
AND R16,R26
TST R16
BREQ ??SearchBuses_6
// 181 {
// 182 // Do slave search on each bus, and place identifiers and corresponding
// 183 // bus "addresses" in the array.
// 184 do
// 185 {
// 186 memcpy(newID, currentID, 8);
??SearchBuses_7:
LDI R20,8
LDI R21,0
MOVW R19 : R18,R11 : R10
MOVW R17 : R16,R5 : R4
CALL memcpy
// 187 OWI_DetectPresence(currentBus);
MOV R16,R26
CALL OWI_DetectPresence
// 188 lastDeviation = OWI_SearchRom(newID, lastDeviation, currentBus);
MOV R19,R26
MOV R18,R8
MOVW R17 : R16,R5 : R4
CALL OWI_SearchRom
MOV R8,R16
// 189 currentID = newID;
MOVW R11 : R10,R5 : R4
// 190 devices[numDevices].bus = currentBus;
MOV R20,R7
LDI R21,0
LDI R16,9
LDI R17,0
CALL ?S_EC_MUL_L02
MOVW R31 : R30,R25 : R24
ADD R30,R16
ADC R31,R17
ST Z,R26
// 191 numDevices++;
INC R7
// 192 newID=devices[numDevices].id;
MOV R20,R7
LDI R21,0
LDI R16,9
LDI R17,0
CALL ?S_EC_MUL_L02
MOVW R19 : R18,R25 : R24
ADD R18,R16
ADC R19,R17
SUBI R18,255
SBCI R19,255
MOVW R5 : R4,R19 : R18
// 193 } while(lastDeviation != OWI_ROM_SEARCH_FINISHED);
TST R8
BRNE ??SearchBuses_7
// 194 }
// 195 }
??SearchBuses_6:
LSL R26
RJMP ??SearchBuses_4
// 196
// 197 // Go through all the devices and do CRC check.
// 198 for (i = 0; i < numDevices; i++)
??SearchBuses_5:
LDI R27,0
??SearchBuses_8:
CP R27,R7
BRCC ??SearchBuses_9
// 199 {
// 200 // If any id has a crc error, return error.
// 201 if(OWI_CheckRomCRC(devices[i].id) != OWI_CRC_OK)
MOV R20,R27
LDI R21,0
LDI R16,9
LDI R17,0
CALL ?S_EC_MUL_L02
MOVW R19 : R18,R25 : R24
ADD R18,R16
ADC R19,R17
SUBI R18,255
SBCI R19,255
MOVW R17 : R16,R19 : R18
CALL OWI_CheckRomCRC
TST R16
BREQ ??SearchBuses_10
// 202 {
// 203 return SEARCH_CRC_ERROR;
LDI R16,1
RJMP ??SearchBuses_11
// 204 }
// 205 }
??SearchBuses_10:
INC R27
RJMP ??SearchBuses_8
// 206 // Else, return Successful.
// 207 return SEARCH_SUCCESSFUL;
??SearchBuses_9:
LDI R16,0
??SearchBuses_11:
LDI R30,15
JMP ?EPILOGUE_B15_L09
CFI EndBlock cfiBlock1
// 208 }
// 209
// 210 /*! \brief Find the first device of a family based on the family id
// 211 *
// 212 * This function returns a pointer to a device in the device array
// 213 * that matches the specified family.
// 214 *
// 215 * \param familyID The 8 bit family ID to search for.
// 216 *
// 217 * \param devices An array of devices to search through.
// 218 *
// 219 * \param size The size of the array 'devices'
// 220 *
// 221 * \return A pointer to a device of the family.
// 222 * \retval NULL if no device of the family was found.
// 223 */
RSEG CODE:CODE:NOROOT(1)
// 224 OWI_device * FindFamily(unsigned char familyID, OWI_device * devices, unsigned char size)
FindFamily:
CFI Block cfiBlock2 Using cfiCommon0
CFI Function FindFamily
// 225 {
MOV R20,R16
MOV R22,R17
// 226 unsigned char i = 0;
LDI R21,0
// 227
// 228 // Search through the array.
// 229 while (i < size)
??FindFamily_0:
CP R21,R22
BRCC ??FindFamily_1
// 230 {
// 231 // Return the pointer if there is a family id match.
// 232 if ((*devices).id[0] == familyID)
MOVW R31 : R30,R19 : R18
LDD R16,Z+1
CP R16,R20
BRNE ??FindFamily_2
// 233 {
// 234 return devices;
MOVW R17 : R16,R19 : R18
RET
// 235 }
// 236 devices++;
??FindFamily_2:
SUBI R18,247
SBCI R19,255
// 237 i++;
INC R21
RJMP ??FindFamily_0
// 238 }
// 239 // Else, return NULL.
// 240 return NULL;
??FindFamily_1:
LDI R16,0
LDI R17,0
RET
CFI EndBlock cfiBlock2
// 241 }
// 242
// 243
// 244 /*! \brief Read the temperature from a DS1820 temperature sensor.
// 245 *
// 246 * This function will start a conversion and read back the temperature
// 247 * from a DS1820 temperature sensor.
// 248 *
// 249 * \param bus A bitmask of the bus where the DS1820 is located.
// 250 *
// 251 * \param id The 64 bit identifier of the DS1820.
// 252 *
// 253 * \return The 16 bit signed temperature read from the DS1820.
// 254 */
RSEG CODE:CODE:NOROOT(1)
// 255 signed int DS1820_ReadTemperature(unsigned char bus, unsigned char * id)
DS1820_ReadTemperature:
CFI Block cfiBlock3 Using cfiCommon0
CFI Function DS1820_ReadTemperature
// 256 {
FUNCALL DS1820_ReadTemperature, OWI_DetectPresence
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_MatchRom
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_SendByte
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_ReadBit
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_DetectPresence
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_MatchRom
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_SendByte
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_ReceiveByte
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS1820_ReadTemperature, OWI_ReceiveByte
LOCFRAME CSTACK, 6, STACK
LOCFRAME RSTACK, 2, STACK
CALL ?PROLOGUE6_L09
CFI R5 Frame(CFA_Y, -1)
CFI R4 Frame(CFA_Y, -2)
CFI R27 Frame(CFA_Y, -3)
CFI R26 Frame(CFA_Y, -4)
CFI R25 Frame(CFA_Y, -5)
CFI R24 Frame(CFA_Y, -6)
CFI CFA_Y Y+6
REQUIRE ?Register_R4_is_cg_reg
REQUIRE ?Register_R5_is_cg_reg
MOV R24,R16
MOVW R27 : R26,R19 : R18
// 257 signed int temperature;
// 258
// 259 // Reset, presence.
// 260 if (!OWI_DetectPresence(bus))
MOV R16,R24
CALL OWI_DetectPresence
TST R16
BRNE ??DS1820_ReadTemperature_0
// 261 {
// 262 return DS1820_ERROR; // Error
LDI R16,24
LDI R17,252
RJMP ??DS1820_ReadTemperature_1
// 263 }
// 264 // Match the id found earlier.
// 265 OWI_MatchRom(id, bus);
??DS1820_ReadTemperature_0:
MOV R18,R24
MOVW R17 : R16,R27 : R26
CALL OWI_MatchRom
// 266 // Send start conversion command.
// 267 OWI_SendByte(DS1820_START_CONVERSION, bus);
MOV R17,R24
LDI R16,68
CALL OWI_SendByte
// 268 // Wait until conversion is finished.
// 269 // Bus line is held low until conversion is finished.
// 270 while (!OWI_ReadBit(bus))
??DS1820_ReadTemperature_2:
MOV R16,R24
CALL OWI_ReadBit
TST R16
BREQ ??DS1820_ReadTemperature_2
// 271 {
// 272
// 273 }
// 274 // Reset, presence.
// 275 if(!OWI_DetectPresence(bus))
MOV R16,R24
CALL OWI_DetectPresence
TST R16
BRNE ??DS1820_ReadTemperature_3
// 276 {
// 277 return -1000; // Error
LDI R16,24
LDI R17,252
RJMP ??DS1820_ReadTemperature_1
// 278 }
// 279 // Match id again.
// 280 OWI_MatchRom(id, bus);
??DS1820_ReadTemperature_3:
MOV R18,R24
MOVW R17 : R16,R27 : R26
CALL OWI_MatchRom
// 281 // Send READ SCRATCHPAD command.
// 282 OWI_SendByte(DS1820_READ_SCRATCHPAD, bus);
MOV R17,R24
LDI R16,190
CALL OWI_SendByte
// 283 // Read only two first bytes (temperature low, temperature high)
// 284 // and place them in the 16 bit temperature variable.
// 285 temperature = OWI_ReceiveByte(bus);
MOV R16,R24
CALL OWI_ReceiveByte
LDI R17,0
MOVW R5 : R4,R17 : R16
// 286 temperature |= (OWI_ReceiveByte(bus) << 8);
MOV R16,R24
CALL OWI_ReceiveByte
MOV R19,R16
LDI R18,0
OR R4,R18
OR R5,R19
// 287
// 288 return temperature;
MOVW R17 : R16,R5 : R4
??DS1820_ReadTemperature_1:
LDI R30,6
JMP ?EPILOGUE_B6_L09
CFI EndBlock cfiBlock3
// 289 }
// 290
// 291
// 292 /*! \brief Set the wiper position of a DS2890.
// 293 *
// 294 * This function initializes the DS2890 by enabling the charge pump. It then
// 295 * changes the wiper position.
// 296 *
// 297 * \param position The new wiper position.
// 298 *
// 299 * \param bus The bus where the DS2890 is connected.
// 300 *
// 301 * \param id The 64 bit identifier of the DS2890.
// 302 */
RSEG CODE:CODE:NOROOT(1)
// 303 void DS2890_SetWiperPosition(unsigned char position, unsigned char bus, unsigned char * id)
DS2890_SetWiperPosition:
CFI Block cfiBlock4 Using cfiCommon0
CFI Function DS2890_SetWiperPosition
// 304 {
FUNCALL DS2890_SetWiperPosition, OWI_DetectPresence
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS2890_SetWiperPosition, OWI_MatchRom
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS2890_SetWiperPosition, OWI_SendByte
LOCFRAME CSTACK, 4, STACK
LOCFRAME RSTACK, 2, STACK
FUNCALL DS2890_SetWiperPosition, OWI_SendByte
LOCFRAME CSTACK, 4, STACK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -