资源描述:
《门禁系统源程序.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineDATAP0//1602驱动端口sbitRS=P2^0;sbitRW=P2^1;sbitE=P2^2;sbitKA=P2^7;intPre_KeyNo=16,KeyNo=16;voiddelayMs(intx);voidKeys_Scan();voidBusy()//LED液晶是否忙碌{DATA=0xff;RS=0;RW=1;while(DATA&0x80){E=0;E=1;}E=0;}//LED写指令程序voidWriteCommand(unsigned
2、charbtCommand){Busy();RS=0;RW=0;E=1;DATA=btCommand;E=0;}//LED写数据程序voidWriteData(unsignedcharbtData){Busy();RS=1;RW=0;E=1;DATA=btData;E=0;}//LED清屏显示voidClear(){WriteCommand(1);}//LED初始化voidInit(){WriteCommand(0x0c);//开显示,无光标显示WriteCommand(0x06);//文字不动,光标自动右移WriteCommand(0x3
3、8);//设置显示模式:8位2行5x7点阵WriteCommand(0x40);//for(i=0;i<24;i++)//日字产生//WriteData(rizi[i]);}//LED显示单个字符voidDisplayOne(bitbRow,unsignedcharbtColumn,unsignedcharbtData,bitbIsNumber){if(bRow)WriteCommand(0xc0+btColumn);elseWriteCommand(0x80+btColumn);if(bIsNumber)WriteData(btData+
4、0x30);elseWriteData(btData);}voidKeys_Scan(){charTmp;P1=0x0f;delayMs(1);Tmp=P1^0x0f;switch(Tmp){case1:KeyNo=0;break;case2:KeyNo=1;break;case4:KeyNo=2;break;case8:KeyNo=3;break;default:KeyNo=16;}P1=0xf0;delayMs(1);Tmp=P1>>4^0x0f;switch(Tmp){case1:KeyNo+=0;break;case2:KeyNo+
5、=4;break;case4:KeyNo+=8;break;case8:KeyNo+=12;}}voiddelayMs(intx){chart;while(x--)for(t=0;t<120;t++);}voidmain(){inthang=0,c=0;inti,j=0;unsignedchartab[12],tab1[12]={1,1,1,1,1,1};unsignedchartab3[]="welcometo...";unsignedchartab4[]="alterpassword...";unsignedchartab5[]="OK
6、";unsignedchartab6[]="NO";Init();loop1:Clear();i=0;KeyNo=16;while(1){WriteCommand(0x80);for(c=0;c<14;c++)WriteData(tab3[c]);P1=0xf0;if(P1!=0xf0)Keys_Scan();if(Pre_KeyNo!=KeyNo){if(KeyNo>=0&&KeyNo<=9){tab[i++]=KeyNo;DisplayOne(1,i,'*',0);//DisplayOne(0,i,KeyNo,1);}if(KeyNo=
7、=14){while(P1!=0xf0);gotoloop1;}if(KeyNo==11)KA=1;if(KeyNo==10){for(j=0;j<6;j++)if(tab[j]!=tab1[j])break;if(j==6){KA=0;for(j=0;j<6;j++)tab[j]=0;}while(P1!=0xf0);gotoloop1;}if(KeyNo==12){i=0;WriteCommand(0x80);for(c=0;c<16;c++)WriteData(tab4[c]);while(1){KeyNo=16;P1=0xf0;if
8、(P1!=0xf0)Keys_Scan();if(Pre_KeyNo!=KeyNo){if(KeyNo>=0&&KeyNo<=9){tab1[i++]=KeyNo;Display