欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

stm32实现4个LED灯的点亮

程序员文章站 2022-06-04 08:51:52
...
#include "math.h"
int main(void)
{
	//亮第一个灯
 	RCC->AHB1ENR |= (1<<2)|(1<<5);
	GPIOC->MODER &= ~((0x3<<0)|(0x3<<12)|(0x3<<20)|(0x3<<18));
	GPIOC->MODER |= (0x1<<0);
	GPIOC->OTYPER &= ~(0x1<<0);
	GPIOC->OSPEEDR &= ~(0x3<<0);
	GPIOC->OSPEEDR |=(0x2<<0);
	GPIOC->PUPDR |= ~(0x3<<0);
	//亮第二三四个灯
	//RCC->AHB1ENR |= (1<<5);
	GPIOF->MODER &= ~((0x3<<20)|(0x3<<18)|(0x3<<12));
	GPIOF->MODER |= ((0x1<<20)|(0x1<<18)|(0x1<<12));
	GPIOF->OTYPER &= ~((0x1<<20)|(0x1<<18)|(0x1<<12));
	GPIOF->OSPEEDR &= ~((0x3<<20)|(0x3<<18)|(0x3<<12));
	GPIOF->OSPEEDR |=((0x2<<20)|(0x2<<18)|(0x2<<12));
	GPIOF->PUPDR |= ~((0x3<<20)|(0x3<<18)|(0x3<<12));
	//亮第三个灯
	//RCC->AHB1ENR |= (1<<5);
	//GPIOF->MODER &= ~(0x3<<18);
	//GPIOF->MODER |= (0x1<<18);
	//GPIOF->OTYPER &= ~(0x1<<18);
	//GPIOF->OSPEEDR &= ~(0x3<<18);
	//GPIOF->OSPEEDR |=(0x2<<18);
	//GPIOF->PUPDR |= ~(0x3<<18);
	//电亮第四个灯
	//RCC->AHB1ENR |= (1<<5);
	//GPIOF->MODER &= ~(0x3<<12);//给使用的两位清0
	//GPIOF->MODER |= (0x1<<12);
	//GPIOF->OTYPER &= ~(0x1<<12);
	//GPIOF->OSPEEDR &= ~(0x3<<12);
	//GPIOF->OSPEEDR |=(0x2<<12);
	//GPIOF->PUPDR |= ~(0x3<<12);     
	//GPIOC->ODR |= (0x1<<0);
  while (1)
  {
		
  }
}
相关标签: arm