📄 main.c
字号:
#include <reg51.h>
#include <intrins.h>
typedef unsigned char BYTE;
sbit P30=P3^0;
sbit P31=P3^1;
sbit P32=P3^2;
sbit P33=P3^3;
sbit P34=P3^4;
sbit P35=P3^5;
BYTE num;
BYTE password[8];
BYTE input[8];
BYTE new_pass[8];
BYTE error_count;
BYTE code K1TAB[]={ 0x81,0x41,0x21,0x11,
0x82,0x42,0x22,0x12,
0x84,0x44,0x24};
void DELAY();
BYTE KEY();
void DISPLED();
BYTE COMP();
BYTE TestKey();
BYTE CHPSW();
main()
{
BYTE offset=0;
BYTE KEY_t;
num=8;
do
{
password[offset]=offset;
offset++;
}while(--num);
MLOOP:
P30=0;
P31=1;
P32=1;
P33=1;
P34=1;
error_count=3;
offset=0;
GETPW:
num=8;
do
{
do
{
KEY_t=KEY();
}while(KEY_t==0x0A);
input[offset]=KEY_t;
DISPLED();
offset++;
}while(--num);
while(KEY()!=0x0A);
DISPLED();
if(!COMP()) goto GETPW;
P30=1;
P31=0;
while(1)
{
wait:
if(P35)
{
if(!TestKey()) continue;
if(!CHPSW()) goto wait;
}
else
{
goto MLOOP;
}
}
}
void DELAY()
{
BYTE i=0x80;
do
{
BYTE j=0xF8;
do
{
_nop_();
_nop_();
}while(--j);
}while(--i);
}
BYTE COMP()
{
BYTE num=8;
BYTE offset=0;
do
{
if(input[offset]!=password[offset])
{
P33=0;
DELAY();
DELAY();
P33=1;
if(--error_count) return 0;
P34=0;
P33=0;
while(1);
}
}while(--num);
}
void DISPLED()
{
P32=0;
DELAY();
P32=1;
}
BYTE TestKey()
{
P1=0x0F;
return ( (~P1)&0xF0 );
}
BYTE KEY()
{
BYTE offset;
BYTE temp;
BYTE temp2;
KEY:
do
{
do
{
P1=0xF0;
}while(P1==0xF0);
DELAY();
P1=0xF0;
temp=P1;
}while(temp==0xF0);
P1=0x0F;
if(P1==0x0F) goto KEY;
else
{
DELAY();
P1=0x0F;
temp2=P1;
if(temp2==0x0F) goto KEY;
else
{
temp=temp2&temp;
num=11;
offset=0;
do
{
if(temp==K1TAB[offset])
{
while(P1!=0x0F);
DELAY();
return offset;
}
offset++;
}while(--num);
}
}
}
BYTE CHPSW()
{
BYTE num=7;
BYTE temp;
BYTE offset;
temp=KEY();
if(temp!=0x0A)
{
new_pass[offset]=temp;
DISPLED();
do
{
do
{
temp=KEY();
}while(temp==0x0A);
new_pass[offset]=temp;
offset++;
DISPLED();
}while(--num);
while(KEY()!=0x0A);
DISPLED();
num=8;
offset=0;
do
{
password[offset]=new_pass[offset];
offset++;
}while(--num);
}
else
{
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -