Exynoss4412-led点亮笔记

A9按键灯程序
按键灯

#define GPM4CON     (*(volatile unsigned int *)0x110002E0)
#define GPM4DAT     (*(volatile unsigned int *)0x110002E4)

#define GPX3CON     (*(volatile unsigned int *)0x11000C60)
#define GPX3DAT     (*(volatile unsigned int *)0x11000C64)
// 延时函数
void delay(unsigned long count)
{
	volatile unsigned long i = count;
	while (i--);
}
int main(void)
{
    unsigned char keyValue = 0 ;
	unsigned int  flag_key = 0;
    // 配置GPM4_0,GPM4_1,GPM4_2,GPM4_3为输出引脚,对应LED1/2/3/4
    GPM4CON  &= ~ ((0xf << 0) | (0xf << 4) | (0xf << 8) | (0xf << 12));
	GPM4CON |=  ((0x1 << 0) | (0x1<< 4) | (0x1 << 8) | (0x1<< 12));
    // 设置K1、K2、K3、K4对应的GPIO(GPX3_2、GPX3_3、GPX3_4、GPX3_5)为输入
    GPX3CON &= ~ ((0xf << 8) | (0xf << 12) | (0xf << 16) | (0xf << 20)); 
    while(1)
	{
		//读按键引脚状态
		keyValue = GPX3DAT;
	    keyValue = (keyValue & (0xf << 2)) >> 2; 
		if(keyValue == 0xf)
		{
			GPM4DAT = 0xffff;
		}
		if(keyValue != 0xf)				//说明有按键被按下,再详细判断是哪个按键被按下
		{
		delay(1000); 			//按键消抖 
			 keyValue = GPX3DAT;
			 keyValue = (keyValue & (0xf << 2)) >> 2;	
            /*********1234全亮**************************************************/
			if(keyValue == 0xe)
			{
				GPM4DAT = 0x0;
				delay(100000);
				GPM4DAT = 0xf;
				delay(100000);			
			}
			else
			{
				GPM4DAT = 0xf;
				}
			
			/***********1、3同时亮灭************************************************/
			if(keyValue == 0xd)
			{
				GPM4DAT = 0xa;		
				delay(1000000);	
				GPM4DAT = 0xf;
				delay(1000000);	
			}
			else
			{
				GPM4DAT = 0xf;
			}
			/**********2、4交叉亮灭*************************************************/
			if(keyValue == 0xb)
			{		
				GPM4DAT = 0x7;
				GPM4DAT = 0xd;				
				delay(1000000);	
				GPM4DAT = 0xf;
				GPM4DAT = 0xd;
				GPM4DAT = 0x7;	
				delay(1000000);	
				GPM4DAT = 0xf;
				delay(1000000);				
			}
			else
			{
				GPM4DAT = 0xf;
				}
			/************4灯同时灭***********************************************/
			if(keyValue == 0x7)
			{
				if(flag_key==0)flag_key=1;
				else flag_key=0;				
			}	
			else
			{
				GPM4DAT = 0xf;
			}
			
			if(flag_key==1)
			{
			GPM4DAT = 0xffff;
			}
		}		
	} 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值