feat: some minor changes in ds18b20 demos

This commit is contained in:
IOsetting 2022-06-11 20:09:05 +08:00
parent 7f5b165ac4
commit 452c3b9a1e
5 changed files with 14 additions and 11 deletions

View File

@ -16,14 +16,15 @@
void DS18B20_Init(void)
{
/* Pull up 2 seconds for possible capacitor charging */
DS18B20_DQ_PULLUP();
DS18B20_DQ_OUTPUT();
DS18B20_DQ = SET;
SYS_DelayUs(1000);
SYS_Delay(1000);
DS18B20_DQ = RESET;
SYS_DelayUs(1000);
SYS_Delay(1);
DS18B20_DQ = SET;
SYS_DelayUs(2000);
SYS_Delay(1000);
}
__BIT DS18B20_Reset(void)
@ -238,7 +239,7 @@ void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf)
}
}
uint8_t DS18B20_Detect(uint8_t *buff, uint8_t *stack, uint8_t split_point)
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point)
{
uint8_t len = 64, pos = 0;
/* Start from deepest point */

View File

@ -163,6 +163,6 @@ void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf);
* @param split_point deepest split point of last search
* @return new split point
*/
uint8_t DS18B20_Detect(uint8_t *buff, uint8_t *stack, uint8_t split_point);
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point);
#endif // __DS18B20_H_

View File

@ -52,7 +52,7 @@ int main(void)
do
{
// ROM search and store ROM bytes to addr
sp = DS18B20_Detect(addr, Search_Stack, sp);
sp = DS18B20_Search(addr, Search_Stack, sp);
// Print the new split point and address
UART1_TxHex(sp);
UART1_TxChar(' ');
@ -74,6 +74,7 @@ int main(void)
UART1_TxString("\r\n");
} while (sp);
UART1_TxString("\r\n");
SYS_Delay(1000);
}
}

View File

@ -16,14 +16,15 @@
void DS18B20_Init(void)
{
/* Pull up 2 seconds for possible capacitor charging */
DS18B20_DQ_PULLUP();
DS18B20_DQ_OUTPUT();
DS18B20_DQ = SET;
SYS_DelayUs(1000);
SYS_Delay(1000);
DS18B20_DQ = RESET;
SYS_DelayUs(1000);
SYS_Delay(1);
DS18B20_DQ = SET;
SYS_DelayUs(2000);
SYS_Delay(1000);
}
__BIT DS18B20_Reset(void)
@ -238,7 +239,7 @@ void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf)
}
}
uint8_t DS18B20_Detect(uint8_t *buff, uint8_t *stack, uint8_t split_point)
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point)
{
uint8_t len = 64, pos = 0;
/* Start from deepest point */

View File

@ -163,6 +163,6 @@ void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf);
* @param split_point deepest split point of last search
* @return new split point
*/
uint8_t DS18B20_Detect(uint8_t *buff, uint8_t *stack, uint8_t split_point);
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point);
#endif // __DS18B20_H_