#include"led.h"
//延时函数
void delay_ms(int ms)
{
int i,j;
for(i = 0; i < ms;i++)
for (j = 0; j < 1800; j++);
}
//设置初始化
void all_led_init()
{
RCC |=(0b10010);
//风扇
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);
//蜂鸣器响
GPIOE->odr &=(~(0X1<<9));
GPIOB->odr |=(0X1<<6);
delay_ms(5000);
}
#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;
//定义GPIOE和GPIOF
#define GPIOE ((gpio_t *)0X50006000)
#define GPIOB ((gpio_t *)0X50003000)
#define RCC (*(volatile unsigned int *)0X50000A28)
void delay_ms(int ms);
void all_led_init();
void all_led_flash();
#endif