ARM-2

ARM-2

码农世界 2024-05-24 后端 62 次浏览 0个评论

 c语言实现三盏灯的控制

#ifndef __LED_H__
#define __LED_H__
typedef struct
{
	volatile unsigned int MODER;
	volatile unsigned int OTYPER;
	volatile unsigned int OSPEEDER;
	volatile unsigned int PUPDR;
	volatile unsigned int IDR;
	volatile unsigned int ODR;
	volatile unsigned int BSRR;
}gpio_t;
#define GPIOE ((gpio_t*)0x50006000)
#define GPIOF ((gpio_t*)0x50007000)
void led1_init();
void led2_init();
void led3_init();
void led1_ctl(int flag);
void led2_ctl(int flag);
void led3_ctl(int flag);
#endif

 

#include "led.h"
void delay_ms(int ms)
{
	int i,j;
	for(i=0;i 
#include "led.h"
void led1_init()
{
	
	GPIOE->MODER &= (~(0x3<<20));
	GPIOE->MODER |= (0x1<<20);
	GPIOE->OTYPER &= (~(0x1<<10));
	GPIOE->OSPEEDER &= (~(0x3<<20));
	GPIOE->PUPDR &= (~(0x3<<20));
}
void led2_init()
{
	GPIOF->MODER &= (~(0x3<<20));
	GPIOF->MODER |= (0x1<<20);
	GPIOF->OTYPER &= (~(0x1<<10));
	GPIOF->OSPEEDER &= (~(0x3<<20));
	GPIOF->PUPDR &= (~(0x3<<20));
}
void led3_init()
{
	GPIOE->MODER &= (~(0x3<<16));
	GPIOE->MODER |= (0x1<<16);
	GPIOE->OTYPER &= (~(0x1<<8));
	GPIOE->OSPEEDER &= (~(0x3<<16));
	GPIOE->PUPDR &= (~(0x3<<16));
}
//LED1控制
void led1_ctl(int flag)
{
    if(flag==1)
    {
        GPIOE->ODR |= (0x1<<10);
    }
    else if(flag==0)
    {
        GPIOE->ODR &= (~(0x1<<10));
    }
}
//LED2控制
void led2_ctl(int flag)
{
    if(flag==1)
    {
        GPIOF->ODR |= (0x1<<10);
    }
    else if(flag==0)
    {
        GPIOF->ODR &= (~(0x1<<10));
    }
}
//LED3控制
void led3_ctl(int flag)
{
    if(flag==1)
    {
        GPIOE->ODR |= (0x1<<8);
    }
    else if(flag==0)
    {
        GPIOE->ODR &= (~(0x1<<8));
    }
}

实验效果

ARM-2

转载请注明来自码农世界,本文标题:《ARM-2》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,62人围观)参与讨论

还没有评论,来说两句吧...

Top