旋转编码计数器
修改中断代码
void EXTI0_IRQHandler(void)
{/* USER CODE BEGIN EXTI0_IRQn 0 */if(__HAL_GPIO_EXTI_GET_FLAG(PB0_Pin)){if(HAL_GPIO_ReadPin(PB1_GPIO_Port, PB1_Pin)==GPIO_PIN_RESET){count--;}/* USER CODE END EXTI0_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(PB0_Pin);/* USER CODE BEGIN EXTI0_IRQn 1 */}/* USER CODE END EXTI0_IRQn 1 */
}/*** @brief This function handles EXTI line1 interrupt.*/
void EXTI1_IRQHandler(void)
{/* USER CODE BEGIN EXTI1_IRQn 0 */
if(__HAL_GPIO_EXTI_GET_FLAG(PB1_Pin))
{if(HAL_GPIO_ReadPin(PB0_GPIO_Port, PB0_Pin)==GPIO_PIN_RESET){count++;}/* USER CODE END EXTI1_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(PB1_Pin);/* USER CODE BEGIN EXTI1_IRQn 1 *//* USER CODE END EXTI1_IRQn 1 */}
}
添加计数函数
int16_t get_sensorcounter(void)
{return count;
}
注意!!!!!!!!!!!
这边的都伤int而不是uint和上面的有所不一样要不然打印出来的数字就不对了