LM35CHUAN1
LM35CHUAN1
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
uint8_t delay_send_data = 0;
uint8_t delay_led = 0;
uint8_t led_state = 0;
uint8_t cai_dat1 = 0;
uint8_t cai_dat2 = 1;
uint8_t muc1 = 30;
uint8_t muc2 = 40;
uint8_t muc3 = 50;
uint8_t muc_state = 0;
/* USER CODE END PD */
TIM_HandleTypeDef htim1;
UART_HandleTypeDef huart1;
/**
* @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();
LCD_Clear();
LCD_Gotoxy(1, 1);
LCD_Putsf("Hoang Trung");
HAL_Delay(2000);
LCD_Clear();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
if(Nhan_cai == 0){
cai_dat1 = 1;
}
// nut nhan cai dat
while (cai_dat1 == 1){
LCD_Clear();
LCD_Gotoxy(0, 0);
sprintf(LCD_send, "CAI MUC: %d", cai_dat2);
LCD_Putsf(LCD_send);
if(cai_dat2 == 1){
if(Nhan_tang == 0){
muc1 += 1;
if(muc1 == muc2){
muc1 = muc2 - 1;
}
}
if(Nhan_giam == 0){
muc1 -= 1;
if(muc1 < 10){
muc1 = 10;
}
}
LCD_Gotoxy(1, 0);
LCD_Putnum(muc1, muc1);
}
if(cai_dat2 == 2){
if(Nhan_tang == 0){
muc2 += 1;
if(muc2 == muc3){
muc2 = muc3 - 1;
}
}
if(Nhan_giam == 0){
muc2 -= 1;
if(muc2 == muc1){
muc2 = muc1 + 1;
}
}
LCD_Gotoxy(1, 0);
LCD_Putnum(muc2, muc2);
}
if(cai_dat2 == 3){
if(Nhan_tang == 0){
muc3 += 1;
if(muc3 == 110){
muc3 = muc3 - 1;
}
}
if(Nhan_giam == 0){
muc3 -= 1;
if(muc3 == muc2){
muc3 = muc2 + 1;
}
}
LCD_Gotoxy(1, 0);
LCD_Putnum(muc3, muc3);
}
if(Nhan_ok == 0){
cai_dat2 += 1;
if(cai_dat2 == 4){
cai_dat2 = 1;
cai_dat1 = 0;
}
}
HAL_Delay(200);
}
HAL_ADC_Start_IT(&hadc1);
LCD_Clear();
LCD_Gotoxy(0, 0);
sprintf(LCD_send, "Nhiet do: %d do", (int)temperature);
LCD_Putsf(LCD_send);
LCD_Gotoxy(1,0);
sprintf(LCD_send, "1:%d 2:%d 3:%d", muc1, muc2, muc3);
LCD_Putsf(LCD_send);
HAL_Delay(1000);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
/**
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM1_Init(void)
{
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/**
* @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 */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#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,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */