[文档下载] LCD12232液晶的模块化程序

[复制链接]
 楼主| 仙女山 发表于 2015-8-17 15:51 | 显示全部楼层 |阅读模式

  1. /*******************************************************************

  2.          lcd12232.h头文件

  3. *******************************************************************/

  4. #ifndef _LCD12232_H_
  5. #define _LCD12232_H_
  6. extern void lcd12232_busy(); //忙标志函数
  7. extern void lcd12232_init(); //初始化函数
  8. extern void lcd12232_clear();//清屏函数
  9. extern void lcd12232_hanzi(unsigned char m,unsigned char n,unsigned char p,unsigned char y);//第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个是页地址
  10.                    //选屏函数,2为两屏,1为左屏,0为右屏
  11.                    //页地址设置的参数值应该为0、1、2三个数中的一个,因为液晶一共分为四页
  12. //extern void lcd12232_zifu(unsigned char m,unsigned char n,unsigned char y,unsigned char d);//第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
  13. #endif

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

  15.          lcd12232.c文件

  16. *******************************************************************/

  17. #include<reg51.h>
  18. #define uchar unsigned char
  19. #define uint  unsigned char
  20. #define port P0
  21. sbit e1=P2^1;
  22. sbit e2=P2^2;
  23. sbit a0=P2^0;
  24. sbit rw=P2^3;
  25. uchar code ziku[]=
  26. {

  27. 0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小
  28. 0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,

  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空" 什么也不显示,需要的时候把它放在任意位置来当空格使用
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  31. 0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒
  32. 0x04,0x05,0x04,0x04,0x04,0x04,0x05,0xFE,0x05,0x04,0x04,0x04,0x05,0x04,0x04,0x00,

  33. 0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,//设
  34. 0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,

  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空"
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  37. 0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00,//计
  38. 0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,

  39. 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!
  40. 0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,
  42. 0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

  43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。
  44. 0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  45. 0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李"
  46. 0x00,0x08,0x08,0x08,0x09,0x49,0x89,0x7D,0x0D,0x0B,0x09,0x08,0x0C,0x08,0x00,0x00,

  47. 0x10,0x10,0x10,0xFF,0x90,0x50,0xFE,0x92,0x92,0x92,0x92,0x92,0x9A,0xD3,0x82,0x00,//"振"  
  48. 0x02,0x42,0x81,0x7F,0x40,0x30,0x0F,0x00,0xFF,0x40,0x07,0x18,0x28,0x64,0x22,0x00,

  49. 0x80,0x40,0x20,0xF8,0x07,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x68,0x4C,0x08,0x00,//"伟"
  50. 0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00
  51. };
  52. void delay(uchar z)    //延时函数
  53. {
  54.      int x;
  55.      for(x=z;x>0;x--);
  56. }
  57. void lcd12232_cs(uchar cs) //选屏函数,2为两屏,1为左屏,0为右屏
  58. {
  59.    switch(cs)
  60.    {
  61.     case 0:e1=1,e2=0;break;
  62.     case 1:e1=0;e2=1;break;
  63.     case 2:e1=0;e2=0;break;
  64.     case 3:e1=1;e2=1;break;  
  65.    }
  66. }
  67. void lcd12232_write_com(uchar com,uchar n)//写命令函数
  68. {
  69. lcd12232_cs(3);
  70. a0=0;
  71. rw=0;
  72. port=com;
  73. //delay(1);
  74. lcd12232_cs(n);
  75. delay(1);
  76. }
  77. void lcd12232_write_dat(uchar dat,uchar n)//写数据函数
  78. {
  79. a0=1;
  80. rw=0;
  81. lcd12232_cs(3);
  82. port=dat;
  83. lcd12232_cs(n);
  84. }
  85. uchar lcd12232_read()   //读状态函数
  86. {
  87. uchar dat;
  88. //e1=0;e2=0;
  89. lcd12232_cs(2);
  90. a0=0;
  91. rw=1;
  92. port=0xff;
  93. delay(1);
  94. //e1=1;e2=1;
  95. lcd12232_cs(3);
  96. dat=port;
  97. delay(1);
  98. //e1=0;e2=0;
  99. lcd12232_cs(2);
  100. return dat;
  101. }
  102. void lcd12232_busy()
  103. {
  104. uchar i;
  105. i=lcd12232_read();
  106. while(i&0x80==0x80);
  107. }
  108. void lcd12232_clear()    //清屏函数
  109. {
  110. uchar i;
  111. lcd12232_write_com(0xb8,2);
  112. lcd12232_write_com(0x00,2);
  113. for(i=0;i<255;i++)
  114. lcd12232_write_dat(0x00,2);
  115. }
  116. void lcd12232_init() //第一个参数为指令,第二个参数为选屏,2为两屏,1为左屏,0为右屏
  117. {
  118. lcd12232_write_com(0xe2,2);//复位
  119. lcd12232_write_com(0xaf,2);//总显示开
  120. lcd12232_write_com(0xc0,2);//从第一行开始显示数据
  121. lcd12232_write_com(0xb8,2);//设置显示页地址为第一页
  122. lcd12232_write_com(0x00,2);//设置显示列地址为第一列
  123. lcd12232_write_com(0xa1,2);//设置正向显示,a0为逆向显示
  124. lcd12232_write_com(0xa9,2);// 1/32占空比
  125. lcd12232_write_com(0xa4,2);//动态驱动
  126. lcd12232_write_com(0xee,2);
  127. lcd12232_clear();     //清屏
  128. }
  129. void lcd12232_hanzi(uchar m,uchar n,uchar p,uchar y)   //汉字显示函数,第一个参数代表的是显示m个字,第二个参数是从第n个字开始显示,第三个参数是选屏,第四个是页地址
  130. {
  131. uchar i,a;
  132. lcd12232_write_com(0x00,2);
  133. lcd12232_write_com(0xb8+y,2);
  134. for(a=0;a<m;a++)
  135. {
  136.   for(i=0;i<16;i++)
  137.   {
  138.    lcd12232_write_dat(ziku[i+a*32+(n-1)*32],p);
  139.   }
  140. }

  141. lcd12232_write_com(0x00,2);
  142. lcd12232_write_com(0xb9+y,2);
  143. for(a=0;a<m;a++)
  144. {
  145.   for(i=0;i<16;i++)
  146.   {
  147.    lcd12232_write_dat(ziku[i+a*32+16+(n-1)*32],p);
  148.   }
  149. }
  150. }
  151. /*void lcd12232_zifu(uchar m,uchar n,uchar y,uchar d)  //第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
  152. {
  153. uchar i;
  154. lcd12232_write_com(0xb8+y,2);
  155. lcd12232_write_com(0x00+d,2);
  156. for(i=0;i<16;i++)
  157. {
  158. lcd12232_write_dat(ziku[m*32+i],n);
  159. }
  160. lcd12232_write_com(0xb9+y,2);
  161. lcd12232_write_com(0x00+d,2);
  162. for(i=0;i<16;i++)
  163. {
  164. lcd12232_write_dat(ziku[m*32+i+16],n);
  165. }
  166. } */

  167. /*******************************************************************

  168.            main.c主文件

  169. *******************************************************************/

  170. #include<reg51.h>
  171. #include"lcd12232.h"
  172. void main()
  173. {     
  174. lcd12232_init(); //初始化
  175. lcd12232_clear();//清屏
  176. lcd12232_busy();//忙检测
  177. lcd12232_hanzi(3,1,1,1);//第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个参数是页地址
  178. lcd12232_busy();
  179. lcd12232_hanzi(4,4,0,1);

  180. //lcd12232_zifu(0,1,0,0);//第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
  181. while(1);
  182. }


Luis德华 发表于 2015-8-17 21:27 | 显示全部楼层
有电路,有程序,有讲解,很受用
yiyigirl2014 发表于 2015-8-18 08:00 | 显示全部楼层
有仿真和程序,这样最好了,很容易理解。
稳稳の幸福 发表于 2015-8-18 08:16 | 显示全部楼层
  • void main()
  • {
  • lcd12232_init(); //初始化
  • lcd12232_clear();//清屏
  • lcd12232_busy();//忙检测
  • lcd12232_hanzi(3,1,1,1);//第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个参数是页地址
  • lcd12232_busy();
  • lcd12232_hanzi(4,4,0,1);
  • //lcd12232_zifu(0,1,0,0);//第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
  • while(1);
  • }



最喜欢这样的了,清晰,结构化,可以移植。
springvirus 发表于 2015-8-18 08:38 | 显示全部楼层
楼主玩过16脚的12232吗,手头有块ZCM12232C,正在尝试点亮
大苏牙 发表于 2015-8-18 09:23 | 显示全部楼层
12232的LCD有没有带字库呢
稳稳の幸福 发表于 2015-8-18 11:55 | 显示全部楼层
不带字库不好玩啊,最好带个中文字库。
IversonCar 发表于 2015-8-18 20:34 | 显示全部楼层
第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个是页地址
稳稳の幸福 发表于 2015-8-19 16:04 | 显示全部楼层
这个是并行接口的,就比较浪费了管脚了,好多应用上,管脚是非常宝贵的。
稳稳の幸福 发表于 2015-8-19 16:04 | 显示全部楼层
最好选择那些串行管脚的显示屏比较好。
玛尼玛尼哄 发表于 2015-8-19 17:17 | 显示全部楼层
最好选择带字库的,那样操作更方便,更加随意。
3085706506 发表于 2017-6-3 16:41 | 显示全部楼层
lcd12232_write_dat(ziku[i+a*32+16+(n-1)*32],p);学习啊,这句话是什么意思啊?
zhuomuniao110 发表于 2017-6-5 16:09 | 显示全部楼层
不错不错,收下学习。
huangcunxiake 发表于 2017-6-5 19:08 | 显示全部楼层
有图有真相,不过仿真软件能发上来就给力了。打个压缩包分享一下呗。
gejigeji521 发表于 2017-6-6 11:53 | 显示全部楼层
这种有图有真相的,多来点,最好仿真的源文件什么的都打包发来
wenking999 发表于 2019-8-8 16:18 | 显示全部楼层
程序移植没显示啊
xixi2017 发表于 2019-8-9 10:59 来自手机 | 显示全部楼层
整点国语
捉虫天师 发表于 2019-8-13 00:11 | 显示全部楼层
跟1602是不是操作时序类似。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

340

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

36

主题

340

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部