登录|立即注册|使用QQ帐号登录
论坛 > 24小时必答区
发帖|
看4372|回2|收藏
楼主 ID:338671 只看他
2019-4-20 21:55
今天使用Proteus自行绘制一个原理图,用来学习LCD602,在Proteus中是没有LCD1602的,所有使用了Lm06l来替代
1)按照我最初的想法是,在第一行显示 who am I 在第二行显示 china的
遇到的问题是,无法在第二行显示数据,write_com(0xC0);经过我自行调试发现问题出现在这里,
我把这句代码删除掉之后,china是跟在who am I 后面显示的
电路原理图
下面是代码

代码:

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

  3. #define uint unsigned int
  4. #define uchar unsigned char
  5.         
  6. void init(void);
  7. void write_com(uchar com);  //写命令函数
  8. void write_data(uint date); //写数据函数
  9. void delay(int z);

  10. sbit lcdrs =P2^7;  //液晶屏数据/命令选择端
  11. sbit lcdrw =P2^6;        //液晶屏读写端
  12. sbit lcden =P2^5;        //使能端

  13. void delay(int z)        //延时1ms
  14. {
  15.         int i,j;
  16.         for(i=0;i<z;i++)
  17.                 for(j=0;j<110;j++);
  18. }

  19. void write_com(uchar com) //写命令函数
  20. {
  21.         lcdrs = 0;
  22.         lcdrw = 0;
  23.         P0 = com;
  24.         delay(5);
  25.         lcden = 0;
  26.         delay(5);
  27.         lcden = 1;
  28.         
  29. }

  30. void write_data(uchar date ) //写数据函数
  31. {
  32.         lcdrs = 1;
  33.         lcdrw = 0;
  34.         P0 = date;
  35.         delay(5);
  36.         lcden = 0;
  37.         delay(5);
  38.         lcden = 1;
  39. }

  40. void init(void)
  41. {
  42.         lcden = 0;//默认使能端是低电平
  43.         lcdrw = 0;
  44.         write_com(0x38);//显示模式设置
  45.         write_com(0x0f);// 开显示,显示光标,光标闪烁
  46.         write_com(0x06);//当读或者写一个字符后地址加一,且光标加一
  47.         //write_com(0x07)当读或者写一个字符后地址加一,且光标加一,且写一个字符,整屏显示左移
  48.         write_com(0x80);
  49. }

  50. void main()
  51. {
  52.         int mun1,mun2,i,j;
  53.         uchar table1[20]="Who am I";
  54.         uchar table2[20]="china";
  55.         
  56.         mun1 = strlen(table1);
  57.         mun2 = strlen(table2);
  58.         init();
  59.         for(i=0;i<mun1;i++)
  60.         {
  61.                 write_data(table1[i]);
  62.                 delay(200);
  63.         }
  64.         
  65.         //重新设置显示指针
  66.         write_com(0xc0);//把指针移到第二行去显示,如果没有这句那么china会接在who am i 后面显示,会发生字符被吞的现象
  67.         
  68.         for(j=0;j<mun2;j++)
  69.         {
  70. write_data(table2[j]);
  71.                 delay(200);
  72.         }
  73.         
  74.         while(1);
  75. }




沙发 ID:213173 只看他
2019-4-21 09:11
错误1.void write_data(uint date);声明写数据函数的参数数据类型错误
错误2.void write_com(uchar com) //写命令函数中lcden逻辑电平错误

错误3.void write_data(uchar date ) //写数据函数中lcden逻辑电平错误

无标题.jpg


代码:

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

  3. #define uint unsigned int
  4. #define uchar unsigned char

  5. void init(void);
  6. void write_com(uchar com);  //写命令函数
  7. void write_data(uchar date); //写数据函数
  8. void delay(int z);

  9. sbit lcdrs =P2^7;  //液晶屏数据/命令选择端
  10. sbit lcdrw =P2^6;        //液晶屏读写端
  11. sbit lcden =P2^5;        //使能端

  12. void delay(int z)        //延时1ms
  13. {
  14.         int i,j;
  15.         for(i=0;i<z;i++)
  16.                 for(j=0;j<110;j++);
  17. }

  18. void write_com(uchar com) //写命令函数
  19. {
  20.         lcdrs = 0;
  21.         lcdrw = 0;
  22.         P0 = com;
  23.         delay(5);
  24.         lcden = 1;
  25.         delay(5);
  26.         lcden = 0;
  27. }

  28. void write_data(uchar date ) //写数据函数
  29. {
  30.         lcdrs = 1;
  31.         lcdrw = 0;
  32.         P0 = date;
  33.         delay(5);
  34.         lcden = 1;
  35.         delay(5);
  36.         lcden = 0;
  37. }

  38. void init(void)
  39. {
  40.         lcden = 0;//默认使能端是低电平
  41.         lcdrw = 0;
  42.         write_com(0x38);//显示模式设置
  43.         write_com(0x0f);// 开显示,显示光标,光标闪烁
  44.         write_com(0x06);//当读或者写一个字符后地址加一,且光标加一
  45. // write_com(0x07)当读或者写一个字符后地址加一,且光标加一,且写一个字符,整屏显示左移
  46.         write_com(0x80);
  47. }

  48. void main()
  49. {
  50.         int mun1,mun2,i,j;
  51.         uchar table1[20]="Who am I";
  52.         uchar table2[20]="china";
  53.        
  54.         mun1 = strlen(table1);
  55.         mun2 = strlen(table2);
  56.         init();
  57.         for(i=0;i<mun1;i++)
  58.         {
  59.                 write_data(table1[i]);
  60.                 delay(200);
  61.         }

  62.         //重新设置显示指针
  63.         write_com(0xc0);
  64.        
  65.         for(j=0;j<mun2;j++)
  66.         {
  67.                 write_data(table2[j]);
  68.                 delay(200);
  69.         }
  70.        
  71.         while(1);
  72. }




板凳 ID:338671 只看他
2019-4-21 11:41
谢谢大佬的答疑,是我对于数据类型理解不到位,

51黑电子论坛

Powered by Discuz! X3.1

首页|标准版|触屏版|电脑版