STM32中各部分配置代码

1.led.c的配置


#include "stm32f10x.h"
#include "led.h"

void Init_LED(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;
  GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
   GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
    
    GPIO_Init(GPIOB,&GPIO_InitStruct);
    GPIO_Init(GPIOE,&GPIO_InitStruct);
    
    GPIO_SetBits(GPIOB,GPIO_Pin_5);
    GPIO_SetBits(GPIOE,GPIO_Pin_5);    
}
2.beep.c的配置


#include "stm32f10x.h"
#include "beep.h"

void Init_BEEP(void)
{
    GPIO_InitTypeDef GPIO_InitS;  
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
    GPIO_InitS.GPIO_Mode=GPIO_Mode_AF_PP;
    GPIO_InitS.GPIO_Pin=GPIO_Pin_8;
    GPIO_InitS.GPIO_Speed=GPIO_Speed_50MHz;

    GPIO_Init(GPIOB,&GPIO_InitS);
    GPIO_ResetBits(GPIOB,GPIO_Pin_8);
}
3.key.c的配置


#include "stm32f10x.h"

#include "key.h"

u8 KEY_Status(u8 mode)
{
    static u8 key_flag = 1;
    if(mode)
        key_flag = 1;
    if(key_flag&&(KEY0==0))
    {
        DELAY_MS;
        key_flag = 0;
        if(KEY0 == 0)
        {
            GPIO_ResetBits(GPIOB,GPIO_Pin_8);
          return 1;    
        }
    }
    return 0;
}
void Init_KEY(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE,ENABLE);

    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_3|GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 
     GPIO_Init(GPIOE, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;  
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}

4.wwdg.c的配置

#include "stm32f10x.h"
#include "wwdg.h"

void Init_IWDG(uint8_t pre,uint16_t Rel)
{

    IWDG_WriteAccessCmd(DISABLE);//È¡Ïûд±£»¤
    IWDG_SetPrescaler(pre);//ÉèÖÃÔ¤·ÖƵ
    IWDG_SetReload(Rel);//ÖØ×°ÔØÖµ
    IWDG_ReloadCounter();//ι¹·
    IWDG_Enable();//ʹÄÜ¿´ÃŹ·
}
void wwdg_feed(void)
{
  IWDG_ReloadCounter();     //ι¹·
}
5.delay.c的配置

#include "delay.h"


void delay_count(uint32_t times)
{
  uint32_t temp = 0;                                            
  
  while(times --)
    {                                             
    temp = 1000;                                                
    while(temp --);                                            
  }
}

delay.h的配置

#ifndef __DELAY_H
#define __DELAY_H

#include "stm32f10x.h"

#define DELAY delay_count(10000)
#define DELAY_MS delay_count(1000)
#define DELAY_S delay_count(0)

void delay_count(uint32_t times);

#endif

各部分头文件(.h)的配置


#ifndef __LED_H //只需要把此处的名字改成对相应的即可
#define __LED_H

void Init_LED(void);  //这里也需要改哦


#endif


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值