新闻中心

EEPW首页>嵌入式系统>设计应用> GPIO输入----检测按键(EasyARM2131)

GPIO输入----检测按键(EasyARM2131)

作者: 时间:2016-11-10 来源:网络 收藏
/****************************************Copyright (c)*****************************

**--------------File Info----------------------------------------------------------
** File name:main.c
** Last modified Date: 2011-04-09
** Last Version:1.0
** Descriptions:The main() function example template
**
**---------------------------------------------------------------------------------
** Created by:lxliu
** Created date:2011-04-09
** Version:1.0
** Descriptions:The original version
************************************************************************************/
#include "config.h"

本文引用地址://m.amcfsurvey.com/article/201611/317407.htm

const uint32 BEEP = (1<<7);
const uint32 KEY1 = (1<<16);

/*************************************************************************
** 函数名称:main()
** 函数功能:GPIO输入测试
检测按键KEY1:KEY1按下,蜂鸣器蜂鸣;松开后,停止蜂鸣
** 跳线说明:需将跳线JP8和KEY1短接,JP11连接蜂鸣器
*************************************************************************/
int main (void)
{

PINSEL0 = 0x00000000; //所有引脚都设置为GPIO
PINSEL1 = 0x00000000; //
IO0DIR = BEEP; //蜂鸣器控制口输出,其余输入

while(1)
{
if((IO0PIN & KEY1) == 0) //KEY1按下,蜂鸣器蜂鸣
IO0CLR = BEEP;
else //松开后,停止蜂鸣
IO0SET = BEEP;
}
return 0;
}
/**********************************************************************************
** End Of File
***********************************************************************************/



评论


技术专区

关闭