大家好,我用PE5、PE6作为按键输入,分别控制PG13、PG14的端口的发光二极管,想实现按一次翻转一次,一直未成功,工程见附件,程序如下:(其中预定义LED0、LED1分别为PGout(13)、PGout(14))
#include "LED.h"
#include "sys.h"
#include "delay.h"
#include "stm32f10x_gpio.h"
int main()
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOG,&GPIO_InitStruct); //??????PG13??PG14????????
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOE,&GPIO_InitStruct); //??????PE5??PE6????????
while(1)
{
if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_5)==0)
{
// delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_5)==0)
{
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_5)==1)
{
LED0=~LED0; //????:????°???????????°???????????????·
}
}
}
if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_6)==0)
{
// delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_6)==0)
{
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_6)==1)
{
LED1=~LED1; //????:????°???????????°???????????????·
}
}
}
}
}
|