野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12434|回复: 4

为什么我的按键实验,led灯一直闪,按键没反应?

[复制链接]
发表于 2016-7-22 13:45:43 | 显示全部楼层 |阅读模式
用的是ISO_V2板子
main.c
int main(void)
{       
        /* config the led */
        LED_GPIO_Config();
        LED1_ON;

        /*config key*/
        Key_GPIO_Config();       
       
        while(1)                           
        {          
                if( Key_Scan(GPIOA,GPIO_Pin_0) == KEY_ON  )
                {
                        /*LED1·′×a*/
                        LED1_TOGGLE;
                }   
        }
}

bsp_key.c
void Key_GPIO_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
//        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
       
        GPIO_Init(GPIOA, &GPIO_InitStructure);
}


void Delay(__IO uint32_t nCount)         //¼òμ¥μÄÑóê±oˉêy
{
        for(; nCount != 0; nCount--);
}

uint8_t Key_Scan(GPIO_TypeDef* GPIOx,u16 GPIO_Pin)
{                       

        if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )
        {          
               
                Delay(10000);               
                if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )  
                {         
               
                     while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON);   
                        return         KEY_ON;         
                }
                else
                        return KEY_OFF;
        }
        else
                return KEY_OFF;
}


回复

使用道具 举报

发表于 2016-7-22 13:50:53 | 显示全部楼层
ISO V2板子一个按键是高电平有效,一个按键是低电平有效,不一样的,注意看原理图,或者直接用例程
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-22 14:00:18 | 显示全部楼层
找到原因了  引脚输错了  
回复 支持 反对

使用道具 举报

发表于 2016-7-22 17:56:15 | 显示全部楼层
注意看程序的引脚
回复 支持 反对

使用道具 举报

发表于 2016-7-23 09:03:25 | 显示全部楼层
醉了 ,,,,基本的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-23 03:13 , Processed in 0.038527 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表