📄 main.c
字号:
#include <panel.h>
#include <1621.h>
#include <STC89C51.H>
#include <stdlib.h>
static unsigned char sbuf[100];
static unsigned char key_num[10];
unsigned char token=0;
unsigned char len=0;
static unsigned int t=5;
void DisplayNum(void)
{
unsigned char ADDr[]={0x06,0x04,0x02,0x00,0x0e,
0x10,0x12,0x08,0x0a,0x0c};
unsigned char seg[]={0xdf,0x86,0xbd,0xaf,0xe6,0xeb,0xfb,0x8e,0xff,0xef};//数码管1,2,3,4,5,6,7,8,9,10对应数字显示
//0 1 2 3 4 5 6 7 8 9
unsigned char i,j;
int num[]={0,1,2,3,4,5,6,7,8,9};
//SMG10 SMG1 SMG2 SMG3 SMG4 SMG5 SMG6 SMG7 SMG8 SMG9
int rn[10];
srand((unsigned)t++);//time(&t));
for(i=0;i<10;i++)
{
rn[i]=rand()%10;
for(j=0;j<i;j++)
{
if(rn[i]==rn[j]){i--;j=i;}
}
}
for(i=0;i<10;i++)
{key_num[i] = num[rn[i]];}
for(i=0;i<10;i++)
{
Write_1621(ADDr[i],seg[key_num[i]]);
}
}
void DisplayNum_sequence(void)
{
int i;
unsigned char ADDr[]={0x06,0x04,0x02,0x00,0x0e,
0x10,0x12,0x08,0x0a,0x0c};
unsigned char seg[]={0xdf,0x86,0xbd,0xaf,0xe6,0xeb,0xfb,0x8e,0xff,0xef};//数码管1,2,3,4,5,6,7,8,9,10对应数字显示
//0 1 2 3 4 5 6 7 8 9
for(i=0;i<10;i++)
key_num[i] = i;
for(i=0;i<10;i++)
Write_1621(ADDr[i],seg[key_num[i]]);
}
void get_cr(void)
{
int i;
unsigned char sign_enter=0;
unsigned char key_temp;
unsigned int count=0;
len=0;
LightPanel_on();
DisplayNum();
while(!sign_enter)
{
for(count =0;((JudgeKey()!=1) && (count<300));count++)
delay_ms(15);
if(count == 300)
sign_enter = 1;
if(!sign_enter)
key_temp = keypad_scan();
if(key_temp == 10)
{
DisplayNum_sequence();
//num = 0;
//for(i=0;i<len;i++)
//sbuf[i] = 0;
//token=0;
//DisplayToken_on(0);
}
if(key_temp == 11)
{
DisplayNum();
//num = 0;
//for(i=0;i<len;i++)
//sbuf[i] = 0;
//token=0;
//DisplayToken_on(0);
}
if((key_temp>=0) && (key_temp<=9))
{
if(len<8)
{
DisplayToken_on(++token);
} else{
DisplayToken_on(8);
}
sbuf[len]=key_num[key_temp];
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
len++;
}
if(key_temp == 12)
{
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
if(len==0)
{
len=0;
} else {
len--;
}
DisplayToken_on(--token);
}
if(key_temp==13)
{
sign_enter = 1;
break;
}
}
key_temp = 20;
// while((keypad_scan() !=13) && (sign_enter !=1));
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
//sign_enter = 0;
}
void send_package(void)
{
int i;
Send_Byte(0x02);
if(len >0)
{
if((SW3 == 0) && (SW4 == 0))
{
for(i=0;i<len;i++)
{
sbuf[i] +=0x30;
Send_Byte(sbuf[i]);
}
}
if((SW3==1) && (SW4==0))
{
for(i=0;i<len;i++)
{
if(sbuf[i] == 0)
{
sbuf[i] = 0x92;
} else {
sbuf[i] +=0x95;
}
Send_Byte(sbuf[i]);
}
}
if((SW3==0) && (SW4==1))
{
for(i=0;i<len;i++)
{
if(sbuf[i] == 0)
{
sbuf[i] = 0x5f;
} else {
sbuf[i] +=0x4f;
}
Send_Byte(sbuf[i]);
}
}
}
Send_Byte(0x03);
}
void get_cr_send(void)
{
int i;
get_cr();
send_package();
}
void get_send_cr(void)
{
int i;
//unsigned char num=0;
unsigned char sign_enter=0;
unsigned char key_temp;
unsigned int count=0;
len=0;
DisplayNum();
LightPanel_on();
while(!sign_enter)
{
for(count =0;((JudgeKey()!=1) && (count<300));count++)
delay_ms(15);
if(count == 300)
sign_enter = 1;
if(!sign_enter)
key_temp = keypad_scan();
if(key_temp == 10)
{
DisplayNum_sequence();
//num = 0;
//for(i=0;i<len;i++)
//sbuf[i] = 0;
//token=0;
//isplayToken_on(0);
}
if(key_temp == 11)
{
DisplayNum();
//num = 0;
//for(i=0;i<len;i++)
//sbuf[i] = 0;
//token=0;
//DisplayToken_on(0);
}
if((key_temp>=0) && (key_temp<=9) )
{
if(len<8)
{
DisplayToken_on(++token);
} else {
DisplayToken_on(8);
}
sbuf[len]=key_num[key_temp];
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
if((SW3 == 0) && (SW4 == 0))
{
sbuf[len] +=0x30;
Send_Byte(sbuf[len]);
}
if((SW3==1) && (SW4==0))
{
if(sbuf[len] == 0)
{
sbuf[len] = 0x92;
} else {
sbuf[len] +=0x95;
}
Send_Byte(sbuf[len]);
}
if((SW3==0) && (SW4==1))
{
if(sbuf[len] == 0)
{
sbuf[len] = 0x5f;
} else {
sbuf[len] +=0x4f;
}
Send_Byte(sbuf[len]);
}
len++;
}
if(key_temp == 12)
{
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
if(len==0)
{
len=0;
} else {
len--;
}
if((SW3 == 0) && (SW4 == 0))
Send_Byte(0x08);
if((SW3==1) && (SW4==0))
Send_Byte(0x94);
if((SW3==0) && (SW4==1))
Send_Byte(0x5e);
DisplayToken_on(--token);
}
if(key_temp==13)
{
sign_enter = 1;
break;
}
}
key_temp = 20;
//while((keypad_scan() !=13) && (sign_enter !=1));
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
if((SW3 == 0) && (SW4 == 0))
Send_Byte(0x0d);
if((SW3==1) && (SW4==0))
Send_Byte(0x95);
if((SW3==0) && (SW4==1))
Send_Byte(0x74);
}
void main ()
{
int i,j=0;
unsigned char key_temp,key_tempcopy;
unsigned char temp1,temp2;
int sign_enter=0;
int sign_fanxu=0;
int sign_sequence=0;
unsigned char sign,sign_copy;
unsigned char com1_group1,com1_group2,com1_group3,com1_group4;
unsigned char com2_group1,com2_group2,com2_group3;
unsigned char com_key=0;
unsigned char com1_group3_80h,com1_group3_81h,com1_group3_82h,com1_group3_83h,com1_group4_02h,com1_group4_04h,com1_group4_03h;
unsigned char com1_group1_I,com1_group1_E,com1_group1_FI,com1_group1_FE,com1_group1_G,com1_group1_M,com1_group1_L,com1_group1_N;
unsigned char com1_group2_1,com1_group2_2,com1_group2_3;
unsigned char com2_group1_0,com2_group1_1,com2_group1_2,com2_group1_3;
unsigned char com2_group2_81h,com2_group2_83h,com2_group2_84h,com2_group2_85h,com2_group2_88h,com2_group2_89h;
unsigned char com2_group3_I,com2_group3_E;
unsigned char com1_sign,com2_sign;
InitSystem ();
Init_1621();
DisplayNum();
Write_1621(0x14,0x00);//close "*"
LightPanel_on();
Tone();
delay_ms(500);
LightPanel_off();
delay_ms(500);
for(i=0;i<100;i++)
sbuf[i] = 0x30;
#if 1
while(1)
{
com1_group1=0,com1_group2=0,com1_group3=0,com1_group4=0;
com_key=0;
com1_group3_81h=0,com1_group3_80h=0,com1_group3_83h=0,com1_group3_82h=0,com1_group4_02h=0,com1_group4_04h=0,com1_group4_03h=0;
com1_group1_I=0,com1_group1_E=0,com1_group1_FE=0,com1_group1_FI=0,com1_group1_G=0,com1_group1_M=0,com1_group1_L=0,com1_group1_N=0;
com1_group2_1=0,com1_group2_2=0,com1_group2_3=0;
com2_group1_0=0,com2_group1_1=0,com2_group1_2=0,com2_group1_3=0;
com2_group2_81h=0,com2_group2_83h=0,com2_group2_84h=0,com2_group2_85h=0,com2_group2_88h=0,com2_group2_89h=0;
com2_group3_I=0,com2_group3_E=0;
delay_ms(100);
if(SW2 == 0)//格式1
{
delay_ms(50);
t++;
com1_sign = 1;
while(com1_sign)
{
com_key = Receive_Byte();
if ((com_key == 0x81) || (com_key == 0x82)|| (com_key == 0x80)|| (com_key == 0x83))
{
com1_group3=1;
if(com_key == 0x81)
{
com1_sign=0;
com1_group3_81h = 1;
}
if(com_key == 0x82)
{
com1_sign=0;
com1_group3_82h = 1;
}
if(com_key == 0x80)
{
com1_sign=0;
com1_group3_80h = 1;
}
if(com_key == 0x83)
{
com1_sign=0;
com1_group3_83h = 1;
}
}
if((com_key == 0x02) || (com_key == 0x04) || (com_key == 0x03))
{
com1_group4 = 1;
if(com_key == 0x02)
{
com1_sign=0;
com1_group4_02h = 1;
}
if(com_key == 0x04)
{
com1_sign=0;
com1_group4_04h = 1;
}
if(com_key == 0x03)
{
com1_sign=0;
com1_group4_03h = 1;
}
}
if(com_key == 0x1b)
{
com_key = Receive_Byte();
if((com_key == 0x49) || (com_key == 0x45) ||(com_key == 0x4d) ||(com_key == 0x4c) ||(com_key == 0x4e) ||(com_key == 0x47))
{
com1_group1 = 1;
com1_sign=0;
switch(com_key){
case 0x49: com1_group1_I = 1;
break;
case 0x45: com1_group1_E = 1;
break;
case 0x4d: com1_group1_M =1;
break;
case 0x4c: com1_group1_L = 1;
break;
case 0x4e: com1_group1_N = 1;
break;
case 0x47: com1_group1_G = 1;
break;
}
}
if(com_key == 0x46)
{
com1_group1 = 1;
com_key = Receive_Byte();
com_key = Receive_Byte();
if(com_key == 0x49)
{
com1_sign=0;
com1_group1_FI=1;
}
if(com_key == 0x45)
{
com1_sign=0;
com1_group1_FE=1;
}
}
if(com_key == 0x5b)
{
com1_group2 = 1;
com_key = Receive_Byte();
com_key = Receive_Byte();
if(com_key == 0x31)
{
com1_sign=0;
com1_group2_1=1;
}
if(com_key == 0x32)
{
com1_sign=0;
com1_group2_2=1;
}
if(com_key == 0x33)
{
com1_sign=0;
com1_group2_3=1;
}
}
}
}//判断命令结束
//Send_Byte(0xaa);
//DisplayNum();
//for(i=0;i<6;i++)
//sbuf[i] = 0;
if(com1_group1_I == 1)
{
GREENLED = 0;
LightPanel_on();
input_password();
get_cr_send();
}
if(com1_group1_E == 1)
{
REDLED = 0;
LightPanel_on();
re_input_password();
get_cr_send();
}
if(com1_group1_FI ==1)
{
GREENLED = 0;
LightPanel_on();
input_password();
get_cr();
}
if(com1_group1_FE ==1)
{
REDLED = 0;
LightPanel_on();
input_password();
get_cr();
}
if(com1_group1_G == 1)
{
send_package();
}
if((com1_group1_M == 1) || (com1_group2_1 == 1) || (com1_group3_82h == 1) || (com1_group4_02h == 1))
{
GREENLED= 0;
LightPanel_on();
input_password();
get_send_cr();
}
if((com1_group1_L ==1) || (com1_group2_2 == 1) || (com1_group4_04h == 1) || (com1_group3_81h ==1))
{
REDLED = 0;
LightPanel_on();
re_input_password();
get_send_cr();
}
if(com1_group1_N == 1)
{
com1_group1_N = 0;//密码长度如何得到
}
if((com1_group2_3 == 1) || (com1_group3_83h == 1) || (com1_group4_03h==1))
{
REDLED = 1;
GREENLED = 1;
}
if(com1_group3_80h == 1)
{
REDLED = 0;
GREENLED = 0;
}
}
delay_ms(100);
if(SW2 == 1)
{
delay_ms(50);
t++;
com2_sign = 1;
while(com2_sign)
{
com_key = Receive_Byte();
if ((com_key == 0x81) || (com_key == 0x83) || (com_key == 0x84) || (com_key == 0x88))
{
if(com_key == 0x81)
{
com2_sign=0;
com2_group2_81h = 1;
}
if(com_key == 0x83)
{
com2_sign=0;
com2_group2_83h = 1;
}
if(com_key == 0x84)
{
com2_sign=0;
com2_group2_84h = 1;
}
if(com_key == 0x88)
{
com2_sign=0;
com2_group2_88h = 1;
}
if(com_key == 0x85)
{
com2_sign=0;
com2_group2_85h = 1;
}
if(com_key == 0x89)
{
com2_sign=0;
com2_group2_89h = 1;
}
}
if(com_key == 0x1b)
{
com_key = Receive_Byte();
if((com_key == 0x49) || (com_key == 0x45))
{
com2_sign=0;
switch(com_key){
case 0x49: com2_group3_I = 1;
break;
case 0x45: com2_group3_E = 1;
break;
}
}
if(com_key == 0x5b)
{
com_key = Receive_Byte();
com_key = Receive_Byte();
if(com_key == 0x30)
{
com2_sign=0;
com2_group1_0=1;
}
if(com_key == 0x31)
{
com2_sign=0;
com2_group1_1=1;
}
if(com_key == 0x32)
{
com2_sign=0;
com2_group1_2=1;
}
if(com_key == 0x33)
{
com2_sign=0;
com2_group1_3=1;
}
}
}
if(com2_group1_1==1)
{
REDLED =1;
}
if(com2_group1_3==1)
{
GREENLED =1;
}
if((com2_group2_81h==1) ||(com2_group2_83h==1) ||(com2_group1_2==1) ||(com2_group2_88h==1) ||(com2_group3_I==1))
{
GREENLED = 0;
LightPanel_on();
input_password();
get_send_cr();
}
if((com2_group2_84h==1) || (com2_group1_0==1) ||(com2_group3_E == 1))
{
REDLED =0;
LightPanel_on();
re_input_password();
get_send_cr();
}
if((com2_group2_85h==1))
{
GREENLED=1;
REDLED=1;
}
if((com2_group2_89h==1))
{
GREENLED=1;
REDLED=1;
}
}
}
DisplayToken_on(0);
LightPanel_off();
token=0;
GREENLED = 1;
REDLED=1;
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -