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);
//对按键