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 with single DS18B20
17 *
18 * Board: STC8H3K32
19 *
20 * Normal Power Mode:
21 * P35 -> DQ
22 * GND -> GND
23 * 5V/3.3V -> VDD
24 *
25 * Parasite Power Mode:
26 * Parasite power mode requires both DS18B20 GND and Vdd to be
27 * connected to ground. The DQ pin is the data/parasite power line,
28 * which requires a pull-up resistor (set by PxPU command)
29 * P35 -> DQ
30 * GND -> GND -> VDD
31 * 5V
32 *
33 * Parasite Power Mode Emulation:
34 * In case some DS18B20 doesn't work in parasite mode, you can add one
35 * 0.1uF capacitor and one 1N4148 to achieve it. In thise way DS18B20
36 * actually works in normal power mode
37 *
38 * +-----1N4148-|>|-----+
39 * | |
40 * | |DS18B20|-VCC--+
41 * | | | |
42 * P35 --+-DQ--|DS18B20| 0.1uF
43 * | | |
44 * GND ----GND-|DS18B20|-GND--+
45 *
46 */
47
48
49#include "fw_hal.h"
50#include "ds18b20.h"
51
52void PrintArray(uint8_t *arr, uint8_t start, uint8_t end)
53{
54 uint8_t i;
55 for (i = start; i < end; i++)
56 {
57 UART1_TxHex(*(arr + i));
58 }
59}
60
61int main(void)
62{
63 uint8_t buff[9], i;
64
66 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
69
70 while(1)
71 {
73 /*
74 In Parasite Power Mode, replace the while block below with
75 SYS_Delay(x), x can be [500, 1000]
76 */
77 while (!DS18B20_AllDone())
78 {
79 UART1_TxChar('.');
80 SYS_Delay(50);
81 }
83 PrintArray(buff, 0, 9);
84 UART1_TxChar(' ');
85 i = DS18B20_Crc(buff, 8);
86 UART1_TxString("CRC:");
88 UART1_TxChar(' ');
89 UART1_TxString("\r\n");
90 SYS_Delay(1000);
91 }
92}
void DS18B20_Init(void)
Initialize DS18B20.
Definition: DS18B20_ATY.c:53
__XDATA uint8_t buff[7]
Definition: ds3231.c:17
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
void PrintArray(uint8_t *arr, uint8_t start, uint8_t end)
Definition: main.c:30
uint8_t __XDATA i
uint8_t DS18B20_Crc(uint8_t *addr, uint8_t len)
8-bit CRC calculation
Definition: ds18b20.c:151
void DS18B20_StartAll(void)
Start conversion on all slaves.
Definition: ds18b20.c:173
void DS18B20_ReadScratchpad(uint8_t *buf)
Read SRAM scratchpad.
Definition: ds18b20.c:133
__BIT DS18B20_AllDone(void)
If read bit is low, then device is not finished yet with calculation temperature.
Definition: ds18b20.c:183