这里的主要实验是motor电机实验
motor中用到的pwm引脚是pb8,时钟是TIM10的通道1,这些基于
F:\BaiduNetdiskDownload\探索者F4资料盘(A盘)《STM32F4xx中文参考手册》
F:\BaiduNetdiskDownload\探索者F4资料盘(A盘)《【英文】STM32F207数据手册(Rev9)》
1. led.h
#include"stm32f2xx.h"
#ifndef __LED_H
#define __LED_H
void LED_Init(void);
//void Delay(vu32 nCount);
void CTL_LED(u8 LED_NUM, u8 OFF_ON);
#endif
led.c
#include"led.h"
#include"stm32f2xx.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;
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(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD, GPIO_Pin_11|GPIO_Pin_12);
}
/*
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
*/
#if 1
void CTL_LED(u8 LED_NUM, u8 OFF_ON)
{
switch(LED_NUM)
{
case 0:
if(OFF_ON == 1)
{
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
}
else
{
GPIO_SetBits(GPIOD, GPIO_Pin_11);
}
break;
case 1:
if(OFF_ON == 1)
{
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
}
else
{
GPIO_SetBits(GPIOD, GPIO_Pin_12);
}
break;
default:
//GPIO_ResetBits(GPIOF,GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
GPIO_ResetBits(GPIOD,GPIO_Pin_11|GPIO_Pin_12);
break;
}
}
#endif
usart.h
#include"stm32f2xx.h"
#include "stm32f2xx_conf.h"
#ifndef __USART_H
#define __USART_H
void uart_init(u32 bound);
void USART_Configuration(void);
void USART_NVIC_Config(void);
#endif
usart.c
#include"stm32f2xx.h"
#include