找回密码
 立即注册

QQ登录

只需一步,快速开始

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

12864中文测试 (带字库)

[复制链接]
跳转到指定楼层
楼主
ID:71259 发表于 2014-12-30 00:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #include <REG51.H>
  2. #include <intrins.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. //延时子程序模块
  6. //**********************************************
  7. void mdelay(uint delay)
  8. { uint i;
  9.   for(;delay>0;delay--)
  10.      {for(i=0;i<80;i++) //1ms延时.
  11.          {;}
  12.      }
  13. }

  14. //************************************************

  15. void show();   //液晶显示程序
  16. //****************************************
  17. //12864液晶显示部分子程序模块
  18. //****************************************
  19. sbit rs  = P2^0;
  20. sbit rw  = P2^1;
  21. sbit e   = P2^2;
  22. #define lcddata P0
  23. sbit busy=P0^7;   //lcd busy bit
  24. void wr_d_lcd(uchar content);
  25. void wr_i_lcd(uchar content);
  26. void clrram_lcd (void);
  27. void init_lcd(void);
  28. void busy_lcd(void);
  29. void rev_row_lcd(uchar row);
  30. void rev_co_lcd(uchar row,uchar col,uchar mode);
  31. void clr_lcd(void);
  32. void wr_co_lcd(uchar row,uchar col,uchar lcddata1,uchar lcddtta2);
  33. void wr_row_lcd(uchar row,char *p);
  34. //**********************************
  35. //液晶初始化
  36. //**********************************
  37. void init_lcd(void)
  38. {
  39. wr_i_lcd(0x06);  /*光标的移动方向*/
  40. wr_i_lcd(0x0c);  /*开显示,关游标*/
  41. }
  42. //***********************************
  43. //填充液晶DDRAM全为空格
  44. //**********************************
  45. void clrram_lcd (void)
  46. {
  47. wr_i_lcd(0x30);
  48. wr_i_lcd(0x01);
  49. }
  50. //***********************************
  51. //对液晶写数据
  52. //content为要写入的数据
  53. //***********************************
  54. void wr_d_lcd(uchar content)
  55. {
  56. busy_lcd();
  57. rs=1;
  58.     rw=0;
  59. lcddata=content;
  60. e=1;
  61. ;
  62. e=0;
  63. }
  64. //********************************
  65. //对液晶写指令
  66. //content为要写入的指令代码
  67. //*****************************
  68. void wr_i_lcd(uchar content)
  69. {
  70. busy_lcd();
  71. rs=0;
  72.     rw=0;
  73. lcddata=content;
  74. e=1;
  75. ;
  76. e=0;
  77. }
  78. //********************************
  79. //液晶检测忙状态
  80. //在写入之前必须执行
  81. //********************************
  82. void busy_lcd(void)
  83. {
  84.   lcddata=0xff;
  85.   rs=0;
  86.   rw=1;
  87.   e =1;
  88.   while(busy==1);
  89.   e =0;
  90. }
  91. //********************************
  92. //指定要显示字符的坐标
  93. //*******************************
  94. void gotoxy(unsigned char y, unsigned char x)
  95. {
  96. if(y==1)
  97.   wr_i_lcd(0x80|x);
  98. if(y==2)
  99.         wr_i_lcd(0x90|x);
  100. if(y==3)
  101.   wr_i_lcd((0x80|x)+8);
  102. if(y==4)
  103.         wr_i_lcd((0x90|x)+8);
  104. }
  105. //**********************************
  106. //液晶显示字符串程序
  107. //**********************************
  108. void print(uchar *str)
  109. {
  110. while(*str!='\0')
  111. {
  112.   wr_d_lcd(*str);
  113.   str++;
  114. }
  115. }

  116. //***************************************
  117. //液晶显示主程序模块
  118. //***************************************
  119. void show()  
  120. {

  121.   gotoxy(1,0);
  122.   print("欢迎光临锐志电子");
  123.     mdelay(200);            
  124.   gotoxy(2,0);
  125.   print("【锐志电子】");
  126.   mdelay(200);                 //扫描延时

  127. gotoxy(3,0);
  128.   print("WWWwwwwwwwwwww");
  129.   mdelay(200);                 //扫描延时
  130. gotoxy(4,0);
  131.   print("12864 液晶测试");
  132.   mdelay(200);                 //扫描延时
  133. }


  134. //************************************
  135. //主程序
  136. //*************************************
  137. main()
  138. {

  139. init_lcd();
  140. clrram_lcd();

  141. while(1)
  142. {  
  143.       
  144.             show();                //液晶显示数据
  145.             
  146.    }  

  147. }

复制代码


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

使用道具 举报

沙发
ID:73187 发表于 2015-2-3 17:22 | 只看该作者
不知楼主可否有兴趣弄串行的
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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