Untitled
unknown
plain_text
22 days ago
4.4 kB
9
Indexable
Never
while (1) { /* USER CODE END WHILE */ int length=sprintf(buffer,"%d - ",bl); HAL_TIM_Base_Start_IT(&htim6); if(bl>12){ HAL_TIM_Base_Stop_IT(&htim6); break; } /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){ if(htim==&htim6){ HAL_UART_Transmit(&huart3,(uint8_t *)buffer,strlen(buffer),10); if(bl<7){ HAL_UART_Transmit(&huart3,(uint8_t *)"Low Charge\r\n",15,10); } else if(bl>=7 && bl<12){ HAL_UART_Transmit(&huart3,(uint8_t *)"Moderate Charge\r\n",20,10); } else{ HAL_UART_Transmit(&huart3,(uint8_t *)"Full Charge\r\n",15,10); } bl++; } } /////////////////////////////////////////////////////////////////// while (1) { /* USER CODE END WHILE */ if(ch=='l'){ HAL_UART_Transmit(&huart3,lt,sizeof(lt),1); }else if(ch=='r'){ HAL_UART_Transmit(&huart3,rt,sizeof(rt),1); }else{ HAL_UART_Transmit(&huart3,off,sizeof(off),1); } HAL_UART_Receive(&huart3,&ch,1,1000); delay(1); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } //////////////////////////////////////////////////////////////////////////////////////////// void delay(int i){ HAL_TIM_Base_Start(&htim6); while(__HAL_TIM_GET_COUNTER(&htim6) < i*2000); HAL_TIM_Base_Stop(&htim6); __HAL_TIM_SET_COUNTER(&htim6,0); } int speed=0; uint8_t a[]="Cruise Control : Active\r\n"; uint8_t ia[]="Cruise Control : Inactive\r\n"; int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART3_UART_Init(); MX_USB_OTG_HS_USB_Init(); MX_TIM6_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ char buffer[50]; sprintf(buffer,"Current Speed : %d Km/h\r\n",speed); HAL_UART_Transmit(&huart3,(uint8_t *)buffer,strlen(buffer),10); if(speed==40){ HAL_UART_Transmit(&huart3,a,sizeof(a),10); } if(speed==80){ HAL_UART_Transmit(&huart3,ia,sizeof(ia),10); } speed+=5; delay(2); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } //////////////////////////////////////////////////////////////////////////////////////// HAL_TIM_Base_Start(&htim6); while (1) { /* USER CODE END WHILE */ HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0); HAL_UART_Transmit(&huart3,tx1,strlen((char*)tx1),10); __HAL_TIM_SET_COUNTER(&htim6,0); while(__HAL_TIM_GET_COUNTER(&htim6) < 10000){} //5sec delay HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0); HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_1); HAL_UART_Transmit(&huart3,tx2,strlen((char*)tx2),10); __HAL_TIM_SET_COUNTER(&htim6,0); while(__HAL_TIM_GET_COUNTER(&htim6) < 20000){} //10sec delay HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_1); HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14); HAL_UART_Transmit(&huart3,tx3,strlen((char*)tx3),10); __HAL_TIM_SET_COUNTER(&htim6,0); while(__HAL_TIM_GET_COUNTER(&htim6) < 10000){} //5sec delay HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /////////////////////////////////////////////////////////////////////////////////////////////////////// __HAL_TIM_CLEAR_FLAG(&htim6, TIM_FLAG_UPDATE); HAL_TIM_Base_Start_IT(&htim6); __HAL_TIM_CLEAR_FLAG(&htim7, TIM_FLAG_UPDATE); HAL_TIM_Base_Start_IT(&htim7); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){ if(htim==&htim6){ HAL_UART_Transmit(&huart3,t6,sizeof(t6),10); } if(htim==&htim7){ HAL_UART_Transmit(&huart3,t7,sizeof(t7),10); } } /////////////////////////////////////////////////////////////////////////////////////////
Leave a Comment