找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3292|回复: 3
收起左侧

LCD1602显示黑色小方块毫无反应无任何显示,测试了好多的程序

[复制链接]
ID:430097 发表于 2018-11-20 19:23 | 显示全部楼层 |阅读模式
用的是普中科技的51单片机,从网上找了一些lcd的代码把程序烧入单片机后lcd毫无反应,就只是背景板亮再就是lcd的第一行有好多黑色的小方块。下面是其中的一个代码。
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. //这三个引脚参考资料
  5. sbit E=P2^7;                //1602使能引脚
  6. sbit RW=P2^6;                //1602读写引脚        
  7. sbit RS=P2^5;                //1602数据/命令选择引脚

  8. uchar tab1[]="512";  //要显示什么就在这儿改
  9. uchar tab2[]="LCD1602 test ok!";  //[size=15.5555562973022px]要显示什么就在这儿改

  10. void delay(uint del)   //延时1ms
  11. {
  12. uint i,j;
  13. for(i=0;i<del;i++)
  14.    for(j=0;j<=168;j++);
  15. }
  16. void writecmd(uchar com)  //写指令
  17. {
  18. E=0;
  19. RS=0;
  20. RW=0;
  21. P0=com;
  22. delay(2);
  23. E=1;  
  24. delay(2);
  25. E=0;
  26. }
  27. void writedata(uchar dat)//写数据
  28. {  
  29.   E=0;
  30.   RS=1;
  31.   RW=0;
  32.   P0=dat;
  33.   delay(2);
  34.   E=1;  
  35.   delay(2);
  36.   E=0;

  37. }
  38. void init(void)               //初始化
  39. {
  40. delay(15);
  41. writecmd(0x38);
  42. delay(5);
  43. writecmd(0x38);
  44. delay(5);
  45. writecmd(0x38);
  46. writecmd(0x38);
  47. writecmd(0x08);
  48. writecmd(0x01);
  49. writecmd(0x06);
  50. writecmd(0x0c);
  51. }
  52. void main()
  53. {  
  54. uchar j;
  55.   init();
  56.   writecmd(0x80);    //告诉液晶在哪个地方显示 (设置地址指针)//80H+00
  57.   for(j=0;j<16;j++)  //有16个字符,要循环16次
  58.   {
  59.    writedata(tab1[j]);
  60.         delay(2);
  61.   }
  62.   writecmd(0x80+0x40); //再设置第二行的起始位置80H+40H

  63.   for(j=0;j<16;j++)   //有16个字符,要循环16次
  64.   {
  65.   writedata(tab2[j]);
  66.          delay(2);
  67.   }
  68.   while(1);         //让液晶显示就一直停在这里。

  69. }
复制代码


回复

使用道具 举报

ID:1 发表于 2018-11-21 01:22 | 显示全部楼层
这是51黑论坛里面别人相似问题的解决过程:http://www.51hei.com/bbs/dpj-39388-1.html
回复

使用道具 举报

ID:405182 发表于 2018-11-21 08:12 | 显示全部楼层
试试这个
void lcd_initial(void)
{
        RS=0;
        delay(300);
        RW=0;
        ENABLE=1;
        delay(300);
        P0=0x38;
        delay(300);
        ENABLE=0;
        P0=0x06;
        ENABLE=1;
        delay(300);
        ENABLE=0;
        P0=0x0c;         //////
        ENABLE=1;
        delay(300);
        ENABLE=0;
        P0=0x0c;
        ENABLE=1;
        delay(300);
        ENABLE=0;
        P0=0x01;
        ENABLE=1;
        delay(300);
        ENABLE=0;
        P0=0x80;
        ENABLE=1;
        delay(300);
        ENABLE=0;
}
/////
void writecharxy(unsigned char x,unsigned char y,unsigned char c)
{
   switch(x)
        {
                case 0x01:
                {
                        RS=0;
                        delay(300);
                        RW=0;
                        delay(300);
                        ENABLE=1;
                        delay(300);
                        P0=0x80|y;
                        delay(300);
                        ENABLE=0;
                        RS=1;
                        delay(300);
                        RW=0;
                        delay(300);
                        ENABLE=1;
                        delay(300);
                        P0=c;
                        delay(300);
                        ENABLE=0;
                }
                        break;
                case 0x02:
                {
                       
                        RS=0;
                        delay(300);
                        RW=0;
                        delay(300);
                        ENABLE=1;
                        delay(300);
                        P0=0xc0|y;
                        delay(300);
                        ENABLE=0;
                        RS=1;
                        delay(300);
                        RW=0;
                        delay(300);
                        ENABLE=1;
                        delay(300);
                        P0=c;
                        delay(300);
                        ENABLE=0;
                }
                        break;
                default:break;
        }
}
//////
void delay(unsigned int t)
{
for(;t>0;t--);
}
回复

使用道具 举报

ID:423020 发表于 2018-11-24 10:45 | 显示全部楼层
1、写指令、写数据子程序里开始没有读忙,不知道是不是这个问题,可以在一开始加入几个ms的延时替代读忙试一下。
2、也有可能是对比度没有调对,可以适当的增加以下LCD电压试一下。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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