【蓝桥杯】基于STM32G431模块总结

目录

 一.LED部分

二.按键部分 

三.ADC部分 

四.基于IIC的24c02读写部分(EEPROM)

 五.LCD显示部分

 六.定时器部分

1.定时器中断回调

2. PWM输出改变频率和占空比

3.输入捕获测量占空比和频率(利用主从模式) 

 4.方波输出回调

七.RTC部分


 一.LED部分


uint8_t ucled;

void LED_Disp(uint8_t ucLed)
{
	/***将所有的灯熄灭***/
	HAL_GPIO_WritePin(GPIOC,0xff00, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);		
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIdouN_RESET);
	/***根据ucLed的数值点亮相应的灯***/
	HAL_GPIO_WritePin(GPIOC, ucLed<<8, GPIO_PIN_RESET);
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);		
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);		
}
/***使用 |= 和 &= 在更改指定led时不会影响到其他led***/
	if (led1_flag) 
	{ 	/***LED1常亮***/
		ucled |= 0x01;
	}
	else 
	{	/***有开就要有关,不然亮了关不掉***/
		ucled &= ~0x01;
	}
/***led以某一频率闪烁***/
	if (uwTick - ledTick < 500) return;
		ledTick = uwTick;
			if (flag) 
		{  //以某频率闪烁 (0.5s)  
			ucled ^= 0x02;
		}
		else 
		{
			ucled &= ~0x02;
		}
		
/***led亮几秒后熄灭
某种情况flag = 1 后 
cnt = 0;
***/
	if (flag) 
	{  //点亮几秒后熄灭 (5s)
		ucled |= 0x04;
	}
	else 
	{
		ucled &= ~0x04;
	}
//SysTick_Handler函数
{
	cnt++;
	if (cnt == 5000) 
	{
		flag = 0;
	}
}

/***led流水灯***/
//led处理程序
	if (led_flag) 
	{  //led流水灯 (0.2s)  5-8
		ucled |= ( 0x10 << led);
	}
	else
	{
		ucled &= ~( 0x10 << led);
	}


//SysTick_Handler函数
{
	led_cnt++;
	if (led_cnt == 200) 
	{   //0.2s
		led1_cnt = 0;
		if (led == 3) 
		{
			led = 0;
		}
		else 
		{
			led++;
		}
	}
}


void Led_Proc(void)
{
	if((uwTick -  uwTick_Led_Set_Point)<200)	return;
		uwTick_Led_Set_Point = uwTick;

	LED_Disp(ucLed);
}

二.按键部分 


uint8_t Key_Scan(void)
{
	uint8_t unKey_Val = 0;
	
	if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0) == GPIO_PIN_RESET)
		unKey_Val = 1;

	if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1) == GPIO_PIN_RESET)
		unKey_Val = 2;

	if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == GPIO_PIN_RESET)
		unKey_Val = 3;
	
	if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == GPIO_PIN_R
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

放牛的守护神_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值