论坛账号至少一个月登录一次,否则会被自动冻结!论坛全站广告位出租300元一年,有需要联系QQ:154000559。下载资料E币不足?可以每日签到可获取E币,土豪则可以充值即可。
搜索
广告位出租:ML01 有需要联系QQ:2322712906。
广告位出租:ML02 有需要联系QQ:2322712906。
欢迎大家来EDA1024硬件设计开发论坛学习交流!【eda1024.com】
广告位出租:ML04 有需要联系QQ:2322712906。
广告位出租:ML05 有需要联系QQ:2322712906。

[资源共享] 12位AD_DS1621与12864液晶的单片机源程序及仿真

[复制链接]
查看: 938|回复: 1

7

主题

7

帖子

15

E币

技术员

Rank: 2

积分
7
发表于 2017-5-2 11:09:30 | 显示全部楼层 |阅读模式
DS1621与lcd12864和单片机接口的仿真原理图:
123701qyuo15ynwep7yk11.png

单片机源程序:
  1. //EDM12864B DRIVE//
  2. /**************************************
  3.    PAGEADD为页地址起使
  4.    TIERADD为行地址起使
  5.    DIS_STARTADD为开始命令
  6.    CTABLE为汉字字库数组
  7.    ETABLE为英文字库数组
  8. ***************************************/
  9. #include <reg51.h>
  10. #define uchar unsigned char
  11. #define uint unsigned int
  12. #define High 1
  13. #define Low 0
  14. #define _nop {}
  15. #define PAGEADD 0xb8
  16. #define TIERADD 0x40
  17. #define DIS_STARADD 0xc0
  18. uint key_value;
  19. sbit DI=P1^4;
  20. sbit E=P1^2;
  21. sbit CS1=P1^1;
  22. sbit CS2=P1^0;
  23. sbit RW=P1^3;
  24. sbit cs=P1^7;
  25. sbit sclk=P1^6;
  26. sbit dout=P1^5;
  27. sbit I2C_SCL = P3^7;
  28. sbit I2C_SDA = P3^6;
  29. //uchar ntable[]={61,49,57,60,19,49,62,49,60,63,55,2,0,0,6,22,56,
  30. //63,68,61,49,57,60,17,51,63,61};//email:analog2006@hotmail.com
  31. uchar data voltage_display[8];
  32. /*****************************
  33.           字符表
  34.   显示"Welcome Use"
  35. ******************************/
  36. uchar code table1[]={
  37. 0x00,0x3e,0x51,0x49,0x45,0x3e,0x00,0x00,//0(0)
  38. 0x00,0x00,0x42,0x7f,0x40,0x00,0x00,0x00,//1
  39. 0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,//2
  40. 0x00,0x21,0x41,0x45,0x4b,0x31,0x00,0x00,//3
  41. 0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00,//4
  42. 0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,//5
  43. 0x00,0x3c,0x4a,0x49,0x49,0x30,0x00,0x00,//6
  44. 0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,//7
  45. 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,//8
  46. 0x00,0x06,0x49,0x49,0x29,0x1e,0x00,0x00,//9
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// (10)
  48. 0x00,0x00,0x00,0x47,0x00,0x00,0x00,0x00,//!
  49. 0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00,//%
  50. 0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00,//&
  51. 0x00,0x14,0x08,0x3e,0x08,0x14,0x00,0x00,//*
  52. 0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00,//+
  53. 0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,//-
  54. 0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,//.
  55. 0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00,///
  56. 0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,//:(19)
  57. 0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00,//=
  58. 0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00,//?
  59. 0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00,//@(22)
  60. 0x00,0x7e,0x11,0x11,0x11,0x7f,0x00,0x00,//A
  61. 0x00,0x41,0x7f,0x49,0x49,0x36,0x00,0x00,//B
  62. 0x00,0x3e,0x41,0x41,0x41,0x22,0x00,0x00,//C
  63. 0x00,0x41,0x7f,0x41,0x41,0x3e,0x00,0x00,//D
  64. 0x00,0x7f,0x49,0x49,0x49,0x49,0x00,0x00,//E
  65. 0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F
  66. 0x00,0x3e,0x41,0x41,0x49,0x7a,0x00,0x00,//G(29)
  67. 0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H
  68. 0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x00,//I
  69. 0x20,0x40,0x41,0x3f,0x01,0x01,0x00,0x00,//J
  70. 0x00,0x7f,0x08,0x14,0x22,0x41,0x00,0x00,//K
  71. 0x00,0x7f,0x40,0x40,0x40,0x40,0x00,0x00,//L
  72. 0x00,0x7f,0x02,0x0c,0x02,0x7f,0x00,0x00,//M
  73. 0x00,0x7f,0x06,0x08,0x30,0x7f,0x00,0x00,//N
  74. 0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,//O
  75. 0x00,0x7f,0x09,0x09,0x09,0x06,0x00,0x00,//P
  76. 0x00,0x3e,0x41,0x51,0x21,0x5e,0x00,0x00,//Q(39)
  77. 0x00,0x7f,0x09,0x19,0x29,0x46,0x00,0x00,//R
  78. 0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,//S
  79. 0x00,0x01,0x01,0x7f,0x01,0x01,0x00,0x00,//T
  80. 0x00,0x3f,0x40,0x40,0x40,0x3f,0x00,0x00,//U
  81. 0x00,0x1f,0x20,0x41,0x20,0x1f,0x00,0x00,//V
  82. 0x00,0x7f,0x20,0x80,0x20,0x7f,0x00,0x00,//W
  83. 0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00,//X
  84. 0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00,//Y
  85. 0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00,//Z
  86. 0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//a(49)
  87. 0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//b
  88. 0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00,//c
  89. 0x00,0x38,0x44,0x44,0x48,0x7f,0x00,0x00,//d
  90. 0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00,//e
  91. 0x00,0x00,0x08,0x7e,0x09,0x02,0x00,0x00,//f
  92. 0x00,0x0c,0x52,0x52,0x4c,0x3e,0x00,0x00,//g
  93. 0x00,0x7f,0x08,0x04,0x04,0x78,0x00,0x00,//h
  94. 0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00,//i
  95. 0x00,0x20,0x40,0x44,0x3d,0x00,0x00,0x00,//j
  96. 0x00,0x00,0x7f,0x10,0x28,0x44,0x00,0x00,//k(59)
  97. 0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00,//l
  98. 0x00,0x7c,0x04,0x78,0x04,0x78,0x00,0x00,//m
  99. 0x00,0x7c,0x08,0x04,0x04,0x78,0x00,0x00,//n
  100. 0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,//o
  101. 0x00,0x7e,0x0c,0x12,0x12,0x0c,0x00,0x00,//p
  102. 0x00,0x0c,0x12,0x12,0x0c,0x7e,0x00,0x00,//q
  103. 0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00,//r
  104. 0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00,//s
  105. 0x00,0x04,0x3f,0x44,0x40,0x20,0x00,0x00,//t
  106. 0x00,0x3c,0x40,0x40,0x3c,0x40,0x00,0x00,//u(69)
  107. 0x00,0x1c,0x20,0x40,0x20,0x1c,0x00,0x00,//v
  108. 0x00,0x3c,0x40,0x30,0x40,0x3c,0x00,0x00,//w
  109. 0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,//x
  110. 0x00,0x1c,0xa0,0xa0,0x90,0x7c,0x00,0x00,//y
  111. 0x00,0x44,0x64,0x54,0x4c,0x44,0x00,0x00,//z(74)
  112. };
  113. /****************************
  114.         中文字符表
  115. 显示"欢迎使用液晶模块"
  116. *****************************/
  117. uchar code table2[]={
  118. 0x14,0x24,0x44,0x84,0x64,0x1c,0x20,0x18,
  119. 0x0f,0xe8,0x08,0x08,0x28,0x18,0x08,0x00,
  120. 0x20,0x10,0x4c,0x43,0x43,0x2c,0x20,0x10,
  121. 0x0c,0x03,0x06,0x18,0x30,0x60,0x20,0x00,//欢(0)
  122. 0x40,0x41,0xce,0x04,0x00,0xfc,0x04,0x02,
  123. 0x02,0xfc,0x04,0x04,0x04,0xfc,0x00,0x00,
  124. 0x40,0x20,0x1f,0x20,0x40,0x47,0x42,0x41,
  125. 0x40,0x5f,0x40,0x42,0x44,0x43,0x40,0x00,//迎(1)
  126. 0x40,0x20,0xf0,0x1c,0x07,0xf2,0x94,0x94,
  127. 0x94,0xff,0x94,0x94,0x94,0xf4,0x04,0x00,
  128. 0x00,0x00,0x7f,0x00,0x40,0x41,0x22,0x14,
  129. 0x0c,0x13,0x10,0x30,0x20,0x61,0x20,0x00,//使(2)
  130. 0x00,0x00,0x00,0xfe,0x22,0x22,0x22,0x22,
  131. 0xfe,0x22,0x22,0x22,0x22,0xfe,0x00,0x00,
  132. 0x80,0x40,0x30,0x0f,0x02,0x02,0x02,0x02,
  133. 0xff,0x02,0x02,0x42,0x82,0x7f,0x00,0x00,//用(3)
  134. 0x10,0x61,0x06,0xe0,0x18,0x84,0xe4,0x1c,
  135. 0x84,0x65,0xbe,0x24,0xa4,0x64,0x04,0x00,
  136. 0x04,0x04,0xff,0x00,0x01,0x00,0xff,0x41,
  137. 0x21,0x12,0x0c,0x1b,0x61,0xc0,0x40,0x00,//液(4)
  138. 0x00,0x00,0x00,0x00,0x7e,0x2a,0x2a,0x2a,
  139. 0x2a,0x2a,0x2a,0x7e,0x00,0x00,0x00,0x00,
  140. 0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,
  141. 0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,//晶(5)
  142. 0x10,0xd0,0xff,0x50,0x90,0x04,0xf4,0x54,
  143. 0x5f,0x54,0x54,0x5f,0xf4,0x04,0x00,0x00,
  144. 0x03,0x00,0xff,0x00,0x00,0x84,0x85,0x45,
  145. 0x35,0x0f,0x15,0x25,0x65,0xc4,0x44,0x00,//模(6)
  146. 0x10,0x10,0xff,0x10,0x10,0x00,0x08,0x08,
  147. 0xff,0x08,0x08,0x08,0xf8,0x00,0x00,0x00,
  148. 0x08,0x18,0x0f,0x04,0x85,0x41,0x31,0x0d,
  149. 0x03,0x05,0x09,0x11,0x31,0x61,0x21,0x00,//块(7)
  150. 0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,
  151. 0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
  152. 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,
  153. 0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,//电(8)
  154. 0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,
  155. 0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00,
  156. 0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,
  157. 0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00,//压(9)
  158. 0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,
  159. 0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
  160. 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,
  161. 0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,//温(10)
  162. 0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,
  163. 0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,
  164. 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,
  165. 0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,//度(11)
  166. 0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,
  167. 0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
  168. 0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,
  169. 0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,//测(12)
  170. 0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5,
  171. 0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00,
  172. 0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F,
  173. 0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,//量(13)
  174. };
  175. /********************************
  176.        显示用的延时函数
  177.   延时长度有参数 n 决定
  178. *********************************/

  179. Delay_nms(uchar n)
  180. { uchar a;
  181.    for(;n>0;n--)
  182.       {
  183.     for(a=0;a<100;a++)
  184.        {
  185.      _nop;
  186.      _nop;
  187.      _nop;
  188.      _nop;
  189.      };
  190.     };
  191.   }

  192. /*****************************************
  193.     DEM12864B状态检测,从EDM12864B读出数
  194.     据检测标志位BF
  195. ******************************************/

  196. void LCD_Busy()
  197. {
  198.   uchar busy;
  199.   E=Low;
  200.   DI=Low;
  201.   RW=High;
  202.   while(1)
  203.   {
  204.     E=High;
  205.     _nop;
  206. _nop;
  207.     busy=P2;//读状态标志寄存器
  208. _nop;
  209.     E=Low;
  210.     if((busy&0x90)==0)//检测BF和RES位,两者都为零时表示可进行写入
  211.     break;
  212.   };
  213. }
  214. /*********************************
  215.         写指令
  216. **********************************/
  217. void WRCommand_L(uchar command)
  218. {
  219.   CS1=High;
  220.   CS2=Low;
  221.   LCD_Busy();
  222.   DI=Low;
  223.   _nop;
  224.   RW=Low;
  225.   _nop;
  226.   E=High;
  227.   _nop;
  228.   P2=command;
  229.   _nop;
  230.   E=Low;
  231.   _nop;
  232. }

  233. void WRCommand_R(uchar command)
  234. {
  235.   CS1=Low;
  236.   CS2=High;
  237.   LCD_Busy();
  238.   DI=Low;
  239.   _nop;
  240.   RW=Low;
  241.   _nop;
  242.   E=High;
  243.   _nop;
  244.   P2=command;
  245.   _nop;
  246.   E=Low;
  247.   _nop;
  248. }

  249. /***********************************
  250.        写一个字节的显示数据
  251. ************************************/
  252. void WRdata_L(uchar ucdata)
  253.   {
  254.    CS1=High;
  255.    CS2=Low;
  256.    LCD_Busy();
  257.    DI=High;
  258.    _nop;
  259.    RW=Low;
  260.    _nop;
  261.    E=High;
  262.    _nop;
  263.    P2=ucdata;
  264.    _nop;
  265.    E=Low;
  266.    _nop;
  267.   }

  268. void WRdata_R(uchar ucdata)
  269.   {
  270.    CS1=Low;
  271.    CS2=High;
  272.    LCD_Busy();  
  273.    DI=High;
  274.    _nop;
  275.    RW=Low;
  276.    _nop;
  277.    E=High;
  278.    _nop;
  279.    P2=ucdata;
  280.    _nop;
  281.    E=Low;
  282.    _nop;
  283.   }

  284. /************************************
  285.     读显示数据
  286. *************************************/
  287. /********************************************
  288. RDdata_L()
  289.   {
  290.    uchar receiver;
  291.    CS1=High;
  292.    CS2=Low;
  293.    LCD_Busy();
  294.    DI=High;
  295.    _nop;
  296.    WR=High;
  297.    _nop;
  298.    E=High;
  299.    _nop;
  300.    receiver=P0;
  301.    E=Low;
  302.    return(receiver);
  303.   }

  304. RDdata_R()
  305.   {
  306.    uchar receiver;
  307.    CS1=Low;
  308.    CS2=High;
  309.    LCD_Busy();
  310.    DI=High;
  311.    _nop;
  312.    WR=High;
  313.    _nop;
  314.    E=High;
  315.    _nop;
  316.    receiver=P0;
  317.    E=Low;
  318.    return(receiver);
  319.   }
  320. /*****************************************
  321. /**************************************
  322.    I2C时钟时序要求的数据建立时间,
  323.    nop_可以用其它短延时替代,比如喂狗
  324. ***************************************/
  325. I2C_delay()
  326.    {
  327.     uchar n=5;
  328.     while(n--)
  329.       {
  330.     _nop;
  331.     _nop;
  332.     }
  333.     }
  334. /*********************************************
  335.      I2C的时钟信号可发送和接收.
  336.      接收时通过判断sample对寄存器的值加.
  337.      发送的时候只调用程序产生时序.
  338. **********************************************/
  339. bit I2C_clock(void)
  340.     {
  341.      bit sample;
  342.      I2C_delay();
  343.      I2C_SCL=High;
  344.      I2C_delay();
  345.      sample=I2C_SDA;
  346.      I2C_SCL=Low;
  347.      I2C_delay();
  348.      return(sample);
  349.     }
  350. /********************************************
  351.    I2C确定接收有效的应答信号Acknowledge
  352. *********************************************/
  353. I2C_ACK()
  354.    {
  355.     I2C_SDA=Low;
  356.     I2C_clock();
  357.     I2C_SDA=High;
  358.    }
  359. /*****************************************
  360. I2C的非应答信号
  361. ******************************************/
  362. I2C_NACK()
  363.    {
  364.     I2C_SDA=High;
  365.     I2C_clock();
  366.     I2C_SDA=High;
  367.    }
  368. /*************************************************
  369.      I2C的开始信号.发送和接受数据时,必须先调用.
  370. *************************************************/
  371. I2C_start()
  372.    {
  373.     I2C_SDA=High;
  374.     I2C_delay();
  375.     I2C_SCL=High;
  376.     I2C_delay();
  377.     I2C_SDA=Low;
  378.     I2C_delay();
  379.     I2C_SCL=Low;
  380.     I2C_delay();
  381.   }
  382. /***************************************************
  383.     I2C停止信号.发送和接受数据时结束时,需要调用.
  384. ****************************************************/
  385. I2C_stop()
  386.    {
  387.     I2C_SDA=Low;
  388.     I2C_delay();
  389.     I2C_SCL=High;
  390.     I2C_delay();
  391.     I2C_SDA=High;//产生停止控制信号,并且释放数据线
  392.     I2C_delay();
  393.    }
  394. /*****************************************
  395.     I2C初始化.在main函数中必须先调用它.
  396.      进行初始化后才能调用其他函数.
  397. ******************************************/
  398. void I2C_init(void)
  399.    {
  400.     I2C_SDA=High;
  401.     I2C_SCL=High;
  402.     I2C_delay();
  403.     I2C_stop();
  404.    }
  405. /*****************************************
  406.     I2C总线写一个字节,即发送一个字节
  407.    发送结束后,需要返回一个检测应答位
  408. ******************************************/
  409. bit I2C_send(uchar I2C_data)
  410.    {
  411.     uchar a;
  412.     for(a=0;a<8;a++)
  413.       {
  414.        I2C_SDA=(bit)(I2C_data&0x80);
  415.        I2C_data=I2C_data<<1;
  416.        I2C_clock();
  417.       };
  418.     I2C_SDA=High;
  419.     I2C_delay();
  420.     return(I2C_clock()); //返回应答信号
  421.    }
  422. /***********************************************
  423.    I2C总线读一个字节,即接收一个字节数据
  424.    接收结束后需要发送一个应答位acknowledge
  425. ***********************************************/
  426. uchar I2C_receive()
  427.      {
  428.       uchar a,receive_data;
  429.       for(a=0;a<8;a++)
  430.          {
  431.           receive_data=receive_data<<1;
  432.           if(I2C_clock())
  433.            {
  434.             receive_data++;
  435.            };
  436.          };
  437. //I2C_ACK();
  438.       return(receive_data);
  439.       }

  440. DS1621_start()
  441.    {
  442. do
  443. {
  444.      I2C_start();
  445.   }
  446.     while(I2C_send(0x90));//发送数据完地址字节的数据时,检测从机的应答位        
  447. if(I2C_send(0xee)==0)
  448.    {
  449.     I2C_stop();
  450.     return 1;
  451.     }
  452.     else
  453.    return 0;           
  454.    }
  455. DS1621_stop()
  456.    {
  457.     do
  458. {
  459.   I2C_start();
  460.   //I2C_send(0x90);
  461.   }
  462. while(I2C_send(0x90));
  463. if(I2C_send(0x22)==0)
  464.      {
  465.    I2C_stop();
  466.    return 1;
  467.    }
  468. else
  469.    return 0;     
  470. }
  471. char read_count_remain()
  472.       {
  473.     char temp_remain=0;
  474.     do
  475.      {
  476.       I2C_start();
  477.       }
  478.     while(I2C_send(0x90));//是否应答
  479.     if(I2C_send(0xa8)==0)
  480.       {
  481.     I2C_start();
  482.        if(I2C_send(0x91)==0)
  483.          {
  484.    temp_remain=I2C_receive();
  485.    I2C_NACK();
  486.       I2C_stop();
  487.    return temp_remain;
  488.    }
  489.     else
  490.       return 0;
  491.        }
  492.   else
  493.     return 0;
  494.     }
  495. char read_count_c()
  496.       {
  497.     char temp_c=0;
  498.     do
  499.      {
  500.       I2C_start();
  501.       }
  502.     while(I2C_send(0x90));//是否应答
  503.     if(I2C_send(0xa9)==0)
  504.       {
  505.     I2C_start();
  506.        if(I2C_send(0x91)==0)
  507.          {
  508.    temp_c=I2C_receive();
  509.    I2C_NACK();
  510.       I2C_stop();
  511.    return temp_c;
  512.    }
  513.     else
  514.       return 0;
  515.        }
  516.   else
  517.     return 0;
  518.     }
  519. bit read_temperature(char *point1)
  520.    {
  521. do
  522. {
  523. I2C_start();
  524. }
  525. while(I2C_send(0x90));
  526.     if(I2C_send(0xaa)==0)
  527.    {
  528.     do{
  529.       I2C_start();
  530.       }
  531.       while(I2C_send(0x91));
  532.     (*point1)=I2C_receive();
  533.     I2C_ACK();
  534.     (*(point1+1))=I2C_receive();
  535.     I2C_NACK();
  536.     I2C_stop();
  537.     return 1;
  538.     }
  539. else
  540. return 0;
  541. }
  542. DS1621_state()
  543.    {
  544. do
  545. {
  546.   I2C_start();
  547.   }
  548. while(I2C_send(0x90));
  549. if(I2C_send(0xac)==0)
  550.       {
  551.     do
  552.   {
  553.       I2C_start();
  554.   }
  555.     while(I2C_send(0x90));
  556.     if(I2C_send(0x00)==0)
  557.     //if(I2C_send(0x01)==0)
  558.    {
  559.    I2C_stop();
  560.    return 1;
  561.     }
  562.     else
  563.     return 0;
  564.   }
  565. else
  566.    return 0;     
  567. }
  568. DS1621_th()
  569.    {
  570.   
  571.     }
  572. DS1621_tl()
  573.    {
  574.   
  575.     }
  576. DS1621_init()
  577.    {
  578. while(DS1621_stop()==0)
  579. {};
  580. while(DS1621_state()==0)
  581. {};
  582. DS1621_th();
  583. DS1621_tl();
  584. }
  585. /****************************************************
  586.        字符为16*16显示,分为两个部分写入32个字节
  587.        前16个字节写入第一页(16*8),后16个字节写入
  588.     第二页(16*8)
  589.     左侧写入"欢迎",右侧写入"使用"
  590. *****************************************************/
  591. C_display_L(uchar C_Pagenum,uchar C_Tiernum,uchar C_Temp)
  592.   {
  593.    uchar k;
  594.    C_Pagenum=PAGEADD|C_Pagenum;
  595.    C_Tiernum=TIERADD|C_Tiernum;
  596.    WRCommand_L(C_Pagenum);
  597.    WRCommand_L(C_Tiernum);
  598.    for(k=0;k<16;k++)
  599.       {
  600.        WRdata_L(table2[C_Temp*32+k]);
  601.       };
  602.    C_Pagenum=C_Pagenum+1;
  603.    WRCommand_L(C_Pagenum);
  604.    WRCommand_L(C_Tiernum);
  605.    for(k=0;k<16;k++)
  606.       {
  607.        WRdata_L(table2[C_Temp*32+k+16]);
  608.     };
  609.    }
  610. C_display_R(uchar C_Pagenum,uchar C_Tiernum,uchar C_Temp)
  611.   {
  612.    uchar k;
  613.    C_Pagenum=PAGEADD|C_Pagenum;
  614.    C_Tiernum=TIERADD|C_Tiernum;
  615.    WRCommand_R(C_Pagenum);
  616.    WRCommand_R(C_Tiernum);
  617.    for(k=0;k<16;k++)
  618.       {
  619.        WRdata_R(table2[C_Temp*32+k]);
  620.       };
  621.    C_Pagenum=C_Pagenum+1;
  622.    WRCommand_R(C_Pagenum);
  623.    WRCommand_R(C_Tiernum);
  624.    for(k=0;k<16;k++)
  625.       {
  626.        WRdata_R(table2[C_Temp*32+k+16]);
  627.       };
  628.   }
  629. /****************************************
  630.    写入西文字符,共11个字符,左侧写入6个
  631.    右侧写入5个,左侧起始从16开始,右侧从
  632.    0开始
  633. *****************************************/
  634. E_Display_L(uchar E_Pagenum,uchar E_Tiernum,uchar E_Temp)
  635.   {
  636.    uchar k;
  637.    WRCommand_L(PAGEADD|E_Pagenum);
  638.    WRCommand_L(TIERADD|E_Tiernum);
  639.    for(k=0;k<8;k++)
  640.    {
  641.     WRdata_L(table1[E_Temp*8+k]);
  642.     };
  643.    }   
  644. E_Display_R(uchar E_Pagenum,uchar E_Tiernum,uchar E_Temp)
  645.    {
  646.    uchar k;
  647.    WRCommand_R(PAGEADD|E_Pagenum);
  648.    WRCommand_R(TIERADD|E_Tiernum);
  649.    for(k=0;k<8;k++)
  650.    {
  651.     WRdata_R(table1[E_Temp*8+k]);
  652.     };
  653.     }
  654. /*********************************
  655.     清除所有显示RAM内容
  656. **********************************/
  657. CLR_DisplayRAM()
  658.    {
  659.     uchar C_page,i,k;
  660.     for(i=0;i<8;i++)
  661.     {
  662.      C_page=PAGEADD|i;//清除起始页为0
  663.      WRCommand_L(C_page);//清除起始页写入
  664.   WRCommand_L(TIERADD);//清除起始行地址写入
  665.   WRCommand_R(C_page);
  666.   WRCommand_R(TIERADD);
  667.   for(k=0;k<64;k++)
  668.      {      
  669.    WRdata_L(0x00);
  670.    WRdata_R(0x00);//lcm的ram自动加一,只许循环64次即可   
  671.     };
  672.    };
  673.     }
  674. /*********************************
  675.        初始化 设置启使行
  676. **********************************/
  677. void Init_LCD(void)
  678.    {
  679. CLR_DisplayRAM();//清除所有显示寄存器
  680. WRCommand_L(DIS_STARADD);
  681. WRCommand_R(DIS_STARADD);//设置显示起始行地址
  682. WRCommand_L(0x3f);
  683. WRCommand_R(0x3f);//开显示
  684.     }
  685. /***************************************
  686.     max1241读转换结果
  687. ****************************************/
  688. uint read_max1241()
  689.   {
  690.    uint voltage_temp=0;
  691.    uchar ucloop=12;
  692.    cs=High;
  693.    //dout=low;
  694.    sclk=Low;
  695.    cs=Low;
  696.       while(dout==0);//EOC信号为高表示转换结束
  697.    sclk=High;
  698.    sclk=Low;
  699.       while(ucloop--)
  700.     {
  701.   sclk=High;//上升沿数据稳定并读出
  702.   voltage_temp<<=1;
  703.      if(dout==1)
  704.      voltage_temp+=1;
  705.      sclk=Low;
  706.   };  
  707.    //sclk=low;
  708.    cs=High;
  709.    return voltage_temp;
  710.    }
  711. main()
  712.   {
  713.    uchar a=0,temp=0,b=0,number=0,pagenum=0;
  714.    uchar etable[]={0,0,0,0,0,45,53,60,51,63,61,53,10,69,67,53};//Welcome use
  715.    uchar ttable[]={42,57,61,53,19,10,2,0,0,6,18,1,1,18,0,7};//Time:2006/11/07
  716.    char count_remain=0,count_c=0;
  717.    bit flag=1;
  718.    char temperature_buf[2]={0};
  719.    uchar temperature_display[8]={0};
  720.    //uchar voltage=0; //测试0831时使用
  721.    double voltage=0;
  722.    double temp_buffer=0;
  723.    cs=High;
  724.    sclk=High;
  725.    Init_LCD();
  726.    I2C_init();
  727.    DS1621_init();//初始化
  728.    DS1621_start();//开始温度采集
  729.    /***************************************
  730.    利用开机显示时间(大概三秒)空读一次DS1621
  731.    ***************************************/
  732.    for(b=0;b<2;b++)
  733.       {
  734.       for(number=0;number<20;number++)
  735.       {
  736.        //中文显示:欢迎使用液晶模块
  737.         pagenum=1;//在第二行开始显示
  738.        for(a=0;a<4;a++)
  739.          {
  740.           C_display_L(pagenum,a*16,a);
  741.           C_display_R(pagenum,a*16,a+4);
  742.           };
  743.         
  744.     //英文显示:Welcome use            
  745.           pagenum=5;//在第六行显示
  746.           for(a=0;a<3;a++)
  747.              {
  748.               E_Display_L(pagenum,(a+5)*8,etable[a+5]);
  749.               };
  750.           for(a=0;a<8;a++)
  751.              {
  752.               E_Display_R(pagenum,a*8,etable[a+8]);
  753.               };
  754.         
  755.     //显示制作时间:Time:2006/11/07   
  756.           pagenum=7;//在第八行显示
  757.           for(a=0;a<8;a++)
  758.              {
  759.               E_Display_L(pagenum,a*8,ttable[a]);
  760.               E_Display_R(pagenum,a*8,ttable[a+8]);
  761.               }         
  762.        Delay_nms(100);
  763.     };
  764.     if(flag)
  765.      {
  766.               read_temperature(temperature_buf);//在转到下一个显示界面之前空读一次
  767.      read_count_remain();
  768.      read_count_c();
  769.      DS1621_start();
  770.               flag=0;
  771.               };
  772.       };  
  773. WRCommand_L(0x3e);
  774. WRCommand_R(0x3e);
  775. CLR_DisplayRAM();  //清除显示ram
  776. WRCommand_L(0x3f);
  777. WRCommand_R(0x3f);   
  778.    
  779.     while(1)
  780.     {
  781.      while(read_temperature(temperature_buf)==0);//读温度值(两字节有符数),并检测应答位,只使用第一字节
  782.      count_remain=read_count_remain();//读斜率
  783.   count_c=read_count_c();//读计数器
  784.   temp_buffer = temperature_buf[0] -0.75 + (count_c-count_remain) / (double)count_c;
  785.   DS1621_start();//读完数据后,重新开始一次温度转化
  786.       temperature_display[0]=19;
  787.    if(temp_buffer<0)
  788.      {
  789.       temperature_display[1]=16;//显示负号
  790.          temperature_display[2]=(-temp_buffer)/10;//十位
  791.       temperature_display[3]=((uchar)(-temp_buffer))%10;
  792.       temperature_display[4]=17;//小数点
  793.       temperature_display[5]=(int)((-temp_buffer)*10)%10;
  794.       temperature_display[6]=(int)((-temp_buffer)*100)%10;//小数点后两位
  795.       }
  796.    else
  797.      {
  798.       temperature_display[1]=temp_buffer/100;//百位
  799.          temperature_display[2]=((uchar)temp_buffer)/10%10;
  800.       temperature_display[3]=((uchar)temp_buffer)%10;
  801.       temperature_display[4]=17;
  802.       temperature_display[5]=((int)(temp_buffer*10))%10;
  803.       temperature_display[6]=((int)(temp_buffer*100))%10;//小数点后两位
  804.       }
  805.    // 测试从max1241读出的原始数据
  806.       /***************************
  807.    //pagenum=3;
  808.        voltage=read_max1241();
  809.       voltage_display[0]=19;
  810.       voltage_display[1]= voltage/1000;   
  811.       voltage_display[2]=(voltage/100)%10;
  812.       voltage_display[3]=(voltage/10)%10;
  813.                                 voltage_display[4]= voltage%10;   
  814.       //*******************************/
  815.   //LCD显示第二部分
  816.   for(b=0;b<40;b++)
  817.         {
  818.       //*************************
  819.    //更新max1241显示值      
  820.    voltage=(double)read_max1241();
  821.       voltage=5000*voltage/4095;
  822.       voltage_display[0]=19;
  823.       voltage_display[5]=(uint)voltage %10;//个位
  824.       voltage_display[2]=17;
  825.       voltage_display[4]=(uint)(voltage/10)%10;//小数点后1位
  826.       voltage_display[3]=(uchar)(voltage/100)%10;//小数点后2位
  827.    voltage_display[1]=(uchar)(voltage/1000)%10;//小数点后3位
  828.    //***********************************/
  829.    //显示文字:电压测量  
  830.       pagenum=2;
  831.       for(a=0;a<2;a++)
  832.          C_display_L(pagenum,a*16,a+8);
  833.       for(a=0;a<2;a++)
  834.          C_display_L(pagenum,(a+2)*16,a+12);
  835.      
  836.       //显示文字:温度测量
  837.       pagenum=5;
  838.       for(a=0;a<2;a++)
  839.          C_display_L(pagenum,a*16,a+10);
  840.       for(a=0;a<2;a++)


  841. …………限于本文篇幅 余下代码请从论坛下载附件…………
复制代码


下载:
0001、12位AD_DS1621与12864液晶.zip (33.59 KB, 下载次数: 0)
回复

使用道具 举报

0

主题

19

帖子

62

E币

助理工程师

Rank: 3Rank: 3

积分
20
发表于 2017-7-17 22:02:53 | 显示全部楼层
谢谢分享!!!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 入住EDA1024

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|Archiver|手机版|小黑屋|EDA1024硬件论坛 ( 苏ICP备15024581号 )

GMT+8, 2021-9-20 23:22 , Processed in 0.072895 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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