首页 > 其他 > 详细

LED操作

时间:2016-04-18 10:12:49      阅读:189      评论:0      收藏:0      [点我收藏+]

灯上拉技术分享

GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed =GPIO_Speed_Level_3;
GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_SetBits(GPIOB, GPIO_Pin_0);

取反:

#define RE_LED1 GPIO_WriteBit(GPIOB, GPIO_Pin_1,(BitAction)((1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_1))));

置为0或1

#define LED1OFF {GPIOB->BSRR = GPIO_Pin_0;} //B0 = 1
#define LED1ON {GPIOB->BRR = GPIO_Pin_0;} //B0 = 0

/*****************************************************************************
可置任意管脚为 1
******************************************************************************/
void LED_Close(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin)
{
GPIO_SetBits(GPIOx, GPIO_Pin);

}
/*****************************************************************************
可置任意管脚为 0
******************************************************************************/
void LED_Open(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin)
{
GPIO_ResetBits(GPIOx, GPIO_Pin);
}

LED操作

原文:http://www.cnblogs.com/luckytimor/p/5403213.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!