📄 sock-chek.c
字号:
#include <reg52.H>
#define uint unsigned int
#define uchar unsigned char
////////////////////////////////////////////////////////////////////////////////led digital code define
uchar discod[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0,0x83,0x92,0x98,0x86,0x8e};
////////////////={ 0 1 2 3 4 5 6 7 8 9 A b s q e f };
uchar disbuf[6]={0x01,0x02,0x03,0x04,0x05,0x06}; ///six led figue buffer
uchar seriout,dseriout,seriin=0,fuctionled; ///situation variable define
////////////////////////////////////////////////////////////////////////////////yf chek weep sequence
uchar yfincode[16]={16,38,37,17,49,1,30,4,42,36,25,18,0, 2,31,3,};
///////////////////={1 , 2, 3, 4, 5,6, 7,8, 9,10,11,12,13,14,15,16};
////////////////////////////////////////////////////////////////////////////////yq chek weep sequence
uchar yqincode[21]={25,0,18,19,11,0, 0,38,42,16,36, 0,49, 4, 3,30,31, 1, 2,17};
////////////////////{1 ,2,3 ,4 ,5 ,6, 7,8 , 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
////////////////////////////////////////////////////////////////////////////////fs chek weep sequence
uchar fsincode[18]={49,42,33,29,19,25,31, 3, 0, 0, 0, 0,32,28,17, 0,30,4 };
///////////////////={1 , 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18};
//////////////////////////////////////////////////////////////////////
sbit DS =P1^0;
sbit OE =P1^1;
sbit STCP =P1^2; //////define port for 595 use at led
sbit SHCP =P1^3;
sbit MR =P1^4;
///////////////////////
sbit DS1 =P1^5;
sbit OE1 =P1^6;
sbit STCP1 =P1^7; //////define port for 595 use at CHEK NUMBER OUT
sbit SHCP1 =P3^0;
sbit MR1 =P3^1;
///////////////////////
sbit S1 =P0^3;
sbit SO =P0^4;
sbit CLK =P0^1; //////define port for 165 use at CHEK NUMBER IN
sbit INH =P0^2;
sbit SHL =P0^0;
///////////////////////
sbit L1 =P2^5;
sbit L2 =P2^6;
sbit L3 =P2^7; //////function port definition
sbit BELL =P3^7;
sbit L0 =P3^6;
///////////////////////
sbit K4 =P2^0;
sbit K3 =P2^1;
sbit K2 =P2^2; //////key definition
sbit K1 =P2^3;
///////////////////////
main()
{
L0=0;L1=0;L2=0;L3=0;BELL=0; ///clear function
DS1=0; DS=0; ///clear seial in
for(;;)
{
nest:
seriout=3; ///out chek number recognice signal wire type
chekout(); ///chek number out procedures
chekin(); ///chek number in procedures
switch (seriin) ///recognice wire type
{
////////////////////////////////////////////////////////////////////////////////////////////////////
case 15: //yq code chek process
{uchar qdelay;
for(seriout=1;seriout<50;seriout++) //50 scsi out
{L1=1;L0=1;fuctionled=13; //led ant function code
if ((seriout==25)|(seriout==18)|(seriout==19)|(seriout==11)|(seriout==37)|(seriout==42)| //yq useful port
(seriout==38)|(seriout==36)|(seriout==16)|(seriout==49)|(seriout==4)|(seriout==3)|
(seriout==30)|(seriout==31)|(seriout==1)|(seriout==2)|(seriout==17))
{
chekout();chekin();if(K1==0){goto nest;} //jump out restart
if((seriout==yqincode[seriin-1])|(seriout==yqincode[seriin-1]+26)) //compare out code to in code
{
if(K3==0){for(qdelay=0;qdelay<30;qdelay++){display();}} //press k3 to delay
if(K2==1){for(qdelay=0;qdelay<10;qdelay++){display();}} //press k2 to speed up
L1=0;L0=0;
if(K3==0){for(qdelay=0;qdelay<30;qdelay++){display();}}
if(K2==1){for(qdelay=0;qdelay<10;qdelay++){display();}}
for(qdelay=0;qdelay<10;qdelay++){display();}
}
else
{
BELL=1; //read wrong bell alrm
while(!(seriout==yqincode[seriin-1]))
{chekin();fuctionled=14;display();if(K1==0){goto nest;}} //read again and if k1pres jump out
}
BELL=0; //off alrm
while(!K4){display();} //pause
}
}
BELL=1; for(qdelay=0;qdelay<10;qdelay++){display();}
BELL=0; for(qdelay=0;qdelay<10;qdelay++){display();}
BELL=1; for(qdelay=0;qdelay<10;qdelay++){display();}
BELL=0; for(qdelay=0;qdelay<10;qdelay++){display();}
}break;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 16: //yf code chek process
{
uchar fdelay;
for(seriout=1;seriout<50;seriout++) //the next function same to yq
{L3=1;L0=1;fuctionled=15;
if ((seriout==16)|(seriout==38)|(seriout==37)|(seriout==17)|(seriout==49)|(seriout==1)|
(seriout==30)|(seriout==4)|(seriout==42)|(seriout==36)|(seriout==25)|(seriout==18)|
(seriout==2)|(seriout==31)|(seriout==3))
{
chekout();chekin();if(K1==0){goto nest;}
if(seriout==yfincode[seriin-1])
{
if(K3==0){for(fdelay=0;fdelay<30;fdelay++){display();}}
if(K2==1){for(fdelay=0;fdelay<10;fdelay++){display();}}
L3=0;L0=0;
if(K3==0){for(fdelay=0;fdelay<30;fdelay++){display();}}
if(K2==1){for(fdelay=0;fdelay<10;fdelay++){display();}}
for(fdelay=0;fdelay<10;fdelay++){display();}
}
else
{
BELL=1;
while(!(seriout==yfincode[seriin-1]))
{chekin();fuctionled=14;display();if(K1==0){goto nest;}}
}
BELL=0;
while(!K4){display();}
}
}
BELL=1; for(fdelay=0;fdelay<10;fdelay++){display();}
BELL=0; for(fdelay=0;fdelay<10;fdelay++){display();}
BELL=1; for(fdelay=0;fdelay<10;fdelay++){display();}
BELL=0; for(fdelay=0;fdelay<10;fdelay++){display();}
}break;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 8: //fs code chek process
{
uchar delay; //the next function same to yq
for(seriout=1;seriout<50;seriout++)
{L2=1;L0=1;fuctionled=12;
if ((seriout==49)|(seriout==42)|(seriout==33)|(seriout==29)|(seriout==19)|(seriout==25)|
(seriout==31)|(seriout==3)|(seriout==32)|(seriout==28)|(seriout==17)|(seriout==30)|
(seriout==4))
{
chekout();chekin();if(K1==0){goto nest;}
if(seriout==fsincode[seriin-1])
{
if(K3==0){for(delay=0;delay<30;delay++){display();}}
if(K2==1){for(delay=0;delay<10;delay++){display();}}
L2=0;L0=0;
if(K3==0){for(delay=0;delay<30;delay++){display();}}
if(K2==1){for(delay=0;delay<10;delay++){display();}}
for(delay=0;delay<10;delay++){display();}
}
else
{
BELL=1;
while(!(seriout==fsincode[seriin-1]))
{chekin();fuctionled=14;display();if(K1==0){goto nest;}}
}
BELL=0;
while(!K4){display();}
}
}
BELL=1; for(delay=0;delay<10;delay++){display();}
BELL=0; for(delay=0;delay<10;delay++){display();}
BELL=1; for(delay=0;delay<10;delay++){display();}
BELL=0; for(delay=0;delay<10;delay++){display();}
}break;
//////////////////////////////////////////////////////////////////////////////////////////
}
display();
}
}
///////////////////////////////////////////////////////////////////////
////display start ////
///////////////////////////////////////////////////////////////////////
display() // display by 74hc595d
{
uchar i,ii,iii,iiii,disad=1; //i:6lednumber ii:ledallcodnumber disad:led at address
uint dscod,sericode;
/////////////////////////////////// here compile the display code then send to buffer
disbuf[0]=discod[fuctionled]; ///
disbuf[1]=discod[seriout/10]; ///
disbuf[2]=discod[seriout%10]; ///
disbuf[3]=0xbf; ///
disbuf[4]=discod[seriin/10]; ///
disbuf[5]=discod[seriin%10]; ///
///////////////////////////////////
for(iiii=0;iiii<1;iiii++)
{
for(i=0;i<6;i++)
{
sericode=(disbuf[i]*256)+disad; //the number of 595 use to shefit out
disad*=2; //led address add one
OE=1; //595 enable off
MR=0;MR=1; //begin datashfit
for(ii=0;ii<17;ii++) //shfit 16 bit
{
STCP=0;SHCP=0; //pluse down for ready
dscod=sericode&0x8000; //cunt out bit
DS=dscod; //out
STCP=1;SHCP=1; //clok pluse up data_bit out
sericode<<=1; //lift shfit one bit
}
OE=0; //595 enable on all data out
for(iii=0;iii<200;iii++); //dealy 100
}
}
}
//////////////////////////////////////////////////////////////////
///display end ////
//////////////////////////////////////////////////////////////////
////////////////////////////////
///cheknumber out start ////
////////////////////////////////
chekout()
{
uchar i ;
DS1=1;
MR1=0;MR1=1; //begin datashfit
dseriout=58-seriout;
for(i=0;i<dseriout;i++) //seriout the number out of need
{
STCP1=0; SHCP1=0; //pluse down for ready
STCP1=1; SHCP1=1; //clok pluse up data_bit out
DS1=0; //in bit clear
}
OE1=0; //595 enable on all data out
}
////////////////////////////////
///cheknumber out end ////
////////////////////////////////
////////////////////////////////
///cheknumber in start ////
////////////////////////////////
chekin()
{
uchar i,ii=0;
SHL=0;SHL=1;
INH=0;S1=0;
for (i=1;i<32;i++) //loop 32 bit in code
{
CLK=0;CLK=1; //clok
if(SO==1) //find code in
{ii++;seriin=32-ii; } //record the in code
else
{ii++;} //no in code find the buffer++
}
}
////////////////////////////////
///cheknumber in end /////
////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -