init: 项目初始化,添加基础文件
This commit is contained in:
96
循迹/Hardware/LED.c
Normal file
96
循迹/Hardware/LED.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "stm32f10x.h" // Device header
|
||||
|
||||
/**
|
||||
* 函 数:LED初始化
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED_Init(void)
|
||||
{
|
||||
/*开启时钟*/
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //开启GPIOA的时钟
|
||||
|
||||
/*GPIO初始化*/
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure); //将PA1和PA2引脚初始化为推挽输出
|
||||
|
||||
/*设置GPIO初始化后的默认电平*/
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1 | GPIO_Pin_2); //设置PA1和PA2引脚为高电平
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED1开启
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED1_ON(void)
|
||||
{
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_1); //设置PA1引脚为低电平
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED1关闭
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED1_OFF(void)
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1); //设置PA1引脚为高电平
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED1状态翻转
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED1_Turn(void)
|
||||
{
|
||||
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_1) == 0) //获取输出寄存器的状态,如果当前引脚输出低电平
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1); //则设置PA1引脚为高电平
|
||||
}
|
||||
else //否则,即当前引脚输出高电平
|
||||
{
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_1); //则设置PA1引脚为低电平
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED2开启
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED2_ON(void)
|
||||
{
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_2); //设置PA2引脚为低电平
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED2关闭
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED2_OFF(void)
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_2); //设置PA2引脚为高电平
|
||||
}
|
||||
|
||||
/**
|
||||
* 函 数:LED2状态翻转
|
||||
* 参 数:无
|
||||
* 返 回 值:无
|
||||
*/
|
||||
void LED2_Turn(void)
|
||||
{
|
||||
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_2) == 0) //获取输出寄存器的状态,如果当前引脚输出低电平
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_2); //则设置PA2引脚为高电平
|
||||
}
|
||||
else //否则,即当前引脚输出高电平
|
||||
{
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_2); //则设置PA2引脚为低电平
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user