国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee

ELEOK

標(biāo)題: 51單片機(jī)電子密碼鎖程序 3x3矩陣按鍵Proteus仿真 [打印本頁(yè)]

作者: eng    時(shí)間: 2021-6-25 02:47
標(biāo)題: 51單片機(jī)電子密碼鎖程序 3x3矩陣按鍵Proteus仿真
3*3矩陣按鍵 繼電器控制密碼正確與錯(cuò)誤
兩個(gè)LED燈顯示報(bào)警和密碼正確
LCD1602顯示屏顯示密碼
仿真原理圖如下(proteus仿真工程文件和完整單片機(jī)c源碼可到本帖附件中下載)

部分源碼:完整源碼見附件
  1. include<reg51.h>
  2. #define ulong unsigned long
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. uchar temp,num,flag,r;
  6. uchar code table1[]="welcome!       ";
  7. uchar code table2[]="enter password";
  8. uchar code table3[]="012345";
  9. uchar code table4[]="code is wrong!";
  10. uchar code table5[]="you are right!";
  11. uchar code table6[]="the second time!";
  12. uchar code table7[]="the last time!";
  13. uchar code table8[]="Input new code:";
  14. uchar code table9[]="calling.....";
  15. uchar code table10[]="password";
  16. uchar code table11[]="    ";
  17. uchar code table12[]="Modify right!!!";
  18. uchar code table13[]="Input again:";
  19. uchar code table14[]="Modify error!!!";
  20. uchar init_pswd[4]={2,3,0,5};
  21. uchar pswd[4]={0};
  22. sbit lcdrs=P2^0; //LCD數(shù)據(jù)/指令(H/L)選擇端
  23. sbit lcdrw=P2^1;
  24. sbit lcden=P2^2; //LCD使能
  25. sbit P1_6=P1^6;
  26. sbit P2_6=P2^6;//報(bào)警指示燈
  27. sbit P2_7=P2^7;
  28. sbit P3_7=P3^7; //蜂鳴器
  29. /****************子函數(shù)聲明*/
  30. void delay(uint z);
  31. void init();//初始化子函數(shù)
  32. void write_com(uchar com);//寫指令子函數(shù)
  33. void write_data(uchar dat1);//寫數(shù)據(jù)子函數(shù)
  34. uint keyscan();
  35. void mima();//密碼處理子函數(shù)
  36. void mima1();//修改密碼函數(shù)
  37. void Alarm(uchar t);//報(bào)警函數(shù)
  38. /***************液晶驅(qū)動(dòng)*/
  39. void init()
  40. {
  41. lcden=0;
  42. write_com(0x38);
  43. write_com(0x0e);
  44. write_com(0x06);
  45. write_com(0x01);
  46. write_com(0x80);
  47. }
  48. void write_com(uchar com)
  49. {
  50. lcdrs=0;
  51. lcdrw=0;
  52. P0=com;
  53. delay(5);
  54. lcden=1;
  55. delay(5);
  56. lcden=1;
  57. delay(5);
  58. lcden=0;
  59. }
  60. void write_data(uchar dat1)
  61. {
  62. lcdrs=1;
  63. lcdrw=0;
  64. P0=dat1;
  65. delay(5);
  66. lcden=1;
  67. delay(5);
  68. lcden=0;
  69. }
  70. void delay(uint z) //延時(shí)子函數(shù) z*1ms
  71. {
  72. uint x,y;
  73. for(x=z;x>0;x--)
  74. for(y=110;y>0;y--);
  75. }
  76. uint keyscan() //鍵盤掃描程序
  77. {
  78. P1=0xfe; //先選定第一行
  79. temp=P1;
  80. temp=temp&0xf8; //列線全為1,行線為0
  81. while(temp!=0xf8)
  82. {
  83. delay(15); //延時(shí)去抖
  84. temp=P1;
  85. temp=temp&0xf8;
  86. while(temp!=0xf8)
  87. {
  88. temp=P1;
  89. switch(temp) //判斷哪列按下
  90. {
  91. case 0xf6:num=0;flag=1;break;//第一列按下
  92. case 0xee:num=1;flag=1;break;//第二列按下
  93. case 0xde:num=2;flag=1;break;//第三列按下
  94. }
  95. while(temp!=0xf8)
  96. {
  97. temp=P1;
  98. temp=temp&0xf8;
  99. }
  100. }
  101. }
  102. P1=0xfd; //選定第二行,列線為1
  103. temp=P1;
  104. temp=temp&0xf8;
  105. while(temp!=0xf8)
  106. {
  107. delay(15);
  108. temp=P1;
  109. temp=temp&0xf8;
  110. while(temp!=0xf8)
  111. {
  112. temp=P1;
  113. switch(temp) //判斷哪列按下
  114. {
  115. case 0xf5:num=3;flag=1;//第一列按下
  116. break;
  117. case 0xed:num=4;flag=1;//第二列按下
  118. break;
  119. case 0xdd:num=5;flag=1;//第三列按下
  120. break;
  121. }
  122. while(temp!=0xf8)
  123. {
  124. temp=P1;
  125. temp=temp&0xf8;

  126. ……………………

  127. …………限于本文篇幅 余下代碼請(qǐng)下載附件…………
復(fù)制代碼
完整單片機(jī)源程序和proteus仿真文件.zip (101.18 KB, 售價(jià): 2 E幣)






歡迎光臨 ELEOK (http://m.afoofa.cn/) Powered by Discuz! X5.0