ARMday5

风扇蜂鸣器

1.main.c

#include"led.h"
//封装延时函数
void delay(int ms)
{
    int i,j;
    for(i=0;i<ms;i++)
    {
        for(j=0;j<2000;j++)
        {}

    }
}
int main()
{
    //外设初始化
    all_pplout_init();
    while(1)
    {
        BUZZER_ON();
        delay(2000);
        BUZZER_OFF();
        delay(2000);
        MOTOR_ON();
        delay(2000);
        MOTOR_OFF();
        delay(2000);
        FAN_ON();
        delay(2000);
        FAN_OFF();
        delay(2000);
    }
    return 0;
}

2.led.c

#include "led.h"

void all_pplout_init()//led灯的初始化
{
    //GPIOE/GPIOF时钟使能
   RCC  |= (0x3<<4);
   RCC  |= (0x1<<2);
    //PE10设置为输出
    GPIOE.MODER &= (~(0X3<<12));
    GPIOE.MODER |= (0X1<<12);
    //PF10设置为输出
    GPIOE.MODER &= (~(0X3<<18));
    GPIOE.MODER |= (0X1<<18);
    //PE8设置为输出
    GPIOE.MODER &= (~(0X3<<12));
    GPIOE.MODER |= (0X1<<12);
    //PE10设置为推挽输出
    GPIOB.OTYPER &= (~(0X1<<6));
    //PF10设置为推挽输出
    GPIOE.OTYPER &= (~(0X1<<9));
    //PE8设置为推挽输出
    GPIOF.OTYPER &= (~(0X1<<6));
    //PE10设置为低速输出
    GPIOB.OSPEEDR &= (~(0X3<<12));
    //PF10设置为低速输出
    GPIOE.OSPEEDR &= (~(0X3<<18));
    //PE8设置为低速输出
    GPIOF.OSPEEDR &= (~(0X3<<12));
    //PE10无上拉下拉电阻
    GPIOB.OPUPDR &= (~(0X3<<12));
    //PF10无上拉下拉电阻
    GPIOE.OPUPDR &= (~(0X3<<18));
    //PE8无上拉下拉电阻
    GPIOF.OPUPDR &= (~(0X3<<12));

    //三盏灯默认输出低电平
    GPIOB.ODR &= (~(0X1<<6));
    GPIOE.ODR &= (~(0X1<<9));
    GPIOF.ODR &= (~(0X1<<6));
}

//led1亮
void BUZZER_ON()
{
    GPIOB.ODR |= (0X1<<6);
}
//led2亮
void MOTOR_ON()
{
   GPIOE.ODR |= (0X1<<9);
}
//led1亮
void FAN_ON()
{
    GPIOF.ODR |= (0X1<<6);
}

//LED1灭
void BUZZER_OFF()
{
     GPIOB.ODR &= (~(0X1<<6));
}
//LED2灭
void MOTOR_OFF()
{
     GPIOE.ODR &= (~(0X1<<9));
}
//LED3灭
void FAN_OFF()
{
     GPIOF.ODR &= (~(0X1<<6));
}    

3.led.h

#ifndef __LED_H__
#define __LED_H__
typedef struct
{
    unsigned int MODER;
    unsigned int OTYPER;
    unsigned int OSPEEDR;
    unsigned int OPUPDR;
    unsigned int IDR;
    unsigned int ODR;
}gpio_t;

#define RCC (*(unsigned int *)0X50000A28)
#define GPIOB (*(gpio_t *)0X50003000)
#define GPIOE (*(gpio_t *)0X50006000)
#define GPIOF (*(gpio_t *)0X50007000)

void all_pplout_init();
void BUZZER_ON();
void FAN_ON();
void MOTOR_ON();
void BUZZER_OFF();
void FAN_OFF();
void MOTOR_OFF();

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值