高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-10-25
|
#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_key.h"
#define GPIOE_ODR_Addr (GPIOE_BASE+0x0C)
#define PEout(n) *(unsigned int*)((GPIOE_ODR_Addr & 0xF0000000)+0x02000000+((GPIOE_ODR_Addr & 0x00FFFFFF)<<5)+(n<<2))
#define GPIOA_IDR_Addr (GPIOA_BASE+0x08)
#define PAin(n) *(unsigned int*)((GPIOA_IDR_Addr & 0xF0000000)+0x02000000+((GPIOA_IDR_Addr & 0x00FFFFFF)<<5)+(n<<2))
void Delay(uint32_t count)
{
for( ; count!=0; count--);
}
int main(void)
{
//来到这里的时候,系统的时钟已经被配置成72M。
LED_GPIO_Config();
KEY_GPIO_Config();
#if 0
while(1)
{
//GPIO_SetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
//LED_G(OFF);
PEout(0) = 1;
Delay(0xFFFFF);
//GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
//LED_G(ON);
PEout(0) = 0;
Delay(0xFFFFF);
}
#else
while(1)
{
if( PAin(0) == KEY_ON )
{
while(PAin(0) == KEY_ON); //KEY_0
LED_G_TOGGLE; //绿灯
}
if( PAin(1) == KEY_ON )
{
while(PAin(1) == KEY_ON); //KEY_1
LED_R_TOGGLE; //红灯
}
}
#endif
}
为什么按键不能按一个就控制一个灯,而需要按了KEY_0,黄灯灭,需要再按KEY_1,才能按KEY_0,让黄灯亮
|
|