|
最近用keil MDK完成了一个关于用STM32驱动8个LED灯循环点亮的项目由于是初学菜鸟,想记录一下自己的学习历程,还请大家多多指教- #include "stm32f10x.h"
- void Delay(unsigned int count) //延时函数
- {
- unsigned int i;
- for(;count!=0;count--)
- {
- i=5000;
- while(i--);
- }
- }
- void GPIO_LEDInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; //初始化变量
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能LED的GPIOC时钟
- // 配置 LED灯使用的GPIO引脚
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //推挽输出
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
- GPIO_Init(GPIOC,&GPIO_InitStructure); //对LED的GPIOC口初始化
- GPIO_SetBits(GPIOC,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7); //关闭所有的LED
- }
- int main()
- {
- GPIO_LEDInit(); //初始化LED引脚
- while(1)
- {
- GPIO_SetBits(GPIOC,GPIO_Pin_7); //关7
- GPIO_ResetBits(GPIOC,GPIO_Pin_0); //开0
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_0); //关0
- GPIO_ResetBits(GPIOC,GPIO_Pin_1); //开1
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_1); //关1
- GPIO_ResetBits(GPIOC,GPIO_Pin_2); //开2
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_2); //关2
- GPIO_ResetBits(GPIOC,GPIO_Pin_3); //开3
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_3); //关3
- GPIO_ResetBits(GPIOC,GPIO_Pin_4); //开4
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_4); //关4
- GPIO_ResetBits(GPIOC,GPIO_Pin_5); //开5
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_5); //关5
- GPIO_ResetBits(GPIOC,GPIO_Pin_6); //开6
- Delay(300); //延时
- GPIO_SetBits(GPIOC,GPIO_Pin_6); //关6
- GPIO_ResetBits(GPIOC,GPIO_Pin_7); //开7
- Delay(300); //延时
- }
- }
复制代码 |
-
51hei.png
(162.62 KB, 下载次数: 70)
proteus搭的仿真电路
评分
-
查看全部评分
|