📄 key.c
字号:
#include "config.h"
#define BEEP
#define KEY1 1<<16
#define KEY2 1<<17
#define KEY3 1<<18
#define KEY4 1<<19
#define KEY5 1<<20
#define KEY6 1<<21
#define KEYS (0x03f)<<16
#define LED1 1<<18
#define LED2 1<<19
#define LED3 1<<20
#define LED4 1<<21
#define LED5 1<<22
#define LED6 1<<23
#define LED7 1<<24
#define LED8 1<<25
#define PasswordLength 3
uint32 PasswordNum[PasswordLength];
uint32 InputPassword[PasswordLength];
void InitGetPassword(void)
{
PINSEL1 = PINSEL1 &(~(0x0fff));
IO0DIR = IO0DIR & (~KEYS);
PINSEL2 = PINSEL2 & (~(0x08));
IO1DIR = IO1DIR | (LEDS);
IO1SET = LEDS;
}
void SetPassword( uint32* key)
{
uint8 i;
for(i= 0; i<PasswordLength;i++)
PasswordNum[i] = *(key+i);
}
void InputRemind(void)
{
IO1CLR = LED8;
OSTimeDlyHMSM(0,0,0,250);
IO1SET = LED8;
OSTimeDlyHMSM(0,0,0,250);
}
void WrongRemind(void)
{
IO1CLR = LED7;
OSTimeDlyHMSM(0,0,0,100);
IO1SET = LED7;
OSTimeDlyHMSM(0,0,0,100);
}
uint8 GetPasswordNum(void)
{
uint8 i;
uint32 temp;
while((IO0PIN | KEYS) == IO0PIN)
InputRemind();
for(i = 0; i<PasswordLength;i++)
{
while((IO0PIN | KEYS) == IO0PIN);
// if((IO0PIN | KEYS) == IO0PIN)
// return NULL;
OSTimeDlyHMSM(0,0,0,50);
if((IO0PIN | KEYS) == IO0PIN)
return NULL;
IO1CLR = LED8;
temp = IO0PIN & KEYS;
temp = temp >> 16;
//备注:#define的常量作为右值赋给变量时不能进行取反等操作,否则编译器将自动优化掉。
switch(temp)
{
case 0x3e: IO1CLR = LED1;break;
case 0x3d: IO1CLR = LED2;break;
case 0x3b: IO1CLR = LED3;break;
case 0x37: IO1CLR = LED4;break;
case 0x2f: IO1CLR = LED5;break;
case 0x1f: IO1CLR = LED6;break;
default : break;
}
while((IO0PIN | KEYS) != IO0PIN)
OSTimeDlyHMSM(0,0,0,50);
InputPassword[i] = temp;
IO1SET = LEDS;
IO1CLR = LED8;
}
IO1SET = LED8;
return TRUE;
}
uint8 CheckPassword(void)
{
uint8 i;
for(i=0;i<PasswordLength;i++)
{
if((*(InputPassword+i))!=(* (PasswordNum+i)))
return FALSE;
}
return TRUE;
}
/************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -