找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

自己照着书写的单片机程序,但是运行了LCD1602上面什么都不显示,问下哪有问题?

查看数: 2803 | 评论数: 9 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2022-12-21 19:02

正文摘要:

#include <reg51.h> #include <intrins.h> sbit DB=P0; sbit RS=P2^0; sbit RW=P2^1; sbit E=P2^2; void delay(unsigned int z) {         unsigned int x,y;   ...

回复

ID:755966 发表于 2022-12-26 13:24
人人学会单片机 发表于 2022-12-21 21:29
LCD1602液晶最新资料 说明了具体的时间要求 http://www.51hei.com/bbs/dpj-205768-1.html

好的谢谢   
ID:755966 发表于 2022-12-26 13:24
lkc8210 发表于 2022-12-21 21:46
把第3行的sbit DB=P0;
改为#define  DB P0

好的 谢谢
ID:755966 发表于 2022-12-26 13:24
wulin 发表于 2022-12-21 21:13
抄的不仔细,也没有认真检查。

好的 谢谢
ID:755966 发表于 2022-12-26 13:24
陈润源home 发表于 2022-12-21 22:14
sbit DB=P0;   P0是8位   sbit是位定义

好的,谢谢
ID:57657 发表于 2022-12-21 22:22
RV1可能是假的,换成两个电阻试试。
ID:293363 发表于 2022-12-21 22:14
sbit DB=P0;   P0是8位   sbit是位定义   
ID:161164 发表于 2022-12-21 21:46
把第3行的sbit DB=P0;
改为#define  DB P0

把write_com(0x3C);
改为write_com(0x38);
ID:390416 发表于 2022-12-21 21:29
LCD1602液晶最新资料 说明了具体的时间要求 http://www.51hei.com/bbs/dpj-205768-1.html
ID:213173 发表于 2022-12-21 21:13
抄的不仔细,也没有认真检查。


  1. #include <reg51.h>
  2. #include <intrins.h>
  3. #define DB P0
  4. sbit RS=P2^0;
  5. sbit RW=P2^1;
  6. sbit E=P2^2;
  7. void delay(unsigned int z)
  8. {
  9.         unsigned int x,y;
  10.         for(x=z;x>0;x--)
  11.                 for(y=110;y>0;y--);
  12. }

  13. void write_dat(unsigned char dat)
  14. {        
  15.         RW=0;
  16.         RS=1;
  17.         DB=dat;
  18.         delay(5);
  19.         E=1;
  20.         delay(5);
  21.         E=0;
  22. }
  23. void write_com(unsigned char com)
  24. {        
  25.         RW=0;
  26.         RS=0;
  27.         DB=com;
  28.         delay(5);
  29.         E=1;
  30.         delay(5);
  31.         E=0;
  32. }
  33. void lcd_1602init()
  34. {
  35.         RW=0;
  36.         E=0;
  37.         write_com(0x38);
  38.         write_com(0x0c);
  39.         write_com(0x06);
  40.         write_com(0x01);
  41. //        write_com(0x80);
  42. }
  43. void write_sfm(unsigned char add,unsigned char date)
  44. {
  45.         unsigned char shi,ge;
  46.         shi=date/10;
  47.         ge=date%10;
  48.         write_com(0x80+add);
  49.         write_dat(0x30+shi);
  50.         write_dat(0x30+ge);
  51. }
  52. void main()
  53. {
  54.         lcd_1602init();
  55.         write_sfm(0,20);//写第一行
  56.         while(1)
  57.         {
  58.                 write_com(0xc0);//写第二行
  59.                 write_dat('2');
  60.                 write_dat('0');
  61.         }
  62. }
复制代码



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

Powered by 单片机教程网

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