轮询实现按键实验
#include "exynos_4412.h"
int main()
{
//GPX1_1设置为输入模式//
GPX1.CON=GPX1.CON & (~ (0XF<<4));
while(1)
{
if(!(GPX1.DAT&(1<<1)))
{
printf("key pressed\n");
while(!(GPX1.DAT&(1<<1)));
}
else
{
}
}
return 0;
}
作业:
#include "exynos_4412.h"
int main()
{
//GPX1_1设置为输入模式//
GPX1.CON = GPX1.CON & (~ (0XF<<4));
//GPX2CON设置为输出模式//
GPX2.CON = GPX2.CON & (~(0XF << 28)) |(0X1 << 28);
int flag=0;
while(1)
{
if(!(GPX1.DAT&(1<<1)))
{
flag=~flag;
while(!(GPX1.DAT&(1<<1)));
}
if(flag)
{
//LED2亮//
//printf("key pressed\n");
GPX2.DAT = GPX2.DAT | (1<<7);
}
else
{
//LED2熄灭
GPX2.DAT=GPX2.DAT & (~(1<<7));
}
}
return 0;
}
#include "exynos_4412.h"
int main()
{
//将GPX1_1设置为中断功能//
GPX_1.CON=GPX_1.CON | (0xF << 4);
//设置GPX_1中断触发模式---下降沿触发//
EXT_INT41_CON=EXT_INT41_CON & (~(0x7<<4)) |(0x2<<4);
//使能GPX1_1---开启中断模式//
EXT_INT41_MASK=EXT_INT41_MASK & (~(1<<1));
return 0;
}