找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2300|回复: 1
打印 上一主题 下一主题
收起左侧

12864液晶显示程序—适合我的51单片机开发板

[复制链接]
跳转到指定楼层
楼主
ID:76556 发表于 2015-4-10 01:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg51.h>
/**********端口定义*************/
sbit RS = P1^0;
sbit RW = P1^1;
sbit E = P1^5;
#define  Date P0   //定义Date口为数据口P0
unsigned char code TV1[]={"这是薛羽豪的液晶"};
unsigned char code TV2[]={"哈哈哈哈哈哈哈哈"};
unsigned char code TV3[]={"056789asdfgh    "};
unsigned char code TV4[]={"!@#¥&*不是乱码"};
void Delays(unsigned int x)                //延时子函数
{  unsigned int i,j;
   for(i=110;i>0;i--)
      for(j=x;j>0;j--);
}
void Write_Instruction(unsigned char Parameter) //写指令(Write/Instruction)。。形参(Parameter)
{
RS=0;
RW=0;
E=0;
Date=Parameter;
Delays(5);
E=1;
Delays(5);
E=0;
}
void Write_Date(unsigned char Parameter) //写数据(Write/Date)。。形参(Parameter)
{
RS=1;
RW=0;
E=0;
Date=Parameter;
Delays(5);
E=1;
Delays(5);
E=0;
}                                                                                   
void init_Lcd()                                                //液晶初始化(init/lcd)
{
Write_Instruction(0x01);
Delays(5);
Write_Instruction(0x0c);
Delays(5);
Write_Instruction(0x30);
Delays(5);
}
void Position_Lcd(unsigned char x,unsigned char y)        //进入点设定,,液晶显示位置(Lcd/Position)
{
unsigned char  Position;
if(x==1)
        {x=0x80;}
else if(x==2)
        {x=0x90;}
else if(x==3)
        {x=0x88;}
else if(x==4)
        {x=0x98;}
Position=x+y;
Write_Instruction(Position);     //显示地址
}
void main()
{
unsigned char Num1;
RS=0;
RW=0;
E=0;
init_Lcd();
Position_Lcd(1,0);
Num1=0;
while(TV1[Num1]!='\0')                //教材P176页讲述了TV1[Num1]!='\0'的意思特别是'\0'的意思("空"在储存器中的存储形式是"\0")
        {
         Write_Date(TV1[Num1]);
         Num1++;
        }
Position_Lcd(2,0);
Num1=0;
while(TV2[Num1]!='\0')
        {
         Write_Date(TV2[Num1]);
         Num1++;
        }
Position_Lcd(3,0);
Num1=0;
while(TV4[Num1]!='\0')
        {
         Write_Date(TV3[Num1]);
         Num1++;
        }
Position_Lcd(4,0);
Num1=0;
while(TV4[Num1]!='\0')
        {
         Write_Date(TV4[Num1]);
         Num1++;
        }
while(1);
}



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:76556 发表于 2015-4-10 01:52 | 只看该作者
基于上一个程序改进后具有更快的刷新速度,程序刷新更快

  1. #include <reg51.h>
  2. /**********端口定义*************/
  3. sbit RS = P1^0;
  4. sbit RW = P1^1;
  5. sbit E = P1^5;
  6. #define  Date P0   //定义Date口为数据口P0
  7. unsigned char code TV1[]={"这是薛羽豪的液晶"};
  8. unsigned char code TV2[]={"哈哈哈哈哈哈哈哈"};
  9. unsigned char code TV3[]={"056789asdfgh    "};
  10. unsigned char code TV4[]={"!@#¥&*不是乱码"};
  11. void Delays_Lcd(unsigned int x)        //延时子函数
  12. {  unsigned int i,j;
  13.    for(i=45;i>0;i--)
  14.       for(j=x;j>0;j--);
  15. }
  16. void Write_Instruction(unsigned char Parameter) //写指令(Write/Instruction)。。形参(Parameter)
  17. {
  18. RS=0;
  19. RW=0;
  20. E=0;
  21. Date=Parameter;
  22. E=1;
  23. Delays_Lcd(0);
  24. E=0;
  25. }
  26. void Write_Date(unsigned char Parameter) //写数据(Write/Date)。。形参(Parameter)
  27. {
  28. RS=1;
  29. RW=0;
  30. E=0;
  31. Date=Parameter;
  32. E=1;
  33. Delays_Lcd(0);
  34. E=0;
  35. }                  
  36. void init_Lcd()        //液晶初始化(init/lcd)
  37. {
  38. Write_Instruction(0x01);
  39. Write_Instruction(0x0c);
  40. Write_Instruction(0x30);
  41. }
  42. void Position_Lcd(unsigned char x,unsigned char y)        //进入点设定,,液晶显示位置(Lcd/Position)
  43. {
  44. unsigned char  Position;
  45. if(x==1)
  46. {x=0x80;}
  47. else if(x==2)
  48. {x=0x90;}
  49. else if(x==3)
  50. {x=0x88;}
  51. else if(x==4)
  52. {x=0x98;}
  53. Position=x+y;
  54. Write_Instruction(Position);     //显示地址
  55. }
  56. void main()
  57. {
  58. unsigned char Num1;
  59. RS=0;
  60. RW=0;
  61. E=0;
  62. init_Lcd();
  63. Position_Lcd(1,0);
  64. Num1=0;
  65. while(TV1[Num1]!='\0')        //教材P176页讲述了TV1[Num1]!='\0'的意思特别是'\0'的意思("空"在储存器中的存储形式是"\0")
  66. {
  67. Write_Date(TV1[Num1]);
  68. Num1++;
  69. }
  70. Position_Lcd(2,0);
  71. Num1=0;
  72. while(TV2[Num1]!='\0')
  73. {
  74. Write_Date(TV2[Num1]);
  75. Num1++;
  76. }
  77. Position_Lcd(3,0);
  78. Num1=0;
  79. while(TV4[Num1]!='\0')
  80. {
  81. Write_Date(TV3[Num1]);
  82. Num1++;
  83. }
  84. Position_Lcd(4,0);
  85. Num1=0;
  86. while(TV4[Num1]!='\0')
  87. {
  88. Write_Date(TV4[Num1]);
  89. Num1++;
  90. }
  91. while(1);
  92. }
复制代码



回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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