Home > other >  I want to know why I go to shake the UI failed, press the 1 will always flash
I want to know why I go to shake the UI failed, press the 1 will always flash

Time:10-05


# include "reg52. H"

Typedef unsigned int under-16;
Typedef unsigned char u8;

U8 key;
U8 a, b, c, I, p=0;
U8 code Tab [16]={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71};

# define DGIO_DIG P0//variable definition
# define DGIO_key P1
Sbit beep=P2 ^ 0;
Sbit led0=P2 ^ 1;
Sbit led1=P2 ^ 2;
Sbit led2=P2 ^ 3;
Sbit led3=P2 ^ 4;
Sbit L0=P3 ^ 7;
Sbit L1=P3 ^ 6;
Sbit relay=P3 ^ 5;
Sbit k2=P3 ^ 2;

U8 tre=0;

Void delay (under-16 I)//delay 1 us
{
While (I -);
}

void dig ()//rectangle button judgment
{
DGIO_key=0 x0f;

If (DGIO_key!=0 x0f & amp; & ! Tre)
{
delay(1000);
Tre=1;
L0=0;
delay(2000);
L0=1;
If (DGIO_key!=0 x0f)
{
The switch (DGIO_key)
{
Case (0 x07) : key=0; break;//check the line
Case (0 x0b) : key=1; break;
Case (0 x0d) : key=2; break;
Case (0 x0e) : key=3; break;
}
DGIO_key=0 xf0;
The switch (DGIO_key)
{
Case (0 x70) : key=key; b++; break;//check list
Case (0 xb0) : key=key + 4; b++; break;
Case (0 xd0) : key=key + 8; b++; break;
Case (0 xe0-0xfc) : key=key + 12; b++; break;
}
}
}
Else if (DGIO_key==0 x0f)
{tre=0; }
}





LED (void)
{
If (b<5)
{
The switch (b)
{
Case (1) : led0=0; Led1=1; Led2=1; Led3=1; break;//pick digital tube
Case (2) : led0=1; Led1=0; Led2=1; Led3=1; break;
Case (3) : led0=1; Led1=1; Led2=0; Led3=1; break;
Case (4) : led0=1; Led1=1; Led2=1; Led3=0; break;
}
P0=Tab [key];//digital tube output
Delay (8000);
P0=0 x00;//blanking
}
}

Void int0 ()//external interrupt 0 falling edge triggered
{
IT0=1;
EX0=1;
EA=1;
}



Void main ()
{


While (1)
{
Relay=0;
Dig ();
Leds ();
If (key==1)//input correct password order began to count
{
C=c + 1;
Delay (8000);
}



If (key==9)//input the correct password order began to count
{
C=c + 1;
Delay (8000);
}



If (key==6)//input the correct password order began to count
{
C=c + 1;
Delay (8000);
}




If (b==4)//check whether the key is to achieve four
{
If (c!=4)//verify password is normal
{
While (a<10000)//if the password wrong buzzer alarm rapid flash a red light
{L0=1;
Delay (3000);
L0=0;
delay(2000);
Beep=0;
Delay (5000);
Beep=1;
Delay (5000);
a++;
}
}

Else if (c==4)
{the for (I=0; i<100; I++)//loop 100 times, that is, about 5 s
Relay=1;//open motor
Delay (5000);//delay about 50 ms
L1=0;
}
Relay=0;
}
}
}
  • Related