stm32f4平台使用寄存器编程方法点亮一个LED灯。keil 5 下编码。
初学者参考代码。
单片机源程序如下:
- /*******************************************************************************
- * 实 验 名 : 使用寄存器点亮一个LED
- * 实验说明 : 操作寄存器控制D1指示灯闪烁
- * 连接方式 :
- * 注 意 :
- *******************************************************************************/
- #include "stm32f4xx.h"
- typedef unsigned int u32; //类型重定义 unsigned int -- u32。4个字节
- void SystemInit()
- {
-
- }
- //延时函数,通过while循环占用CPU,达到延时功能
- void delay(u32 i)//32位的变量
- {
- while(i--);
- }
- int main()
- {
- RCC_AHB1ENR |= 1<<5;//或运算置一,左移5位。
- GPIOF_MODER = (1<<(2*9));//配置输出模式,2位一个管脚,设置为通用输出
- while(1)
- {
- GPIOF_BSRR=(1<<(16+9));//高位复位0,输出低电平亮
- delay(0xFFFFF);//延时这么多时间
-
- GPIOF_BSRR=(1<<(9));//低位置一,输出高电平灭
- delay(0xFFFFF); //
- }
- }
复制代码
所有资料51hei提供下载:
使用寄存器点亮一个LED.rar
(113.68 KB, 下载次数: 19)
|