Parking sensor by using STM32CubeIDE and HC-SR04
Sources : 1- www.kaynak1.com 2- www.kaynak2.com The hardwares that I used : STM32F103C8 ST-LΔ°NK V2 HC-SR04 ULTRASONIC SENSOR LCD 16 X 2 πππππππππππππππππππππππ πππππππππππππππππππππππ main.c file : #include "main.h" #include "i2c-lcd.h" I2C_HandleTypeDef hi2c1; TIM_HandleTypeDef htim1; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_I2C1_Init(void); static void MX_TIM1_Init(void); void delay (uint16_t time) { __HAL_TIM_SET_COUNTER(&htim1, 0); while (__HAL_TIM_GET_COUNTER (&htim1) < time); } uint32_t IC_Val1 = 0; uint32_t IC_Val2 = 0; uint32_t Difference = 0; uint8_t Is_First_Captured = 0; // is the first value captured ? uint8_t Distance = 0; #define TRIG_PIN GPIO_PIN_9 #define TRIG_PORT GPIOA // Let's write the callback function void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { if (htim->Channel == HAL_TIM_ACTIVE