找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1267|回复: 0
收起左侧

求大佬帮看看为什么LCD1602不显示?

[复制链接]
ID:784213 发表于 2020-6-19 15:52 | 显示全部楼层 |阅读模式
  1. #include<reg52.h>
  2. #include<intrins.h>
  3. #define uchar unsigned char
  4. static unsigned char table[6]={0,0,0,0,0,0};
  5. //Declare functions
  6. uchar Busy_Check();
  7. void Initialize_LCD();
  8. void Weite_LCD_Date(uchar dat);
  9. void Write_LCD_Command(uchar cmd);
  10. void Display_String(uchar x,uchar y,uchar *str);
  11. void Display_char(uchar hang,uchar lie,char sign);
  12. //
  13. void write_add(uchar address,uchar date);//向AT24C中的指定地址写入数据
  14. uchar read_add(uchar address);//从AT24Cxx中的指定地址读取数据
  15. void init();

  16. uchar h=20;
  17. sbit touch=P2^1;
  18. sbit touch1=P2^2;
  19. sbit speaker=P2^0;

  20. void delay(unsigned char ms)  //延时**ms
  21. {
  22.   unsigned char i;
  23.   while(ms--)
  24.   {
  25.    for(i=250;i>0;i--)
  26.    {
  27.     _nop_();
  28.     _nop_();
  29.     _nop_();
  30.     _nop_();
  31.    }
  32.   }
  33. }
  34. unsigned char keyscan()      //扫描键盘
  35. {
  36.   unsigned char temp,y,j;
  37.   unsigned char anjian[]={0xfe,0xfd,0xfb,0xf7};
  38.   for(y=0;y<4;y++)
  39.   {
  40.    P1=anjian[y];
  41.    temp=0x10;
  42.    for(j=0;j<4;j++)
  43.    {
  44.     if(!(P1&temp))
  45.     {
  46.      return(j+y*4);
  47.     }
  48.     temp=_crol_(temp,1);
  49.    }
  50.   return 16;}
  51. }
  52. void judge()
  53. {
  54.   P1=0xf0;
  55.   if(P1!=0xf0)     //判断是否有按键
  56.   {
  57.    delay(50);
  58.    delay(50);   //消抖
  59.    if(P1!=0xf0)
  60.    {
  61.    h=keyscan();
  62.   }
  63. }
  64. }
  65. void main()
  66. {
  67. /*unsigned char a=1,i=0,k=0,l=1,m=1,n,f=0,s=0;
  68. int  q;*/
  69. Initialize_LCD();
  70. init();
  71. Display_String(1,1,"Welcome To Use");
  72. Display_String(2,1,"              ");
  73. touch1=0;
  74. /*//第一个while循环
  75. while(1)
  76. {
  77.   judge();
  78.   if(h<10)
  79.   {
  80.    if(h==table[i])
  81.     k++;
  82.    
  83.    Display_String(2,a,"*");
  84.    a++;
  85.    i++;
  86.    if(a==7)
  87.     a=1;
  88.    if(i==6)
  89.     i=0;
  90.    h=16;
  91.    
  92.    
  93.   }
  94.   
  95.   if(h==14)
  96.   {
  97.    Display_String(1,1,"Input Password");
  98.    Display_String(2,1,"              ");
  99.      h=16;
  100.      touch=1;
  101.      touch1=0;
  102.      k=0;
  103.      l=1;
  104.      q=0;
  105.   }
  106.   
  107.   if(h==12)
  108.     {
  109.       if(k==6)
  110.             {
  111.       
  112.      Display_String(1,1,"Password Right");
  113.      Display_String(2,1,"Lock  Opened!");
  114.             touch=!touch;
  115.      }
  116.      else
  117.       
  118.      {
  119.       Display_String(1,1,"Password Error");
  120.       Display_String(2,1,"              ");
  121.       i=0;
  122.       q++;
  123.       
  124.       while(q==3)
  125.       {
  126.        speaker=0;
  127.        delay(200);
  128.        delay(200);
  129.        delay(200);
  130.        speaker=1;
  131.        q=0;
  132.       }
  133.       h=14;
  134.      }
  135.      delay(255);
  136.      
  137.      k=0;
  138.      h=16;
  139.      while(1)
  140.      {
  141.       judge();
  142.       if(h==11)
  143.       {  Display_String(1,1,"New   Code");
  144.         Display_String(2,1,"          ");
  145.        while(m==1)
  146.        {
  147.         judge();
  148.         touch1=!touch1;
  149.         if(h<10)
  150.         {
  151.          
  152.          table[n]=h;
  153.          write_add(s,h);
  154.          s++;
  155.          
  156.          
  157.          
  158.          Display_String(2,a,"*");
  159.          a++;
  160.          n++;
  161.          h=16;
  162.          if(n==6)
  163.          {
  164.           n=0;
  165.           s=0;
  166.          }
  167.         }
  168.         if(h==15)
  169.         {
  170.          if(n==0)
  171.           n=6;
  172.            s=6;
  173.          a--;
  174.          s--;
  175.          Display_String(2,a," ");
  176.          n--;
  177.          h=16;
  178.          
  179.         }
  180.         if(h==13)
  181.          m=0;
  182.         
  183.         
  184.        }
  185.        if(h==13)
  186.         h=13;
  187.        f=1;
  188.       }
  189.       if(h==14)
  190.       {
  191.          l=0;
  192.      }
  193.       if(h==13)
  194.       {
  195.        Display_String(2,1,"           ");
  196.       
  197.        for(n=0;n<6;n++)
  198.         Display_char(2,n+1,(uchar)(table[n]+48));h=13;l=0,f=1;}
  199.       
  200.        k=0;
  201.              }
  202. }
  203.    if(h==15)
  204.    {
  205.     a--;
  206.     Display_String(2,a," ");
  207.     k--;
  208.     i--;
  209.     h=16;
  210.    }
  211.    if(h==13)
  212.    {   if(f==1)
  213.     { for(n=0;n<6;n++)
  214.      Display_char(2,n+1,(uchar)(table[n]+48)  );f=0;}
  215.     else
  216.      Display_String(2,1,"     ******     ");
  217.       delay(255);
  218.    delay(255);
  219.     Display_String(1,1," Welcome To Use ");
  220.   Display_String(2,1,"                ");
  221.    
  222.     l=1,a=1;k=0;n=0;m=1;
  223.     h=16;
  224.    }
  225.    
  226.    
  227.   }
  228.   for(s=0;s<6;s++)
  229.   { table[s]=read_add(s);
  230.    delay(50);
  231.               }
  232.     }*/
  233.    
复制代码

电路图

电路图
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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