直接操作STM32F407寄存器之跑马灯

// 驱动DCM501的四盏灯为跑马灯
// Designer: Lv Shiqi

#include "stm32f4xx.h"

#define	GPIO_Pin_6	0x0040
#define GPIO_Pin_7	0x0080
#define GPIO_Pin_8	0x0100
#define GPIO_Pin_9	0x0200
#define	light_num	4

void light_init()
{
	// 开启F端口时钟
	RCC->AHB1ENR	|= 0x00000020;
	GPIOF->MODER	|= 0x00055000;
	
	GPIOF->OTYPER	|= 0x000003C0;
	
	GPIOF->OSPEEDR	|= 0x00055000;
	// 不拉高不拉低
	GPIOF->PUPDR	&= 0xFFF00FFF;
	
	GPIOF->BSRRL	|= GPIO_Pin_6;
	GPIOF->BSRRL	|= GPIO_Pin_7;
	GPIOF->BSRRL	|= GPIO_Pin_8;
	GPIOF->BSRRL	|= GPIO_Pin_9;
}

void paomadeng(u16 i)
{
	u32	delay_time	= 0xFFFFF;
	while(delay_time--){
		GPIOF->BSRRH	= i;
	}
	GPIOF->BSRRL	= i;
}

int main()
{
	int	num	= 0;
	u16	light[light_num]	= {GPIO_Pin_6, GPIO_Pin_7,GPIO_Pin_8,GPIO_Pin_9};
	
	light_init();
	
	while(1){
		if(num==light_num)
			num	= 0;
		paomadeng(light[num]);
		num++;
	}
}

你可能感兴趣的:(STM32F407)