S6---S15 数字键0-9
S16---更改密码 S17---更改密码完毕后确认
S18---重试密码、重新设定 S19---关闭密码锁
初始密码:000000 密码位数:6位
注意:掉电后,所设密码会丢失,重新上点时,密码恢复为原始的000000
与P1相连的8位发光LED点亮代表锁被打开;熄灭代表锁被锁上
程序功能: 本程序结合了24C02存储器的存储功能,可以掉电保存密码。
第一次运行时,若输入000000原始密码后无反应,可以试验着将主程序中前面的
一小段被注释线屏蔽的程序前的注释线删掉,然后重新编译下载(可以将密码还原为000000)。
此后,再将这小段程序屏蔽掉,再编译下载。方可正常使用。
1、开锁:
下载程序后,直接按六次S7(即代表数字1),8位LED亮,锁被打开,输入密码时,
六位数码管依次显示小横杠。
2、更改密码:
只有当开锁(LED亮)后,该功能方可使用。
首先按下更改密码键S16,然后设置相应密码,此时六位数码管会显示设置密码对应
的数字。最后设置完六位后,按下S17确认密码更改,此后新密码即生效。
3、重试密码:
当输入密码时,密码输错后按下键S18,可重新输入六位密码。
当设置密码时,设置中途想更改密码,也可按下此键重新设置。
4、关闭密码锁:
按下S19即可将打开的密码锁关闭。
推荐初级演示步骤:输入原始密码000000---按下更改密码按键S16---按0到9设置密码---按S17
确认密码更改---按S18关闭密码锁---输入新的密码打开密码锁
*******************************************************************************/
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar old1,old2,old3,old4,old5,old6//原始密码000000
uchar new1,new2,new3,new4,new5,new6 //每次MCU采集到的密码输入
uchar a=16,b=16,c=16,d=16,e=16,f=16//送入数码管显示的变量
uchar wei,key,temp
bit allow,genggai,ok,wanbi,retry,close //各个状态位
sbit dula=P2^6
sbit wela=P2^7
sbit beep=P2^3
sbit sda=P2^0 //IO口定义
sbit scl=P2^1
unsigned char code table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40}
/*****************IIC芯片24C02存储器驱动程序************************************/
void nop()
{
_nop_()
_nop_()
}
/////////24C02读写驱动程序////////////////////
void delay1(unsigned int m)
{ unsigned int n
for(n=0n<mn++)
}
void init() //24c02初始化子程序
{
scl=1
nop()
sda=1
nop()
}
void start()//启动I2C总线
{
sda=1
nop()
scl=1
nop()
sda=0
nop()
scl=0
nop()
}
void stop() //停止I2C总线
{
sda=0
nop()
scl=1
nop()
sda=1
nop()
}
void writebyte(unsigned char j) //写一个字节
{
unsigned char i,temp
temp=j
for (i=0i<8i++)
{
temp=temp<<1
scl=0
nop()
sda=CY //temp左移时,移出的值放入了CY中
nop()
scl=1 //待sda线上的数据稳定后,将scl拉高
nop()
}
scl=0
nop()
sda=1
nop()
}
unsigned char readbyte() //读一个字节
{
unsigned char i,j,k=0
scl=0nop()sda=1
for (i=0i<8i++)
{
nop()scl=1nop()
if(sda==1)
j=1
else
j=0
k=(k<<1)|j
scl=0
}
nop()
return(k)
}
void clock() //I2C总线时钟
{
unsigned char i=0
scl=1
nop()
while((sda==1)&&(i<255))
i++
scl=0
nop()
}
////////从24c02的地址address中读取一个字节数据/////
unsigned char read24c02(unsigned char address)
{
unsigned char i
start()
writebyte(0xa0)
clock()
writebyte(address)
clock()
start()
writebyte(0xa1)
clock()
i=readbyte()
stop()
delay1(100)
return(i)
}
//////向24c02的address地址中写入一字节数据info/////
void write24c02(unsigned char address,unsigned char info)
{
start()
writebyte(0xa0)
clock()
writebyte(address)
clock()
writebyte(info)
clock()
stop()
delay1(5000)//这个延时一定要足够长,否则会出错。因为24c02在从sda上取得数据后,还需要一定时间的烧录过程。
}
/****************************密码锁程序模块********************************************************/
void delay(unsigned char i)
{
uchar j,k
for(j=ij>0j--)
for(k=125k>0k--)
}
void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f)
{
dula=0
P0=table[a]
dula=1
dula=0
wela=0
P0=0xfe
wela=1
wela=0
delay(5)
P0=table[b]
dula=1
dula=0
P0=0xfd
wela=1
wela=0
delay(5)
P0=table[c]
dula=1
dula=0
P0=0xfb
wela=1
wela=0
delay(5)
P0=table[d]
dula=1
dula=0
P0=0xf7
wela=1
wela=0
delay(5)
P0=table[e]
dula=1
dula=0
P0=0xef
wela=1
wela=0
delay(5)
P0=table[f]
dula=1
dula=0
P0=0xdf
wela=1
wela=0
delay(5)
}
void keyscan()
{
{
P3=0xfe
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xee:
key=0
wei++
break
case 0xde:
key=1
wei++
break
case 0xbe:
key=2
wei++
break
case 0x7e:
key=3
wei++
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
}
}
P3=0xfd
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xed:
key=4
wei++
break
case 0xdd:
key=5
wei++
break
case 0xbd:
key=6
wei++
break
case 0x7d:
key=7
wei++
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
}
}
P3=0xfb
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xeb:
key=8
wei++
break
case 0xdb:
key=9
wei++
break
case 0xbb:
genggai=1
wei=0
break
case 0x7b:
if(allow)
ok=1
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
}
}
P3=0xf7
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xe7:
retry=1
break
case 0xd7:
close=1
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
}
}
}
}
void shumima() //对按键采集来的数据进行分配
{
if(!wanbi)
{
switch(wei)
{
case 1:new1=key
if(!allow) a=17
else a=key break
case 2:new2=key
if(a==17) b=17
else b=key break
case 3:new3=key
if(a==17) c=17
else c=key break
case 4:new4=key
if(a==17) d=17
else d=key break
case 5:new5=key
if(a==17) e=17
else e=key break
case 6:new6=key
if(a==17) f=17
else f=key
wanbi=1 break
}
}
}
void yanzheng() //验证密码是否正确
{
if(wanbi) //只有当六位密码均输入完毕后方进行验证
{
if((new1==old1)&(new2==old2)&(new3==old3)&(new4==old4)&(new5==old5)&(new6==old6))
allow=1 //当输入的密码正确,会得到allowe置一
}
}
void main()
{
init() //初始化24C02
/*********下面的一小段程序的功能为格式化密码存储区。************
******当24c02中这些存储区由于其他程序的运行而导致***************
*******所存数据发生了变化,或者密码遗忘时, ********************
******可以删掉其前面的注释线,然后重新编译下载。****************
******而将密码还原为000000后,请将下面的程序用******************
******注释屏蔽掉,重新编译、下载,方可正常使用****************/
// write24c02(110,0x00)
// write24c02(111,0x00)//24c02的第110到115地址单元作为密码存储区
// write24c02(112,0x00)
// write24c02(113,0x00)
// write24c02(114,0x00)
// write24c02(115,0x00)
/*******************************************************************/
old1=read24c02(110)
old2=read24c02(111)
old3=read24c02(112)
old4=read24c02(113)
old5=read24c02(114)
old6=read24c02(115)
while(1)
{
keyscan()
shumima()
yanzheng()
if(allow) //验证完后,若allow为1,则开锁
{
P1=0x00
if(!genggai)
wanbi=0
}
if(genggai) //当S16更改密码键被按下,genggai会被置一
{
if(allow) //若已经把锁打开,才有更改密码的权限
{
while(!wanbi) //当新的六位密码没有设定完,则一直在这里循环
{
keyscan()
shumima()
if(retry|close) //而当探测到重试键S18或者关闭密码锁键S19被按下时,则跳出
{ wanbi=1
break
}
display(a,b,c,d,e,f)
}
}
}
if(ok) //更改密码时,当所有六位新密码均被按下时,可以按下此键,结束密码更改
{ //其他时间按下此键无效
ok=0wei=0
genggai=0
old1=new1old2=new2old3=new3//此时,旧的密码将被代替
old4=new4old5=new5old6=new6
//新密码写入存储区。
write24c02(110,old1)
write24c02(111,old2)
write24c02(112,old3)
write24c02(113,old4)
write24c02(114,old5)
write24c02(115,old6)
a=16b=16c=16d=16e=16f=16
}
if(retry) //当重试按键S18被按下,retry会被置位
{
retry=0wei=0wanbi=0
a=16b=16c=16d=16e=16f=16
new1=0new2=0new3=0new4=0new5=0new6=0
}
if(close) //当关闭密码锁按键被按下,close会被置位
{
close=0genggai=0//所有变量均被清零。
wei=0 wanbi=0
allow=0
P1=0xff
a=16b=16c=16d=16e=16f=16
new1=0new2=0new3=0new4=0new5=0new6=0
}
display(a,b,c,d,e,f)//实时显示
}
}
对着代码自己做吧,,要是还做不出来,,那我就不说什么了,,
首先得说明我这个可是自己原创手打的,但是没去仿真了,程序可能有错误,你自己修改下吧#include<reg52.h>
typedef unsigned char uchar
typedef unsigned int uint
sbit key1=P0^0
sbit key2=P0^1
sbit key3=P0^2
sbit key4=P0^3
sbit wela=P2^0//位锁存端
#define SMG P1
sbit LED=P3^0//低电平亮
uchar code table[]={0x8d,0x86}//共阳数码管 P,E
uchar chushi_mima[]={2,1,3}
uchar shuru_mima[3]
uchar index//控制输入密码的位数
uchar flag_3s=0//3s标志位
uchar keydown//确定按键变量
#define times 15//去抖时间15Ms
uchar key1_count,key2_count,key3_count,key4_count
void init()
{
wela=0
SMG=0xff
TMOD=0x01
TH0=(65536-1000)/256
TL0=(65536-1000)%256
ET0=1
EA=1
TR0=1
LED=1;
}
void main()
{
init()
while(1)
{
switch(keydown)
{
if(index>2)index=0
case 1:
shuru_mima[index]=0
index++
break
case 2:
shuru_mima[index]=1
index++
break
case 3:
shuru_mima[index]=2
index++
break
case 4:
shuru_mima[index]=3
index++
break
}
flag_3s=0
for(i=0i<3i++)
{
if(shuru_mima[i]==chushi_mima[i])
{
LED=0
wela=1
SMG=table[0]
if(flag_3s)
{
flag_3s=0
wela=0
}
}
else
{
LED=1
wela=1
SMG=table[1]
if(flag_3s)
{
flag_3s=0
wela=0
}
}
}
}
}
void timer0() interrupt 1
{
uchar count
TH0=(65536-1000)/256
TL0=(65536-1000)%256
if(++count>=600)
{
count=0
flag_3s=1
}
/*********1ms中断扫描按键(包含去抖程序)********/
if(!key1&&key1_count!=0)
{
key1_count--
if(key1_count==0)
{
keydown=1
}
}
else if(!key1) key1_count=times
// key2,key3,key4你自己写吧
}
程序设计内容
(1).&nbsp密码的设定,在此程序中密码是固定在程序存储器ROM中,假设预设的密码为“12345”共5位密码。
(2).&nbsp密码的输入问题: 由于采用两个按键来完成密码的输入,那么其中一个按键为功能键,另一个按键为数字键。在输入过程中,首先输入密码的长度,接着根据密码的长度输入密码的位数,直到所有长度的密码都已经输入完毕;或者输入确认功能键之后,才能完成密码的输入过程。进入密码的判断比较处理状态并给出相应的处理过程。
(3).按键禁止功能:初始化时,是允许按键输入密码,当有按键按下并开始进入按键识别状态时,按键禁止功能被激活,但启动的状态在3次密码输入不正确的情况下发生的。
C语言源程序
#include unsigned char code ps[]={1,2,3,4,5}
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66, &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40}
unsigned char pslen=9 unsigned char templen
unsigned char digit unsigned char funcount
unsigned char digitcount
unsigned char psbuf[9]
bit cmpflag
bit hibitflag
bit errorflag
bit rightflag
unsigned int second3
unsigned int aa
unsigned int bb
bit alarmflag
bit exchangeflag
unsigned int cc
unsigned int dd
bit okflag
unsigned char oka
unsigned char okb
void main(void)
{ &nbsp
unsigned char i,j &nbsp
P2=dispcode[digitcount] &nbsp
TMOD=0x01 &nbsp
TH0=(65536-500)/256 &nbsp
TL0=(65536-500)%6 &nbsp
TR0=1 &nbsp
ET0=1 &nbsp
EA=1 &nbsp
while(1) &nbsp&nbsp
&nbsp { &nbsp&nbsp&nbsp&nbsp&nbsp
if(cmpflag==0) &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
{ &nbsp&nbsp&nbsp&nbsp&nbsp&nb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