|
自行DIY电磁密码锁 在我的设计中没有用密码存储器 程序在仿真中是没有问题 我也做过实物 但是由于封装的问题 打印的板子不合适 就不能实现功能 还有我的程序还有不足的地方 大家就一起讨论 我也准备用密码存储器来搞 等我搞出来了在分享 我会上传我的PCB设计、仿真设计和程序!
原理图(用AD画的,附件里面有工程文件):
原理图
仿真原理图:
仿真图
pcb文件(用AD画的,附件里面有工程文件):
PCB图
程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uint code jianzhi[]={0xee,0xde,0xbe,0x7e,
- 0xed,0xdd,0xbd,0x7d,
- 0xeb,0xdb,0xbb,0x7b};
- uint code number[]= {0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x90};
- uint mima[]={0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9};
- uchar mima1[6];
- uchar table1[]="Please enter a 7";
-
- uchar table2[]=" bit password !";
-
- uchar table3[]=" Hello user !";
- uchar table4[]="*******";
- sbit rr=P1^0; //绿灯
- sbit rd=P1^1; //蓝灯
- sbit re=P1^2; //红灯
- sbit OK=P3^3; //OK按钮
- sbit delete=P3^4;//delete按钮
- sbit bao=P3^5; //警报器
- sbit rs=P3^5;
- sbit wr=P3^6;
- sbit e=P3^7;
- void delay(uchar del)
- {
- uint i,j;
- for(i=0;i<del;i++)
- for(j=0;j<130;j++);
- }
- void write_com(uchar com)
- {
- P0=com;
- rs=0;
- wr=0;
- e=0;
- delay(1);
- e=1;
- delay(1);
- e=0;
- }
- void write_data(uchar dat)
- {
- P0=dat;
- rs=1;
- wr=0;
- e=0;
- delay(1);
- e=1;
- delay(1);
- e=0;
- }
- void initi()
- {
- write_com(0x38);//16*2显示,5*7点阵,8位数据口
- write_com(0x0c);//开显示,显示光标,光标不闪烁
- write_com(0x06);//地址自动加一,不移屏
- write_com(0x01);//清屏
- }
- void cle()
- {
- write_com(0x01);//清屏
- }
- void xianshi()
- {
- uchar i=0;
- write_com(0x80+0x00);
- while(table1[i]!='\0')
- {
- write_data(table1[i++]);
- delay(1); //显示模块
- }
- i=0;
- write_com(0x80+0x41);
- while(table2[i]!='\0')
- {
- write_data(table2[i++]);
- delay(1); //显示模块
- }
- }
- void xianshi1()
- {
- uchar i=0;
- write_com(0x80+0x00);
- while(table3[i]!='\0')
- {
- write_data(table3[i++]);
- delay(1); //显示模块
- }
- }
- void xianshi2(int b)
- {
- uint i;
- write_com(0x80+0x41);
- for(i=0;i<b+1;i++) //显示自定义字符
- {
- write_data(table4[i]);
- delay(5);
- }
- }
- void panduan()
- {
- uint i,flag;
- for(i=0;i<6;i++)
- if(mima1[i]==mima[i])
- flag=1;
- else
- flag=0;
- if (flag==0)
- {
- re=0;
- delay(1000);
- re=1; //判断模块
- }
- else if (flag==1)
- {
- rr=0;
- delay(1000);
- rr=1;
- }
- }
- void key ()
- {
- uchar zhi,lie,i,j,k=-1,shuzhi=0;
- delay(1000);
- cle();
- xianshi1();
- while(1)
- {
- P2=0xf0;
- if(P2!=0xf0)
- {
- delay(10);
- if(P2!=0xf0)
- {
- lie=P2;
- P2=0x0f;
- zhi=lie|P2;
- for(i=0;i<12;i++)
- {
- if(zhi==jianzhi[i])
- {
- shuzhi=i;
- k++; //按键模块
- rd=0;
- delay(1000);
- rd=1;
- break;
- }
- }
- for(j=k;j<k+1;j++)
- mima1[j]=number[shuzhi];
- xianshi2(k);
- while(P2!=0x0f);
- delay(10);
- }
- }
-
- if(OK==0&&k==6)
- {
- panduan(); //判断调用
- k=-1;
- cle();
- xianshi1();
- }
- if(delete==0)
- {
- for (j=-1;j<k;j++)
- mima[j]=0xc0;
- cle();
- xianshi1();
- k=-1; //清零调用
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
全部设计资料下载:
按键和显示组合pcb电路板.zip
(9.92 MB, 下载次数: 47)
|
|