圣源电子制作

 找回密码
 立即注册
查看: 6996|回复: 0

C51四位密码锁-数码管显示-包含仿真文件-C语言程序

[复制链接]
发表于 2011-11-14 10:42:51 | 显示全部楼层 |阅读模式
转载自互联网!!!

20111114102600.jpg

程序:
  1. #include<reg51.h>
  2.   unsigned char lie[]={0xff,0x07,0x0b,0x0d};
  3. unsigned char L,L1=0,L2,L3=0,L4,L5,L6,L7,m,n,a,s,i;
  4. unsigned char shu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  5.   sbit P25=P1^5;


  6.   void delay();
  7.         
  8.          void delay()
  9.          {
  10.          unsigned char i;
  11.          for(i=0;i<200;i++);
  12.          }

  13.   void main()
  14. {
  15. while(1)
  16. {         
  17. P2=0X00;        
  18. P3=0xff;
  19. if(P3!=0xff)
  20. {
  21. delay();
  22. L=0;  L2=0;P25=1;
  23. }
  24. else
  25. {
  26. L=1;
  27. }


  28. if(L==0)
  29. {                  
  30.     for(i=1;i<4;i++)
  31.         {
  32.         delay(); delay(); delay();
  33.         
  34.           P2=lie[i];
  35.         if(P3!=0xff)
  36.         {
  37.          
  38.                           
  39.          

  40.         if(L1==0)
  41.         {if(P3==0xfe){m=0+i;}
  42.         if(P3==0XFd){m=3+i;}
  43.         if(P3==0xfb){m=6+i;}
  44.         }
  45.         if(L1==1)         
  46.         {
  47.         if(P3==0xfe){n=0+i;}
  48.         if(P3==0xfd){n=3+i;}
  49.         if(P3==0xfb){n=6+i;}
  50.         }
  51.         if(L1==2)
  52.         {        
  53.         if(P3==0xfe){a=0+i;}
  54.         if(P3==0xfd){a=3+i;}
  55.         if(P3==0xfb){a=6+i;}
  56.          }
  57.           if(L1==3)
  58.           {
  59.           if(P3==0xfe){s=0+i;}
  60.         if(P3==0xfd){s=3+i;}
  61.         if(P3==0xfb){s=6+i;}
  62.           }           
  63.           while(P3!=0Xff);
  64.           L1++;
  65.           if(L1>3){L1=0;}

  66.           if(m==8){a=s=m=n=L1=0;L2=0;}
  67.           if(n==8){m=n=a=s=L1=0;L2=0;}
  68.           if(a==8){m=n=a=s=L1=0;L2=0;}
  69.           if(s==8){m=n=a=s=L1=0;L2=0;}                                                   
  70.          
  71.            if(m==9){L2=1;a=s=m=n=L1=0;}
  72.            if(n==9){L2=1;a=s=m=n=L1=0;}
  73.            if(a==9){L2=1;a=s=m=n=L1=0;}
  74.            if(s==9){L2=1;a=s=m=n=L1=0;}
  75.          
  76.           }
  77.           }
  78.           }
  79.                



  80.            if(m>0)
  81.            {
  82.            P2=0x80;
  83.            P0=shu[m];
  84.            delay();
  85.            
  86.            }
  87.                 else
  88.                 {
  89.                 P2=0X80;
  90.                
  91.                 P0=0Xbf;
  92.                 delay();
  93.                
  94.                 }
  95.                 if(n>0)
  96.                 {
  97.                 P2=0X40;
  98.                 P0=shu[n];
  99.                 delay();
  100.                
  101.                 }
  102.                 else
  103.                 {
  104.                 P2=0X40;
  105.                 P0=0xbf;
  106.                 delay();
  107.         
  108.                 }
  109.                 if(a>0)
  110.                 {
  111.                 P2=0X20;
  112.                 P0=shu[a];
  113.                 delay();
  114.         
  115.                 }
  116.                 else
  117.                 {
  118.                 P2=0X20;
  119.                 P0=0Xbf;
  120.                 delay();
  121.                
  122.                 }
  123.                 if(s>0)
  124.                 {
  125.                 P2=0x10;
  126.                 P0=shu[s];
  127.                 delay();
  128.         
  129.                 }
  130.                 else
  131.                 {
  132.                 P2=0X10;
  133.                 P0=0Xbf;
  134.                 delay();
  135.         
  136.                 }
  137.            if(L2==0){L7=L6=L5=L4=L3=0;}
  138.            if(m==2)
  139.            { L4=L3+1;}
  140.            if(n==5)
  141.            { L5=L4+1;}
  142.            if(a==6)
  143.            { L6=L5+1;}
  144.            if(s==5)
  145.            { L7=L6+1; }
  146.                   
  147.            if(L7==4)
  148.            {
  149.            if(L2==1)
  150.             {P25=0;} }
  151.            }
  152.            }
  153.                





  154.   
复制代码

下载:
程序.zip (38.31 KB, 下载次数: 84)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|联系我们|闽公网安备 35012102000020号|圣源电子 ( 闽ICP备11020110号 )

GMT+8, 2024-3-29 17:04 , Processed in 0.061478 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表