找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 938|回复: 7
收起左侧

请各位大佬帮我看看为啥我的单片机LCD1602仿真显示不出来?

[复制链接]
ID:1026584 发表于 2023-3-25 22:26 | 显示全部楼层 |阅读模式
3.png

代码如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char

sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^4;
uint i,j;
uchar num;
uchar code table1[]="YL51   MCU";
uchar code table2[]="000000000000";

void delay(uint x)
{
        for(i=x;i>0;i--)
        {
        for(j=120;j>0;j--);
        }
}
void write_com(uchar com)
        {
                RS=0;
                RW=0;
                E=0;
                P2=com;
                E=1;
                delay(5);
                E=0;
        }
void write_data(uchar dat)
{
        RS = 1;  
        RW = 0;  
        E=0;
        P2 = dat;  
        E = 1;
        delay(5);  
        E = 0;  
}
void init()
{
         write_com(0x38);
         write_com(0x08);
         write_com(0x01);
         write_com(0x06);
}
void main()
{
        init();
        for(num=0;num<9;num++)
        {
                write_data(table1[num]);
                delay(300);
        }
        write_com(0x80+0x40);
        for(num=0;num<16;num++)
        {
                write_data(table2[num]);
                delay(300);
        }
        while(1);
}


回复

使用道具 举报

ID:161164 发表于 2023-3-25 23:00 | 显示全部楼层
  1. void init()
  2. {
  3.          write_com(0x38);
  4.          write_com(0x0C);
  5.          write_com(0x01);
  6.          write_com(0x06);
  7. }
复制代码


回复

使用道具 举报

ID:1026584 发表于 2023-3-25 23:13 | 显示全部楼层
回复

使用道具 举报

ID:94031 发表于 2023-3-26 06:51 | 显示全部楼层

初始化改一下:
void init()
{
        RW=0;
        write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
        write_com(0x01);//显示清零,数据指针清零
        write_com(0x0c);//设置开显示,不显光标
        write_com(0x06);//设置写一个字符后地址指针加1
        write_com(0x80);//数据指
}
回复

使用道具 举报

ID:213173 发表于 2023-3-26 06:55 | 显示全部楼层
  1. #include<reg52.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char

  4. sbit RS=P3^5;
  5. sbit RW=P3^6;
  6. sbit E=P3^4;
  7. uint i,j;
  8. uchar num;
  9. uchar code table1[]="YL51   MCU";
  10. uchar code table2[]="000000000000";

  11. void delay(uint x)
  12. {
  13.         for(i=x;i>0;i--)
  14.         {
  15.                 for(j=120;j>0;j--);
  16.         }
  17. }
  18. void write_com(uchar com)
  19. {
  20.         RS=0;
  21.         P2=com;
  22.         E=1;
  23.         delay(1);
  24.         E=0;
  25. }
  26. void write_data(uchar dat)
  27. {
  28.         RS=1;  
  29.         P2=dat;  
  30.         E=1;
  31.         delay(1);  
  32.         E=0;  
  33. }
  34. void init()
  35. {
  36.         E=0;
  37.         RW=0;
  38.         write_com(0x38);
  39.         write_com(0x0c);
  40.         write_com(0x01);
  41.         write_com(0x06);
  42. }
  43. void main()
  44. {
  45.         init();
  46.         write_com(0x80);
  47.         for(num=0;num<10;num++)
  48.         {
  49.                 write_data(table1[num]);
  50.                 delay(100);
  51.         }
  52.         write_com(0x80+0x40);
  53.         for(num=0;num<12;num++)
  54.         {
  55.                 write_data(table2[num]);
  56.                 delay(100);
  57.         }
  58.         while(1);
  59. }
复制代码
回复

使用道具 举报

ID:1026584 发表于 2023-3-26 09:07 | 显示全部楼层

非常感谢,已经可以了。
麻烦能说明一下我代码的问题吗?我实在看不出来哪里有问题
回复

使用道具 举报

ID:213173 发表于 2023-3-26 17:05 | 显示全部楼层
qzusergod 发表于 2023-3-26 09:07
非常感谢,已经可以了。
麻烦能说明一下我代码的问题吗?我实在看不出来哪里有问题

就是在你的程序基础上改的,你逐句对比不就知道哪里有问题?
回复

使用道具 举报

ID:1026584 发表于 2023-3-27 15:27 | 显示全部楼层
wulin 发表于 2023-3-26 17:05
就是在你的程序基础上改的,你逐句对比不就知道哪里有问题?

ok感谢
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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