主函数:
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t count=0;
/* 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_DMA_Init();
MX_ADC1_Init();
MX_TIM1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
//桥臂1和桥臂2使能
HAL_GPIO_WritePin(GPIOC, EN1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC, EN2_Pin, GPIO_PIN_SET);
//PWM通道使能
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
//开启ADC采集
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)Get_ADC,1000);
//初始化上位机
debug_init();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(KEY_Scany(KEY_GPIO_Port,KEY_Pin)==1)
{
Duty+=5;
if(Duty>=100)
Duty=100;
TIM1->CCR1=Duty;
}
HAL_Delay(10);
if(count%50==0)
{
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
debug_send_wave_data(1,Get_Current);
debug_send_wave_data(2,Get_ADC_Val);
count=0;
}
count++;
}
/* USER CODE END 3 */
} |