ARM day5作业

使用C语音,控制开发板蜂鸣器和风扇

ARM day5作业_第1张图片
led.h

#ifndef __LED_H__
#define __LED_H__

//定义寄存器组织结构体
typedef struct{
    unsigned int moder;
    unsigned int otyper;
    unsigned int ospeedr;
    unsigned int pupdr;
    unsigned int idr;
    unsigned int odr;
}gpio_t;
//定义GPIOB和GPIOE
#define GPIOB ((gpio_t *)0X50003000)
#define GPIOE ((gpio_t *)0X50006000)
#define RCC (*(volatile unsigned int *)0X50000A28)
void delay_ms(int ms);
 void all_led_init();
 void  all_led_flash();
#endif

led.c

#include"led.h"
//延时函数
void delay_ms(int ms)
{
 int i,j;
 for(i = 0; i < ms;i++)
  for (j = 0; j < 1800; j++);
}
//led灯设置初始化 
 void all_led_init()
 {
    RCC |=(0x9<<1);
    //风扇
    GPIOE->moder &= (~(0X3<<18));
    GPIOE->moder |= (0X1<<18);
    GPIOE->otyper &=(~(0X1<<9));
    GPIOE->ospeedr &= (~(0X3<<18));
    GPIOE->pupdr &= (~(0X3<<18));
     //蜂鸣器
    GPIOB->moder &= (~(0X3<<12));
    GPIOB->moder |= (0X1<<12);
    GPIOB->otyper &=(~(0X1<<6));
    GPIOB->ospeedr &= (~(0X3<<12));
    GPIOB->pupdr &= (~(0X3<<12));
 }
void  all_led_flash()
{
	//风扇转五秒
    GPIOE->odr |=(0X1<<9);
    GPIOB->odr &=(~(0X1<<6));
    delay_ms(5000);

	//蜂鸣器响五秒
    GPIOB->odr |=(0X1<<6);
    GPIOE->odr &=(~(0X1<<9));
    delay_ms(5000);
} 

main.c

#include "led.h"
int main()
{
	all_led_init();
	while(1)
	{
		all_led_flash();
	}
	return 0;
}

你可能感兴趣的:(c#,开发语言,vim,编辑器,linux)