电子密码锁程序Word格式.docx

上传人:b****5 文档编号:16314860 上传时间:2022-11-22 格式:DOCX 页数:26 大小:21.11KB
下载 相关 举报
电子密码锁程序Word格式.docx_第1页
第1页 / 共26页
电子密码锁程序Word格式.docx_第2页
第2页 / 共26页
电子密码锁程序Word格式.docx_第3页
第3页 / 共26页
电子密码锁程序Word格式.docx_第4页
第4页 / 共26页
电子密码锁程序Word格式.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

电子密码锁程序Word格式.docx

《电子密码锁程序Word格式.docx》由会员分享,可在线阅读,更多相关《电子密码锁程序Word格式.docx(26页珍藏版)》请在冰豆网上搜索。

电子密码锁程序Word格式.docx

unsignedcharcodename[]={"

===CodedLock==="

//显示名称

unsignedcharcodeCorrect[]={"

correct"

//输入正确

unsignedcharcodeError[]={"

error"

//输入错误

unsignedcharcodecodepass[]={"

pass"

unsignedcharcodeLockOpen[]={"

open"

//OPEN

unsignedcharcodeSetNew[]={"

SetNewWordEnable"

unsignedcharcodeInput[]={"

input:

//INPUT

unsignedcharcodeResetOK[]={"

ResetPasswordOK"

unsignedcharcodeinitword[]={"

Initpassword..."

unsignedcharcodeEr_try[]={"

error,tryagain!

"

unsignedcharcodeagain[]={"

inputagain"

unsignedcharInputData[6];

//输入密码暂存区

unsignedcharCurrentPassword[6]={1,3,1,4,2,0};

//当前密码值

unsignedcharTempPassword[6];

unsignedcharN=0;

//密码输入位数记数

unsignedcharErrorCont;

//错误次数计数

unsignedcharCorrectCont;

//正确输入计数

unsignedcharReInputCont;

//重新输入计数

unsignedcharcodeinitpassword[6]={0,0,0,0,0,0};

//=====================5ms延时==============================

voidDelay5Ms(void)

{

unsignedintTempCyc=5552;

while(TempCyc--);

}

//===================400ms延时==============================

voidDelay400Ms(void)

unsignedcharTempCycA=5;

unsignedintTempCycB;

while(TempCycA--)

{

TempCycB=7269;

while(TempCycB--);

}

//=============================================================================================

//================================24C02========================================================

voidmDelay(uintt)//延时

{

uchari;

while(t--)

{

for(i=0;

i<

125;

i++)

{;

}

voidNop(void)//空操作

_nop_();

/*起始条件*/

voidStart(void)

Sda=1;

Scl=1;

Nop();

Sda=0;

/*停止条件*/

voidStop(void)

/*应答位*/

voidAck(void)

Sda=0;

Nop();

Scl=1;

Scl=0;

/*反向应答位*/

voidNoAck(void)

Scl=0;

/*发送数据子程序,Data为要求发送的数据*/

voidSend(ucharData)

ucharBitCounter=8;

uchartemp;

do

temp=Data;

Scl=0;

Nop();

if((temp&

0x80)==0x80)

Sda=1;

else

Sda=0;

Scl=1;

temp=Data<

<

1;

Data=temp;

BitCounter--;

while(BitCounter);

/*读一字节的数据,并返回该字节值*/

ucharRead(void)

uchartemp=0;

uchartemp1=0;

ucharBitCounter=8;

Sda=1;

do{

if(Sda)

temp=temp|0x01;

else

temp=temp&

0xfe;

if(BitCounter-1)

temp1=temp<

temp=temp1;

BitCounter--;

while(BitCounter);

return(temp);

voidWrToROM(ucharData[],ucharAddress,ucharNum)

uchar*PData;

PData=Data;

for(i=0;

Num;

Start();

Send(0xa0);

Ack();

Send(Address+i);

Send(*(PData+i));

Stop();

mDelay(20);

voidRdFromROM(ucharData[],ucharAddress,ucharNum)

Send(0xa1);

*(PData+i)=Read();

NoAck();

//==================================================================================================

//=======================================LCD1602====================================================

#defineyi0x80//LCD第一行的初始位置,因为LCD1602字符地址首位D7恒定为1(100000000=80)

#defineer0x80+0x40//LCD第二行初始位置(因为第二行第一个字符位置地址是0x40)

//----------------延时函数,后面经常调用----------------------

voiddelay(uintxms)//延时函数,有参函数

uintx,y;

for(x=xms;

x>

0;

x--)

for(y=110;

y>

y--);

//--------------------------写指令---------------------------

write_1602com(ucharcom)//****液晶写入指令函数****

lcd1602_rs=0;

//数据/指令选择置为指令

lcd1602_rw=0;

//读写选择置为写

P0=com;

//送入数据

delay

(1);

lcd1602_en=1;

//拉高使能端,为制造有效的下降沿做准备

lcd1602_en=0;

//en由高变低,产生下降沿,液晶执行命令

//-------------------------写数据-----------------------------

write_1602dat(uchardat)//***液晶写入数据函数****

lcd1602_rs=1;

//数据/指令选择置为数据

P0=dat;

//en置高电平,为制造下降沿做准备

//en由高变低,产生下降沿,液晶执行命令

//-------------------------初始化-------------------------

voidlcd_init(void)

write_1602com(0x38);

//设置液晶工作模式,意思:

16*2行显示,5*7点阵,8位数据

write_1602com(0x0c);

//开显示不显示光标

write_1602com(0x06);

//整屏不移动,光标自动右移

write_1602com(0x01);

//清显示

//========================================================================================

//=========================================================================================

//==============将按键值编码为数值=========================

unsignedcharcoding(unsignedcharm)

unsignedchark;

switch(m)

case(0x18):

k=1;

break;

case(0x28):

k=2;

case(0x48):

k=3;

case(0x88):

k='

A'

;

case(0x14):

k=4;

case(0x24):

k=5;

case(0x44):

k=6;

case(0x84):

B'

case(0x12):

k=7;

case(0x22):

k=8;

case(0x42):

k=9;

case(0x82):

C'

case(0x11):

*'

case(0x21):

k=0;

case(0x41):

#'

case(0x81):

D'

return(k);

//=====================按键检测并返回按键值===============================

unsignedcharkeynum(void)

unsignedcharrow,col,i;

P1=0xf0;

if((P1&

0xf0)!

=0xf0)

Delay5Ms();

Delay5Ms();

if((P1&

row=P1^0xf0;

//确定行线

i=0;

P1=a[i];

//精确定位

while(i<

4)

{

if((P1&

{

col=~(P1&

0xff);

//确定列线

break;

//已定位后提前退出

}

else

i++;

P1=a[i];

}

else

return0;

while((P1&

=0xf0);

return(row|col);

//行线与列线组合后返回

elsereturn0;

//无键按下时返回0

//=======================一声提示音,表示有效输入========================

voidOneAlam(void)

ALAM=0;

ALAM=1;

//========================二声提示音,表示操作成功========================

voidTwoAlam(void)

//========================三声提示音,表示错误========================

voidThreeAlam(void)

//=====================显示输入的N个数字,用H代替以便隐藏============================

voidDisplayOne(void)

//DisplayOneChar(9+N,1,'

);

write_1602com(yi+5+N);

write_1602dat('

//=======================显示提示输入=========================

voidDisplayChar(void)

unsignedchari;

if(pass==1)

//DisplayListChar(0,1,LockOpen);

write_1602com(er);

for(i=0;

16;

write_1602dat(LockOpen[i]);

if(N==0)

//DisplayListChar(0,1,Error);

write_1602com(er);

write_1602dat(Error[i]);

else

//DisplayListChar(0,1,start_line);

write_1602dat(start_line[i]);

voidDisplayInput(void)

if(CorrectCont==1)

//DisplayListChar(0,0,Input);

write_1602dat(Input[i]);

//========================重置密码==================================================

//==================================================================================

voidResetPassword(void)

unsignedcharj;

if(pass==0)

pass=0;

DisplayChar();

ThreeAlam();

if(ReInputEn==1)

if(N==6)

ReInputCont++;

if(ReInputCont==2)

for(i=0;

6;

{

if(TempPassword[i]==InputData[i])//将两次输入的新密码作对比

i++;

else

{

//DisplayListChar(0,1,Error);

write_1602com(er);

for(j=0;

j<

j++)

{

write_1602dat(Error[j]);

}

ThreeAlam();

//错误提示

pass=0;

ReInputEn=0;

//关闭重置功能,

ReInputCont=0;

DisplayChar();

break;

}

}

if(i==6)

//DisplayListChar(0,1,ResetOK);

write_1602com(er);

for(j=0;

write_1602dat(ResetOK[j]);

TwoAlam();

//操作成功提示

WrToROM(TempPassword,0,6);

//将新密码写入24C02存储

ReInputEn=0;

}

ReInputCont=0;

CorrectCont=0;

else

OneAlam();

//DisplayListChar(0,1,again);

//显示再次输入一次

write_1602com(er);

for(j=0;

write_1602dat(again[j]);

}

TempPassword[i]=InputData[i];

//将第一次输入的数据暂存起来

N=0;

//输入数据位数计数器清零

//=======================输入密码错误超过三过,报警并锁死键盘======================

voidAlam_KeyUnable(void)

P1=0x00;

ALAM=~ALAM;

//=======================取消所有操作============================================

voidCancel(void)

//DisplayListChar(0,1,start_line);

write_1602c

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 学科竞赛

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1