STM32F207下的实验(2)

这篇博客详细介绍了在STM32F207芯片上进行的一系列基本实验,包括蜂鸣器Beep、CAN通信、PWM输出、DMA数据传输、LED灯控制、USART串口通信、按键控制、外部中断和定时器实验。通过这些实验,可以深入理解STM32F207的多种功能及其在实际应用中的操作。
摘要由CSDN通过智能技术生成

F盘中workspace文件下的是配合STM32F207做的一些基本实验,其中Template是模板文件夹(也叫固件库)
包括
蜂鸣器Beep实验、
Can通信实验、
Pwm(占空比可变的脉冲波形)输出实验、
DMA传输数据实验、
Led灯点亮实验,
usart串口通信实验(通过串口线连接pc与开发板,在串口调试助手端输入指定指令,可控制开发板上的引脚)、
KEYS按键控制实验(开发板上有一些开关,通过控制开关,可控制led亮灭等实验)、
EXIT外部中断实验、
Icapture捕获实验(捕获按下按键的操作,可用来记录两次按键中间的时间间隔)、

TIME计时器实验

1. beep

beep.h

#include"stm32f2xx.h"

#ifndef __BEEP_H

#define __BEEP_H

void BEEP_Init(void);

void BEEP_on(void);

void BEEP_OFF(void);

void Delay(vu32 nCount);
	
#endif

beep.c

#include"beep.h"
#include"stm32f2xx.h"

void BEEP_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
		
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //GPIO_OType_PP表示推挽方式输出,GPIO_OType_OD表示开漏
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_Init(GPIOF,&GPIO_InitStructure);
	GPIO_SetBits(GPIOF,GPIO_Pin_6);
}

void BEEP_on(void)
{
  GPIOF-> BSRRH = GPIO_Pin_6; //BSRRH和BSRRL代表BSRR的高16位和低16位
}

void BEEP_OFF(void)
{
  GPIOF-> BSRRL = GPIO_Pin_6;
}

void Delay(vu32 nCount)
{
  for(; nCount != 0; nCount--);
}

main.c

#include"beep.h"
#include"stm32f2xx.h"

u8 count=0;

int main()
{
    BEEP_Init();
    //BEEP_on();
    //Delay(0x800000);

	
	while(1)
	{
	    BEEP_on();
	    Delay(0x800000);
	    BEEP_OFF();
	    Delay(0x800000);
	}
}

2. LED

led.h

#include"stm32f2xx.h"
#ifndef __LED_H

#define __LED_H

void LED_Init(void);

void Delay(vu32 nCount);

void Turn_On_LED(u8 LED_NUM);
	
#endif

led.c

#include"led.h"
#include"stm32f2xx.h"

void LED_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
		
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //GPIO_OType_PP表示推挽方式输出,GPIO_OType_OD表示开漏
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_Init(GPIOF, &GPIO_InitStructure);
	GPIO_SetBits(GPIOF, GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
}

void Delay(vu32 nCount)
{
  for(; nCount != 0; nCount--);
}

void Turn_On_LED(u8 LED_NUM)
{
  switch(LED_NUM)
	{
	  case 0:
			GPIO_ResetBits(GPIOF, GPIO_Pin_7);
		    break;
		case 1:
			GPIO_ResetBits(GPIOF, GPIO_Pin_8);
		    break;
		case 2:
			GPIO_ResetBits(GPIOF, GPIO_Pin_9);
		     break;
		case 3:
			GPIO_ResetBits(GPIOF, GPIO_Pin_10);
		    break;
		default:
			GPIO_ResetBits(GPIOF, GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
		    break;
	}
}

main.c

#include"led.h"
#include"stm32f2xx.h"

u8 count=0;

int main()
{
    LED_Init();
    while(1)
    {
		GPIO_SetBits(GPIOF,GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
		Turn_On_LED(count%4);
		count++;
		Delay(0x2FFFFF);
        GPIO_ResetBits(GPIOF, GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
    }
}

3. keys

key.h

#include"stm32f2xx.h"
#ifndef __KEY_H

#define __KEY_H

void KEY_Init(void);

void LED_Init(void);

	
#endif

key.c

#include"key.h"
#include"stm32f2xx.h"

#define KEY1  GPIO_Pin_5
#define KEY2  GPIO_Pin_11
#define KEY3  GPIO_Pin_13
#define KEY4  GPIO_Pin_0

#define KEY1_press 1
#define KEY2_press 2
#define KEY3_press 3
#define KEY4_press 4

void KEY_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	
	//首先对按键1进行初始化,按键1是A型的
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
		
	GPIO_InitStructure.GPIO_Pin = KEY1;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; 
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	
	//对按键2进行初始化,按键2是F型的
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
		
	GPIO_InitStructure.GPIO_Pin = KEY2;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; 
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOF,&GPIO_InitStructure);
	
	//对按键
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值