|
kiểm soát demo bước Servor
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "uart.h"
- #include "control.h"
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- int main(void)
- {
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- SystemClock_Config();
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART1_UART_Init();
- MX_USART2_UART_Init();
- /* USER CODE BEGIN 2 */
- HAL_UART_Receive_IT(&huart2, (uint8_t*) &UART1_Data, 1);
- /* USER CODE END 2 */
- DWT_Delay_Init();
-
-
- while (1)
- {
-
- if(UART_Buffer[0]!=0){
- sprintf(copy,"%s\r\n", UART_Buffer);
-
- cpystr(&chuoi[0],substr(©[0],0,0));
- printf("%s\r\n",&chuoi[0]);
- home=chuoi[0];
- // ta=atoi(&n[0]);
- cpystr(&chuoi[1],substr(©[1],7,7));
- printf("%s\r\n",&chuoi[1]);
- // svong=atoi(&chuoi[1]);
- cpystr(&chuoi[2],substr(©[2],9,9));
- printf("%s\r\n",&chuoi[2]);
- // dir=atoi(&chuoi[2]);
-
- HAL_Delay(700);
-
- if(copy[0]>0&&chuoi[0]>0){
- for(int h=0;h<100;h++){
- copy[h]=0;
- chuoi[h]=0;
- }
- for(int p=0;p<100;p++){
- UART_Buffer[p]=0;
- }
- }
- }
- HAL_Delay(500);
- //=====================================================================================================
- if(home=='h'){
- if(HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==1&&HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==1){
- dc2(phai,1,100); // lui ve
- }
- else{
- stopdc2();
- }
- if(HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==1&&HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0){
- dc2(phai,1,100); // lui ve
- }
- else{
- stopdc2();
- }
-
- if(HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==1&&HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==0){
- dc1(trai,1,100); // lui ve
- }
- else{
- stopdc1();
- }
- if (HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0&&HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==0){
- stopdc1();
- stopdc2();
- home=0;
- }
-
- }
- else{
- stopdc1();
- stopdc2();
- }
- //=================================================================================================================
- if(home=='r'){
- if(HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0 && HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==0)
- {
- dc2(trai,7,40);
- if(HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0){
- for(int k =0 ; k<9 ;k ++){
- vitriy(phai,20,50);
- HAL_Delay(700);
-
- }
- dc2(trai,3,40);
-
- for(int lo =0 ; lo<9 ;lo++){
- vitriy(trai,20,50);
- HAL_Delay(700);
- }
- dc2(trai,3,40);
-
- for(int m =0 ; m<9 ;m ++){
- vitriy(phai,20,50);
- HAL_Delay(700);
- }
- for(int dd =0 ; dd<9 ;dd ++){
- vitriy(trai,20,50);
- }
- if(HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0){
- stopdc1();
- dc2(phai,5,40);
- dc2(phai,3,70);
- dc2(phai,3,90);
- runx(100,2200);
- }
- else{
- stopdc2();
- }
- if(HAL_GPIO_ReadPin(STOP2_GPIO_Port,STOP2_Pin)==0&&HAL_GPIO_ReadPin(STOP3_GPIO_Port,STOP3_Pin)==0){
- HAL_Delay(500);
- stopdc2();
- stopdc1();
- home=0;
- }
- }
- }
- }
- else{
- stopdc1();
- stopdc2();
- }
-
-
-
- //==========================================================================================
-
- }
- }
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- /** Initializes the CPU, AHB and APB busses clocks
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Initializes the CPU, AHB and APB busses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
- {
- Error_Handler();
- }
- }
- void Error_Handler(void)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- /* 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,
- tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
复制代码
|
评分
-
查看全部评分
|