最近学习了32,做了一个小东玩玩,给大家分享一下
int main(void)
{
/* USER CODE BEGIN 1 */
char dispBuff[100];
float distance;
/* 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_FSMC_Init();
MX_USART2_UART_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
//HAL_UART_Receive_IT(&huart2, (uint8_t *)&aRxBuffer, 1);
HAL_UART_Receive_IT(&huart2, (uint8_t*)recv_buf, 1);
ILI9341_Init ();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
distance = Hcsr04_Get_Distance();
printf("juli:%.2f cm\r\n",distance/10.0);
ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);
ILI9341_DispStringLine_EN(LINE(0),"bbgu");
LCD_SetFont(&Font16x24);
LCD_SetTextColor(RED);
sprintf(dispBuff,"juli:%.2f cm",distance/10.0);
LCD_ClearLine(LINE(4));
ILI9341_DispStringLine_EN(LINE(4),dispBuff);
switch(flag)
{
case 0:
direction = 1;
Motor_Angle_Cal(90);
break;
case 1 :
direction = 0;
Motor_Angle_Cal(90);
break;
}
HAL_Delay(1000);
}
/* USER CODE END 3 */
}
|