实现LED1/LED2/LED3三盏灯c语言点亮

led.h:

#ifndef __LED_H__
#define __LED_H__ 
#define RCC (*(volatile unsigned int*)0x50000A28)
typedef struct{
	volatile unsigned int MODER;
	volatile unsigned int OTYPER;
	volatile unsigned int OSPEEDR;
	volatile unsigned int PUPDR;
	volatile unsigned int IDR;
	volatile unsigned int ODR;
}gpio_t;
#define GPIOE ((gpio_t*)0x50006000)
#define GPIOF ((gpio_t*)0x50007000)

int LD1_reset();

int LED1_on();
int LED1_off();



#endif

led.c:

#include "led.h"

int LD1_reset()
{
	RCC=RCC|(0x1 << 4);
//pe10
	GPIOE->MODER=GPIOE->MODER & (~(0x3 << 20));
	GPIOE->MODER=GPIOE->MODER | (0x1 << 20);

	GPIOE->OTYPER=GPIOE->OTYPER & (~(0x1 << 10));

	GPIOE->OSPEEDR=GPIOE->OSPEEDR & (~(0x3 << 20));

	GPIOE->PUPDR=GPIOE->PUPDR & (~(0x3 << 20));


//pe8
	GPIOE->MODER=GPIOE->MODER & (~(0x3 << 16));
	GPIOE->MODER=GPIOE->MODER | (0x1 << 16);

	GPIOE->OTYPER=GPIOE->OTYPER & (~(0x1 << 8));

	GPIOE->OSPEEDR=GPIOE->OSPEEDR & (~(0x3 << 16));

	GPIOE->PUPDR=GPIOE->PUPDR & (~(0x3 << 16));
//pf10
	RCC=RCC|(0x1 << 5);
	GPIOF->MODER=GPIOF->MODER & (~(0x3 << 20));
	GPIOF->MODER=GPIOF->MODER | (0x1 << 20);

	GPIOF->OTYPER=GPIOF->OTYPER & (~(0x1 << 10));

	GPIOF->OSPEEDR=GPIOF->OSPEEDR & (~(0x3 << 20));

	GPIOF->PUPDR=GPIOF->PUPDR & (~(0x3 << 20));
	return 0;
}
int LED1_on()
{
	GPIOE->ODR=GPIOE->ODR | (0x1 << 10);
	GPIOE->ODR=GPIOE->ODR | (0x1 << 8);
	GPIOF->ODR=GPIOF->ODR | (0x1 << 10);
	return 0;

}
int LED1_off()
{
	GPIOE->ODR=GPIOE->ODR & (~(0x1 << 10));
	GPIOE->ODR=GPIOE->ODR & (~(0x1 << 8));
	GPIOF->ODR=GPIOF->ODR & (~(0x1 << 10));
	return 0;
}

main.c:

#include "led.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
	int i,j;
	for(i = 0; i < ms;i++)
		for (j = 0; j < 1800; j++);
}


int main()
{
	LD1_reset();// LED1灯初始化
	while(1)
	{
		LED1_on();
		delay_ms(500);
		LED1_off();
		delay_ms(500);
	
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值