找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1377|回复: 10
收起左侧

如何使1602lcd呈现双行显示还有程序错在哪里了指明一下谢谢

[复制链接]
ID:943830 发表于 2021-11-16 12:26 | 显示全部楼层 |阅读模式
  1. #include<reg51.h>
  2. #include<intrins.h>
  3. sbit RS=0xb0;
  4. sbit RW=0xb1;
  5. sbit E=0xb2;
  6. void lcd_w_cmd(unsigned char com);
  7. void lcd_w_dat(unsigned char dat);
  8. unsigned char lcd_r_start();
  9. void lcd_int();
  10. void delay(unsigned int i);
  11. void delay1();
  12. void main()
  13. {
  14.    unsigned char lcd[]="0123456789ABCDEFG";
  15.    unsigned char lcd[]="HELLO WORLD!" ;
  16.    unsigned char i;
  17.    P1=0xff;
  18.    lcd_int();
  19.    delay(255);
  20.    lcd_w_cmd(0x83);
  21.    delay(255);
  22.    for(i=0;lcd[i]!='\0';i++)
  23.    {  lcd_w_dat(lcd[i]);
  24.       delay(200);   }
  25.           while(i);
  26.    }
  27. void delay1()
  28. {

  29.   _nop_();
  30.   _nop_();
  31.   _nop_();
  32.   }
  33. void lcd_int()
  34. {
  35.    lcd_w_cmd(0x3c);
  36.    lcd_w_cmd(0x0e);
  37.    lcd_w_cmd(0x01);
  38.    lcd_w_cmd(0x06);
  39.    lcd_w_cmd(0x80);
  40.    }
  41. unsigned char lcd_r_start()
  42. {
  43.   unsigned char s;
  44.   RW=1;
  45.   delay1();
  46.   RS=0;
  47.   delay1();
  48.   E=1;
  49.   delay1();
  50.   s=P1;
  51.   delay1();
  52.   E=1;
  53.   delay1();
  54.   RW=0;
  55.   delay1();
  56.   return(s);
  57.   }
  58. void lcd_w_cmd(unsigned char com)
  59. {
  60.   unsigned char i;
  61.   do{
  62.        i=lcd_r_start();
  63.            i&=0x80;
  64.            delay(2);
  65.          }while(i!=0);
  66.        RW=0;
  67.        delay1();
  68.        RS=0;
  69.        delay1();
  70.        E=1;
  71.        delay1();
  72.        P1=com;
  73.        delay1();
  74.        E=0;
  75.        delay1();
  76.        RW=1;
  77.        delay(255);
  78.            }
  79. void lcd_w_dat(unsigned char dat)
  80. {
  81.   unsigned char i;
  82.   do{
  83.        i=lcd_r_start();
  84.            i&=0x80;
  85.            delay(2);
  86.          }while(i!=0);
  87.        RW=0;
  88.        delay1();
  89.        RS=0;
  90.        delay1();
  91.        E=1;
  92.        delay1();
  93.        P1=dat;
  94.        delay1();
  95.        E=0;
  96.        delay1();
  97.        RW=1;
  98.        delay(255);
  99.            }
  100. void delay(unsigned int i)
  101. {unsigned int k;
  102. for(k=0;k<i;k++);
  103. }
复制代码

回复

使用道具 举报

ID:943830 发表于 2021-11-16 12:27 | 显示全部楼层
error C231: 'lcd': redefinition错误原因
回复

使用道具 举报

ID:908826 发表于 2021-11-16 14:36 | 显示全部楼层
我觉得你还是先搞明白如何显示第一行的数据,然后第二行就是在选中位置的时候有一点不同罢了。
回复

使用道具 举报

ID:584814 发表于 2021-11-16 14:37 | 显示全部楼层
   unsigned char lcd[]="0123456789ABCDEFG";
   unsigned char lcd[]="HELLO WORLD!" ;
这是毛意思 ?
回复

使用道具 举报

ID:943830 发表于 2021-11-16 14:38 来自手机 | 显示全部楼层
1602lcd显示双行
回复

使用道具 举报

ID:943830 发表于 2021-11-16 14:42 来自手机 | 显示全部楼层
man1234567 发表于 2021-11-16 14:37
unsigned char lcd[]="0123456789ABCDEFG";
   unsigned char lcd[]="HELLO WORLD!" ;
这是毛意思 ?

unsignedcharlcd[]=“HELLOWORLD”不带这一行上边的可以显示
让第二行显示helloworld!
回复

使用道具 举报

ID:744809 发表于 2021-11-16 15:07 | 显示全部楼层
赢了一切又何妨 发表于 2021-11-16 14:42
unsignedcharlcd[]=“HELLOWORLD”不带这一行上边的可以显示
让第二行显示helloworld!

不能定义相同名字的数组
回复

使用道具 举报

ID:213173 发表于 2021-11-16 17:27 | 显示全部楼层

无标题.jpg

  1. #include<reg51.h>
  2. #include<intrins.h>

  3. sbit RS=0xb0;
  4. sbit RW=0xb1;
  5. sbit E =0xb2;

  6. void lcd_w_cmd(unsigned char com);
  7. void lcd_w_dat(unsigned char dat);
  8. void lcd_r_start();
  9. void lcd_int();
  10. void delay(unsigned int i);

  11. void main()
  12. {
  13.    unsigned char lcd[]="0123456789ABCDEF";
  14.    unsigned char lcd1[]="HELLO WORLD!" ;
  15.    unsigned char i;

  16.    lcd_int();
  17.    lcd_w_cmd(0x80);
  18.    for(i=0;i<16;i++)
  19.                 lcd_w_dat(lcd[i]);
  20.    lcd_w_cmd(0xc2);
  21.    for(i=0;i<12;i++)
  22.                 lcd_w_dat(lcd1[i]);  
  23.         while(1);
  24. }

  25. void lcd_int()
  26. {
  27.         RW=0;
  28.         E =0;
  29.         lcd_w_cmd(0x38);
  30.         lcd_w_cmd(0x01);
  31.         lcd_w_cmd(0x0c);
  32.         lcd_w_cmd(0x06);
  33. }

  34. void lcd_r_start()
  35. {
  36.   unsigned char s;
  37.         P1=0xff;
  38.         RS=0;
  39.         RW=1;
  40.         do
  41.         {
  42.                 E = 1;
  43.                 s = P1;
  44.                 E = 0;    //使能
  45.         }while(s&0x80);
  46. }
  47. void lcd_w_cmd(unsigned char com)
  48. {
  49.         lcd_r_start();
  50.         RW=0;
  51.         RS=0;
  52.         P1=com;
  53.         delay(10);
  54.         E=1;
  55.         delay(10);
  56.         E=0;
  57. }
  58. void lcd_w_dat(unsigned char dat)
  59. {
  60.         lcd_r_start();
  61.         RW=0;
  62.         RS=1;
  63.         P1=dat;
  64.         delay(10);
  65.         E=1;
  66.         delay(10);
  67.         E=0;
  68. }
  69. void delay(unsigned int i)
  70. {
  71.         unsigned int a,b;
  72.         for(a=i;a>0;a--)
  73.                 for(b=10;b>0;b--);
  74. }
复制代码



回复

使用道具 举报

ID:943830 发表于 2021-11-16 18:12 | 显示全部楼层

哥们有isis的全图吗你用的是isis的几我这教室只有isis6和keil2
lcd的灯用的不是1602的
回复

使用道具 举报

ID:213173 发表于 2021-11-16 20:19 | 显示全部楼层
赢了一切又何妨 发表于 2021-11-16 18:12
哥们有isis的全图吗你用的是isis的几我这教室只有isis6和keil2
lcd的灯用的不是1602的

ISIS 7 Professional

无标题.jpg


回复

使用道具 举报

ID:943830 发表于 2021-11-17 09:39 来自手机 | 显示全部楼层
wulin 发表于 2021-11-16 20:19
ISIS 7 Professional

好的明白了  谢谢
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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