直接操作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++;
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章