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
29
30void 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
39int main(void)
40{
41 uint8_t i, sp;
42
44 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
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
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
62 while (!DS18B20_AllDone())
63 {
64 UART1_TxChar('.');
65 SYS_Delay(50);
66 }
69 UART1_TxChar(' ');
71 UART1_TxString("CRC:");
73 UART1_TxChar(' ');
74 UART1_TxString("\r\n");
75 } while (sp);
76
77 UART1_TxString("\r\n");
78 SYS_Delay(1000);
79 }
80}
void DS18B20_Init(void)
Initialize DS18B20.
Definition: DS18B20_ATY.c:53
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxChar(char dat)
Definition: fw_uart.c:72
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer1
Definition: fw_uart.h:33
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
int main(void)
Definition: main.c:45
uint8_t Search_Stack[8]
Definition: main.c:28
uint8_t DS18B20_Buff[9]
Definition: main.c:28
void PrintArray(uint8_t *arr, uint8_t start, uint8_t end)
Definition: main.c:30
uint8_t addr[8]
Definition: main.c:28
uint8_t __XDATA i
void DS18B20_ReadScratchpadFromAddr(const uint8_t *addr, uint8_t *buf)
Read SRAM scratchpad from selected slave.
Definition: ds18b20.c:224
uint8_t DS18B20_Crc(uint8_t *addr, uint8_t len)
8-bit CRC calculation
Definition: ds18b20.c:151
uint8_t DS18B20_Search(uint8_t *buff, uint8_t *stack, uint8_t split_point)
Perform one ROM search.
Definition: ds18b20.c:242
__BIT DS18B20_AllDone(void)
If read bit is low, then device is not finished yet with calculation temperature.
Definition: ds18b20.c:183
void DS18B20_Start(const uint8_t *addr)
Start conversion on selected slave.
Definition: ds18b20.c:214