Code Ok
Code Ok
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2022 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "tim.h"
#include "gpio.h"
#include "stdio.h"
#include "string.h"
#include "i2c-lcd.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
char dulieu[20];
uint8_t Presence = 0;
float Temperature = 0;
uint8_t Temp_byte1;
uint8_t Temp_byte2;
uint16_t TEMP;
//float t = 30.57;
/* USER CODE END Includes */
#define DS18B20_PORT GPIOB
#define DS18B20_PIN GPIO_PIN_9
return Response;
}
Set_Pin_Output(DS18B20_PORT, DS18B20_PIN);
HAL_GPIO_WritePin (DS18B20_PORT, DS18B20_PIN, 0); // pull the
pin LOW
delay(50); // wait for 60 us
Set_Pin_Intput(DS18B20_PORT, DS18B20_PIN);
}
}
}
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
lcd_put_cur(0,4);
lcd_send_string("DS18B20");
lcd_put_cur(1,2);
lcd_send_string("T = ");
lcd_put_cur(1,11);
lcd_send_data(223);
lcd_put_cur(1,12);
lcd_send_string("C");
DS18B20_Start();
Presence = DS18B20_Start ();
delay (1);
DS18B20_Write (0xCC); // skip ROM
DS18B20_Write (0x44); // convert t
delay (800);
Temp_byte1 = DS18B20_Read();
Temp_byte2 = DS18B20_Read();
TEMP = (Temp_byte2 <<8)|Temp_byte1;
Temperature = (float)TEMP/16;
sprintf(dulieu,"%2.2f",Temperature);
lcd_send_cmd(0x80|0x46);
lcd_send_string(dulieu);
HAL_Delay(1000);
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */