ATY_LIB
V2_102_230218
ATY_LIB for general devices or ALGO
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/***
16
* Example code of communication on 1-Wire bus with multiple DS18B20
17
*
18
* Board: STC8H3K32
19
*
20
* P35 -> DQ
21
* GND -> GND
22
* 3.3V -> VCC
23
*/
24
25
#include "
fw_hal.h
"
26
#include "
ds18b20.h
"
27
28
uint8_t
DS18B20_Buff
[9],
addr
[8],
Search_Stack
[8];
29
30
void
PrintArray
(
uint8_t
*arr,
uint8_t
start,
uint8_t
end)
31
{
32
uint8_t
i
;
33
for
(
i
= start;
i
< end;
i
++)
34
{
35
UART1_TxHex
(*(arr +
i
));
36
}
37
}
38
39
int
main
(
void
)
40
{
41
uint8_t
i
, sp;
42
43
SYS_SetClock
();
44
// UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
45
UART1_Config8bitUart
(
UART1_BaudSource_Timer1
,
HAL_State_ON
, 115200);
46
DS18B20_Init
();
47
48
while
(1)
49
{
50
// Reset split point and search for all DS18B20
51
sp = 0;
52
do
53
{
54
// ROM search and store ROM bytes to addr
55
sp =
DS18B20_Search
(
addr
,
Search_Stack
, sp);
56
// Print the new split point and address
57
UART1_TxHex
(sp);
58
UART1_TxChar
(
' '
);
59
PrintArray
(
addr
, 0, 8);
60
// Convert and read from this address
61
DS18B20_Start
(
addr
);
62
while
(!
DS18B20_AllDone
())
63
{
64
UART1_TxChar
(
'.'
);
65
SYS_Delay
(50);
66
}
67
DS18B20_ReadScratchpadFromAddr
(
addr
,
DS18B20_Buff
);
68
PrintArray
(
DS18B20_Buff
, 0, 9);
69
UART1_TxChar
(
' '
);
70
i
=
DS18B20_Crc
(
DS18B20_Buff
, 8);
71
UART1_TxString
(
"CRC:"
);
72
UART1_TxHex
(
i
);
73
UART1_TxChar
(
' '
);
74
UART1_TxString
(
"\r\n"
);
75
}
while
(sp);
76
77
UART1_TxString
(
"\r\n"
);
78
SYS_Delay
(1000);
79
}
80
}
DS18B20_Init
void DS18B20_Init(void)
Initialize DS18B20.
Definition:
DS18B20_ATY.c:53
fw_hal.h
SYS_SetClock
void SYS_SetClock(void)
Definition:
fw_sys.c:40
SYS_Delay
void SYS_Delay(uint16_t t)
Definition:
fw_sys.c:65
HAL_State_ON
@ HAL_State_ON
Definition:
fw_types.h:71
uint8_t
unsigned char uint8_t
Definition:
fw_types.h:18
UART1_TxChar
void UART1_TxChar(char dat)
Definition:
fw_uart.c:72
UART1_TxString
void UART1_TxString(uint8_t *str)
Definition:
fw_uart.c:85
UART1_BaudSource_Timer1
@ UART1_BaudSource_Timer1
Definition:
fw_uart.h:33
UART1_TxHex
void UART1_TxHex(uint8_t hex)
Definition:
fw_uart.c:79
UART1_Config8bitUart
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition:
fw_uart.c:56
main
int main(void)
Definition:
main.c:45
Search_Stack
uint8_t Search_Stack[8]
Definition:
main.c:28
DS18B20_Buff
uint8_t DS18B20_Buff[9]
Definition:
main.c:28
PrintArray
void PrintArray(uint8_t *arr, uint8_t start, uint8_t end)
Definition:
main.c:30
addr
uint8_t addr[8]
Definition:
main.c:28
i
uint8_t __XDATA i
Definition:
mem_read_chipid.c:24
DS18B20_ReadScratchpadFromAddr
void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf)
Read SRAM scratchpad from selected slave.
Definition:
ds18b20.c:224
DS18B20_Crc
uint8_t DS18B20_Crc(uint8_t *addr, uint8_t len)
8-bit CRC calculation
Definition:
ds18b20.c:151
DS18B20_Search
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point)
Perform one ROM search.
Definition:
ds18b20.c:242
DS18B20_AllDone
__BIT DS18B20_AllDone(void)
If read bit is low, then device is not finished yet with calculation temperature.
Definition:
ds18b20.c:183
DS18B20_Start
void DS18B20_Start(const uint8_t *addr)
Start conversion on selected slave.
Definition:
ds18b20.c:214
ds18b20.h
ATY_LIB
FwLib_STC8
demo
gpio
ds18b20
multiple-ds18b20
main.c
Generated by
1.9.6