描述
<h3>1、项目功能介绍</h3>
<p>利用单片机控制io,生成pwm调速风扇,屏幕显示当前温度和风扇转速,同时读取温湿度,智能调节转速</p>
<hr>
<h3>2、项目属性</h3>
<p>项目为首次公开,个人原创设计,未参与过其他比赛</p>
<hr>
<h3>3、开源协议</h3>
<p>CC BY-NC 3.0</p>
<hr>
<h3>4、硬件部分</h3>
<p>MCU采用STM32F103</p>
<p>搭载SHT41I温湿度传感器</p>
<p><img src="//image.lceda.cn/oshwhub/bc3da415125e41c585fa2bb057736a60.jpg" alt="51b1dcbeb72c431fbd916e71f7b44656.jpg"></p>
<p><img src="//image.lceda.cn/oshwhub/cd0aa762b0e741f9bc1f74e7f1815a45.jpg" alt="84a5916da6044c47b177f9b1c0e070a4.jpg"></p>
<p><img src="//image.lceda.cn/oshwhub/2e3a1e4c41c84f5390d2f21eb392e303.jpg" alt="482cb54e90c244108f0cd96eb93a2e76.jpg"></p>
<h4>io分配图</h4>
<p><img src="//image.lceda.cn/oshwhub/7bdb8c6d43f74cafac65e6e7e354299d.png" alt="10c8c5c947ea419cbd3de92abc6d2d08.png"></p>
<ul>
<li>PA9与PA8分别为TIM1的俩通道,用于编码器</li>
<li>PA10为EC11的按钮</li>
<li>PA6为风扇的PWM控速</li>
<li>PB1为风扇的mos控制</li>
<li>PB2为风扇的ARGB控制</li>
</ul>
<hr>
<h3>5、大赛LOGO验证</h3>
<p><img src="//image.lceda.cn/oshwhub/63aec0e0d1de4e9e8c166096a43589c2.jpg" alt="e73c58b2b1c246e19f55e7009d7ef48f.jpg"></p>
<hr>
<h3>6、代码</h3>
<pre><code>
//GPIO中断
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == SW_Pin)
{
uint32_t current_time = HAL_GetTick(); // 获取当前系统时间(毫秒)
if (current_time - last_interrupt_time < debounce_time)
{
return; // 忽略此次中断
}
last_interrupt_time = current_time;
printf(fan_mos ? "fan off\n" : "fan on\n");
fan_mos = !fan_mos;
HAL_GPIO_WritePin(FAN_MOS_GPIO_Port, FAN_MOS_Pin, fan_mos);
if (fan_mos)
{
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); // 启动 PWM
}
else
{
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); // 停止 PWM
}
}
}
//旋转编码器计时器中断
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim)
{
if (htim->Instance == TIM1)
{
uint32_t current_time = HAL_GetTick(); // 获取当前系统时间(毫秒)
if (current_time - pwm_last_interrupt_time < debounce_time)
{
return; // 忽略此次中断
}
pwm_last_interrupt_time = current_time;
int enCodeCount;
const int count = __HAL_TIM_GET_COUNTER(&htim1);
if (count > 6000)
{
enCodeCount = 0;
__HAL_TIM_SET_COUNTER(&htim1, 0);
}
else if (count > 100)
{
enCodeCount = 100;
__HAL_TIM_SET_COUNTER(&htim1, 100);
}
else
{
enCodeCount = count;
}
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, enCodeCount);
printf("%d \n", enCodeCount);
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
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_USART1_UART_Init();
MX_TIM3_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Encoder_Start_IT(&htim1, TIM_CHANNEL_ALL);
// HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
// HAL_GPIO_WritePin(FAN_MOS_GPIO_Port,FAN_MOS_Pin, GPIO_PIN_SET);
// HAL_GPIO_WritePin(ARGB_MOS_GPIO_Port,ARGB_MOS_Pin, GPIO_PIN_SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// printf("%d", HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_10));
// HAL_Delay(200);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}</code></pre>
评论(1)