
在解决了pack问题后,我建了第一个工程,写了个呼吸灯。新建工程我参照的下面这个帖子,写的很详细,很好。https://www.stmcu.org.cn/module/ ... &highlight=f411 不多说,上代码: /***************bsp_led.c**********************/ #include "bsp_led.h" void LED_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);//??LED?IO?? GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; GPIO_Init(GPIOA,&GPIO_InitStructure); } /*********************************************/ /***************bsp_led.h**********************/ #ifndef _BSP_LED_H_ #define _BSP_LED_H_ #include "stm32f4xx.h" #define ON 1 #define OFF 0 #define LED(a) if(a) GPIO_SetBits(GPIOA,GPIO_Pin_5); else GPIO_ResetBits(GPIOA,GPIO_Pin_5) void LED_GPIO_Config(void); #endif /*********************************************/ main.c /***************main.c**********************/ #include "stm32f4xx.h" #include "bsp_led.h" #define N 1 void Delay(__IO uint32_t nCount) { while(nCount--){} } int main(void) { const long num=4000; long i=1; char flag=0; LED_GPIO_Config();// LED IO --PA5 while (1) { LED(ON); Delay((num-i)*N); LED(OFF); Delay(i*N); if(flag==0) { i++; } else if(flag==1) { i--; } if(i>=(num-1)) flag=1; else if(i<=1) flag=0; } } /*********************************************/ |
å¼å¸ç¯20150804.rar
下载1.37 MB, 下载次数: 54
å¼å¸ç¯
失望了吧,第一个工程一般都是点个灯嘛,就像hello world一样
周期性改变延时的时间,就等同于周期性改变占空比
所以没有想象中那么高大上
只要能点亮一个led就行
还可以用pwm,定时器中断改占空比
和点亮一个led本质上没有区别
..点亮LED灯是GPIO操作啊~呼吸灯重点是PWM吧。。
用延时函数也可以达到同样的效果