The display circuit consists of 8-bit digital tubes. When entering the password, only "8" is displayed. When the number of password digits is entered and the enter key is pressed, the entered password will be compared with the set password. If the password is correct, the door will open. Here, the led lights up for one second as a reminder, and at the same time, it makes a "ding-dong" sound. If the password is incorrect, it is forbidden to press the key for 3 seconds, and an alarm sound of "beep, beep" will be given at the same time; If the key is still pressed within 3 seconds, the key input for 3 seconds is prohibited again.
2. Circuit schematic diagram
Figure 4.33. 1
3. Hardware connection on the system board
(1). Connect p0.0-p0.7 in the "Single Chip Microcomputer System" area to the abcdefgh terminal in the "Dynamic Digital Display" area with an 8-core cable.
(2) Connect p2.0-p2.7 in the "Single Chip Microcomputer System" area to the s 1s2s3s4s5s6s7s8 terminal in the "Dynamic Digital Display" area with an 8-core cable.
(3) Connect p3.0-p3.7 in the "Single Chip Microcomputer System" area to the R 1R23R4C 1C2C3C4 terminal in the "4×4 determinant keyboard" area with an 8-core cable.
(4) Connect p 1.0 in the area of "Single Chip Microcomputer System" to l2 terminal in the area of "Eight LED modules" with wires.
(5) Connect p 1.7 in the area of "Single Chip Microcomputer System" to spk in terminal in the area of "Audio Amplification Module" with wires.
(6) Connect spk out in the "Audio Amplification Module" area to the speaker.
4. Program design content
(1) .4× 4 determinant keyboard recognition technology: This aspect has been discussed before, so I won't repeat it here.
(2) 8-digit display. When initializing, "P" will be displayed, and then a password of up to 6 digits will be entered. After entering the password, press Enter to compare the passwords, and then give the corresponding information. In the process of entering the password, the display screen only shows "8". . When the number of digital inputs exceeds 6, an alarm message will be sent out. In the process of password input, if the input is wrong, you can use the "del" key to delete the wrong number just entered.
(3) The key function distribution of the .4× 4 determinant keyboard is shown in Figure 4.33.2:
Figure 4.33.2
5.c language source program
# include & ltat89x52.h & gt
Unsigned char ps[]={ 1, 2,3,4,5};
Unsigned character code dispbit[]={0xfe, 0xfd, 0xfb, 0xf7,
0xef,0xdf,0xbf,0x7f };
Unsigned character code dispcode[]={0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d、0x7d、0x07、0x7f、0x6f、
0x77,0x7c,0x39,0x5e,0x79,0x7 1,
0x00,0x40,0x73,0x ff };
Unsigned char dispbuf[8]={ 18, 16, 16, 16, 16};
Unsigned character display count;
Unsigned character flashcount
Unsigned character temperature;
Unsigned character key;
Unsigned character keycount
Unsigned character pslen = 5;
Unsigned character getps [6];
bit keyoverflag
Bit error flag;
Right sign;
Unsigned integer seconds 3;
Unsigned int aa, bb;
Unsigned int cc
Bit okflag
Bit alarmflag
Bit prohibition sign;
Unsigned char oka, okb
Invalid master (invalid)
{
Unsigned characters I, j;
tmod = 0x 0 1;
th0 =(65536-500)/256;
tl0 =(65536-500)% 256;
tr0 = 1;
et0 = 1;
ea = 1;
while( 1)
{
p3 = 0xff
P3 _ 4 = 0;
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
for(I = 10; I>0; I-)
for(j = 248; j & gt0; j-);
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
Switch (temperature)
{
Case 0x0e:
key = 7;
Break;
Case 0x0d:
key = 8;
Break;
Case 0x0b:
key = 9;
Break;
Case 0x07:
key = 10;
Break;
}
temp = p3
p 1 _ 1 = ~ p 1 _ 1;
If ((key> = 0)&; & amp(key & lt 10))
{
if(key count & lt; 6)
{
getps[key count]= key;
disp buf[key count+2]= 19;
}
key count++;
if(keycount==6)
{
key count = 6;
}
else if(key count & gt; 6)
{
key count = 6;
keyeverflag = 1; //key overflow
}
}
Else if(key = = 12)// Delete the key.
{
if(key count & gt; 0)
{
key count-;
getps[key count]= 0;
disp buf[key count+2]= 16;
}
other
{
keyeverflag = 1;
}
}
Else if(key== 15)//enter key
{
if(keycount! =pslen)
{
error flag = 1;
right flag = 0;
Second3 = 0;
}
other
{
for(I = 0; I & ltkeycounti+++)
{
if(getps[i]! =ps[i])
{
i = keycount
error flag = 1;
right flag = 0;
Second3 = 0;
Go to a;
}
}
error flag = 0;
right flag = 1;
a:I = key count;
}
}
Temperature = Temperature & amp0x0f
while(temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
}
keyeverflag = 0; //?
}
}
p3 = 0xff
P3 _ 5 = 0;
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
for(I = 10; I>0; I-)
for(j = 248; j & gt0; j-);
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
Switch (temperature)
{
Case 0x0e:
key = 4;
Break;
Case 0x0d:
key = 5;
Break;
Case 0x0b:
key = 6;
Break;
Case 0x07:
key = 1 1;
Break;
}
temp = p3
p 1 _ 1 = ~ p 1 _ 1;
If ((key> = 0)&; & amp(key & lt 10))
{
if(key count & lt; 6)
{
getps[key count]= key;
disp buf[key count+2]= 19;
}
key count++;
if(keycount==6)
{
key count = 6;
}
else if(key count & gt; 6)
{
key count = 6;
keyeverflag = 1; //key overflow
}
}
Else if(key = = 12)// Delete the key.
{
if(key count & gt; 0)
{
key count-;
getps[key count]= 0;
disp buf[key count+2]= 16;
}
other
{
keyeverflag = 1;
}
}
Else if(key== 15)//enter key
{
if(keycount! =pslen)
{
error flag = 1;
right flag = 0;
Second3 = 0;
}
other
{
for(I = 0; I & ltkeycounti+++)
{
if(getps[i]! =ps[i])
{
i = keycount
error flag = 1;
right flag = 0;
Second3 = 0;
Go to A4;
}
}
error flag = 0;
right flag = 1;
a4:I = key count;
}
}
Temperature = Temperature & amp0x0f
while(temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
}
keyeverflag = 0; //?
}
}
p3 = 0xff
P3 _ 6 = 0;
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
for(I = 10; I>0; I-)
for(j = 248; j & gt0; j-);
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
Switch (temperature)
{
Case 0x0e:
key = 1;
Break;
Case 0x0d:
key = 2;
Break;
Case 0x0b:
key = 3;
Break;
Case 0x07:
key = 12;
Break;
}
temp = p3
p 1 _ 1 = ~ p 1 _ 1;
If ((key> = 0)&; & amp(key & lt 10))
{
if(key count & lt; 6)
{
getps[key count]= key;
disp buf[key count+2]= 19;
}
key count++;
if(keycount==6)
{
key count = 6;
}
else if(key count & gt; 6)
{
key count = 6;
keyeverflag = 1; //key overflow
}
}
Else if(key = = 12)// Delete the key.
{
if(key count & gt; 0)
{
key count-;
getps[key count]= 0;
disp buf[key count+2]= 16;
}
other
{
keyeverflag = 1;
}
}
Else if(key== 15)//enter key
{
if(keycount! =pslen)
{
error flag = 1;
right flag = 0;
Second3 = 0;
}
other
{
for(I = 0; I & ltkeycounti+++)
{
if(getps[i]! =ps[i])
{
i = keycount
error flag = 1;
right flag = 0;
Second3 = 0;
Go to a3;
}
}
error flag = 0;
right flag = 1;
a3:I = key count;
}
}
Temperature = Temperature & amp0x0f
while(temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
}
keyeverflag = 0; //?
}
}
p3 = 0xff
P3 _ 7 = 0;
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
for(I = 10; I>0; I-)
for(j = 248; j & gt0; j-);
temp = p3
Temperature = Temperature & amp0x0f
if (temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
Switch (temperature)
{
Case 0x0e:
key = 0;
Break;
Case 0x0d:
key = 13;
Break;
Case 0x0b:
key = 14;
Break;
Case 0x07:
key = 15;
Break;
}
temp = p3
p 1 _ 1 = ~ p 1 _ 1;
If ((key> = 0)&; & amp(key & lt 10))
{
if(key count & lt; 6)
{
getps[key count]= key;
disp buf[key count+2]= 19;
}
key count++;
if(keycount==6)
{
key count = 6;
}
else if(key count & gt; 6)
{
key count = 6;
keyeverflag = 1; //key overflow
}
}
Else if(key = = 12)// Delete the key.
{
if(key count & gt; 0)
{
key count-;
getps[key count]= 0;
disp buf[key count+2]= 16;
}
other
{
keyeverflag = 1;
}
}
Else if(key== 15)//enter key
{
if(keycount! =pslen)
{
error flag = 1;
right flag = 0;
Second3 = 0;
}
other
{
for(I = 0; I & ltkeycounti+++)
{
if(getps[i]! =ps[i])
{
i = keycount
error flag = 1;
right flag = 0;
Second3 = 0;
Go to a2;
}
}
error flag = 0;
right flag = 1;
a2:I = key count;
}
}
Temperature = Temperature & amp0x0f
while(temp! =0x0f)
{
temp = p3
Temperature = Temperature & amp0x0f
}
keyeverflag = 0; //?
}
}
}
}
Void t0(void) uses 0 interrupt 1
{
th0 =(65536-500)/256;
tl0 =(65536-500)% 256;
flash count++;
if(flashcount==8)
{
flash count = 0;
P0 = disp code[disp buf[disp count]];
p2 = disp bit[disp count];
disp count++;
if(dispcount==8)
{
dispcount = 0;
}
}
if((error flag = = 1)& amp; & amp(rightflag==0))
{
b b++;
If (bb==800)
{
bb = 0;
alarmflag = ~ alarmflag
}
If(alarm flag = = 1)// audible alarm signal
{
p 1 _ 7 = ~ p 1 _ 7;
}
aa++;
If(aa = = 800)// optical alarm signal
{
aa = 0;
p 1 _ 0 = ~ p 1 _ 0;
}
second 3++;
if(second3==6400)
{
Second3 = 0;
error flag = 0;
right flag = 0;
alarm flag = 0;
bb = 0;
aa = 0;
}
}
else if((error flag = = 0)& amp; & amp(rightflag== 1))
{
p 1 _ 0 = 0;
cc++;
if(cc & lt; 1000)
{
ok flag = 1;
}
else if(cc & lt; 2000)
{
ok flag = 0;
}
other
{
error flag = 0;
right flag = 0;
p 1 _ 7 = 1;
cc = 0;
oka = 0;
okb = 0;
ok flag = 0;
p 1 _ 0 = 1;
}
if(okflag== 1)
{
oka++;
If (oka==2)
{
oka = 0;
p 1 _ 7 = ~ p 1 _ 7;
}
}
other
{
ok b++;
if(okb==3)
{
okb = 0;
p 1 _ 7 = ~ p 1 _ 7;
}
}
}
if(keyoverflag== 1)
{
p 1 _ 7 = ~ p 1 _ 7;
}
}