找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5|回复: 0
收起左侧

试制简易PID调温936焊台

[复制链接]
ID:1136941 发表于 2026-9-12 18:05 | 显示全部楼层 |阅读模式
闲来无事设计制作了这个简易936焊台,单片机是STC8G1K08A,用电位器设置温度.PID参考了某老师的代码,现在温度可以调节并恒定,没条件做温度准确度校准,水平所限,大家别笑话,欢迎指点。

2345截图20260912172103.png IMG_20260912_160501(1).jpg

  1. #include "stc8g.h"
  2. #include <intrins.h>
  3. #include <math.h>

  4. unsigned char sendBuf[6];

  5. #define  u8 unsigned char
  6. #define  u16 unsigned int
  7. #define  u32 unsigned long
  8. //----------------------------------
  9. typedef struct
  10. {
  11. float Sv;//用户设定值
  12. float Pv;

  13. float Kp;
  14. float T;  //PID计算周期--采样周期
  15. float Ti;
  16. float Td;
  17.         
  18. float Ek;  //本次偏差
  19. float Ek_1;//上次偏差
  20. float SEk; //历史偏差之和
  21.         
  22. float Iout;
  23. float Pout;
  24. float Dout;
  25.         
  26. float OUT0;

  27. float OUT;
  28.         
  29. unsigned int C10ms;
  30.         
  31. unsigned int pwmcycle;//pwm周期
  32.         
  33. }PID;

  34. xdata PID pid; //存放PID算法所需要的数据

  35. //--------------OLED12864-----------        
  36. sbit SCL = P3^2;
  37. sbit SDA = P3^3;

  38. #define OLED_CMD  0        //写命令
  39. #define OLED_DATA 1        //写数据
  40. #define OLED_MODE 0
  41. #define OLED_SCLK_Clr() SCL = 0
  42. #define OLED_SCLK_Set() SCL = 1
  43. #define OLED_SDIN_Clr() SDA = 0
  44. #define OLED_SDIN_Set() SDA = 1

  45. //OLED模式设置
  46. //0:4线串行模式
  47. //1:并行8080模式
  48. #define SIZE 16
  49. #define XLevelL                0x02
  50. #define XLevelH                0x10
  51. #define Max_Column        128
  52. #define Max_Row                64
  53. #define        Brightness        0xFF
  54. #define X_WIDTH         128
  55. #define Y_WIDTH         64


  56. const unsigned char code F6x8[][6] =
  57. {
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
  59. 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
  60. 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
  61. 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
  62. 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
  63. 0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
  64. 0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
  65. 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
  66. 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
  67. 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
  68. 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
  69. 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
  70. 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
  71. 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
  72. 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
  73. 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
  74. 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
  75. 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
  76. 0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
  77. 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
  78. 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
  79. 0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
  80. 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
  81. 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
  82. 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
  83. 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
  84. 0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
  85. 0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
  86. 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
  87. 0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
  88. 0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
  89. 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
  90. 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
  91. 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
  92. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
  93. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
  94. 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
  95. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
  96. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
  97. 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
  98. 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
  99. 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
  100. 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
  101. 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
  102. 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
  103. 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
  104. 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
  105. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
  106. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
  107. 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
  108. 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
  109. 0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
  110. 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
  111. 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
  112. 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
  113. 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
  114. 0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
  115. 0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
  116. 0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
  117. 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
  118. 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
  119. 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
  120. 0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
  121. 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
  122. 0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
  123. 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
  124. 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
  125. 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
  126. 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
  127. 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
  128. 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
  129. 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
  130. 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
  131. 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
  132. 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
  133. 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
  134. 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
  135. 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
  136. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
  137. 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
  138. 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
  139. 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
  140. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
  141. 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
  142. 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
  143. 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
  144. 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
  145. 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
  146. 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
  147. 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
  148. 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
  149. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
  150. };
  151. /****************************************8*16的点阵************************************/
  152. const unsigned char code F8X16[]=
  153. {
  154.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  155.   0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  156.   0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  157.   0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  158.   0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  159.   0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  160.   0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  161.   0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  162.   0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  163.   0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  164.   0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  165.   0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  166.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  167.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  168.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  169.   0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  170.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  171.   0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  172.   0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  173.   0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  174.   0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  175.   0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  176.   0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  177.   0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  178.   0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  179.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  180.   0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  181.   0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  182.   0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  183.   0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  184.   0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  185.   0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  186.   0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  187.   0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  188.   0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  189.   0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  190.   0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  191.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  192.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  193.   0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  194.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  195.   0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  196.   0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  197.   0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  198.   0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  199.   0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  200.   0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  201.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  202.   0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  203.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  204.   0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  205.   0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  206.   0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  207.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  208.   0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  209.   0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  210.   0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  211.   0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  212.   0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  213.   0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  214.   0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  215.   0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  216.   0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  217.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  218.   0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  219.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  220.   0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  221.   0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  222.   0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  223.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  224.   0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  225.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  226.   0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  227.   0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  228.   0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  229.   0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  230.   0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  231.   0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  232.   0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  233.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  234.   0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  235.   0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  236.   0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  237.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  238.   0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  239.   0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  240.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  241.   0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  242.   0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  243.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  244.   0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  245.   0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  246.   0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  247.   0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  248.   0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
  249. };
  250. const unsigned char code Hzk[][32]={

  251. {0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00},
  252. {0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00},/*"设",0*/
  253. /* (16 X 16 , ?? )*/

  254. {0x00,0x17,0x15,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x15,0x17,0x00,0x00},
  255. {0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x40,0x40,0x00},/*"置",1*/
  256. /* (16 X 16 , ?? )*/

  257. {0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
  258. {0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},/*"温",2*/
  259. /* (16 X 16 , ?? )*/

  260. {0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00},
  261. {0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},/*"度",3*/
  262. /* (16 X 16 , ?? )*/

  263. {0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00},
  264. {0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00},/*"℃",4*/
  265. /* (16 X 16 , ?? )*/

  266. };
  267. //---------------函数声明----------------------
  268. void IIC_Start();
  269. void IIC_Stop();
  270. void IIC_Wait_Ack();
  271. void Write_IIC_Byte(unsigned char IIC_Byte);
  272. void Write_IIC_Command(unsigned char IIC_Command);
  273. void Write_IIC_Data(unsigned char IIC_Data);
  274. void OLED_WR_Byte(unsigned dat,unsigned cmd);
  275. void fill_picture(unsigned char fill_Data);
  276. void OLED_Set_Pos(unsigned char x, unsigned char y);
  277. void OLED_Display_On(void);
  278. void OLED_Display_Off(void);
  279. void OLED_Clear(void);
  280. void OLED_On(void);
  281. void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size);
  282. u32 oled_pow(u8 m,u8 n);
  283. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2);
  284. void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size);
  285. void OLED_ShowCHinese(u8 x,u8 y,u8 no);
  286. void OLED_Init(void);
  287. void Timer_Init(void);
  288. void gpio_init(void);
  289. void ADC_Init(void);
  290. unsigned int ADC_OUT(unsigned char CH);
  291. void Delay1us();
  292. void Delay100ms();
  293. unsigned int PIDout();
  294. void PWM2_Set_Duty(u16 Duty);
  295. void PCA_Init();
  296. float ADC_Convert(unsigned char ch);
  297. unsigned int PID_Calculation();  //pid计算
  298. void PID_Init(void);
  299. void Delay50ms(void);        //@6.000MHz
  300. /**********************************************
  301. //IIC Start
  302. **********************************************/
  303. void IIC_Start()
  304. {

  305.         OLED_SCLK_Set() ;
  306.         OLED_SDIN_Set();
  307.         OLED_SDIN_Clr();
  308.         OLED_SCLK_Clr();
  309. }

  310. /**********************************************
  311. //IIC Stop
  312. **********************************************/
  313. void IIC_Stop()
  314. {
  315.   OLED_SCLK_Set() ;
  316. //        OLED_SCLK_Clr();
  317.         OLED_SDIN_Clr();
  318.         OLED_SDIN_Set();

  319. }

  320. void IIC_Wait_Ack()
  321. {
  322.         OLED_SCLK_Set() ;
  323.         OLED_SCLK_Clr();
  324. }
  325. /**********************************************
  326. // IIC Write byte
  327. **********************************************/

  328. void Write_IIC_Byte(unsigned char IIC_Byte)
  329. {
  330.         unsigned char i;
  331.         unsigned char m,da;
  332.         da=IIC_Byte;
  333.         OLED_SCLK_Clr();
  334.         for(i=0;i<8;i++)
  335.         {
  336.                         m=da;
  337.                 //        OLED_SCLK_Clr();
  338.                 m=m&0x80;
  339.                 if(m==0x80)
  340.                 {OLED_SDIN_Set();}
  341.                 else OLED_SDIN_Clr();
  342.                         da=da<<1;
  343.                 OLED_SCLK_Set();
  344.                 OLED_SCLK_Clr();
  345.                 }


  346. }
  347. /**********************************************
  348. // IIC Write Command
  349. **********************************************/
  350. void Write_IIC_Command(unsigned char IIC_Command)
  351. {
  352.    IIC_Start();
  353.    Write_IIC_Byte(0x78);            
  354.         IIC_Wait_Ack();
  355.    Write_IIC_Byte(0x00);               
  356.         IIC_Wait_Ack();
  357.    Write_IIC_Byte(IIC_Command);
  358.         IIC_Wait_Ack();
  359.    IIC_Stop();
  360. }
  361. /**********************************************
  362. // IIC Write Data
  363. **********************************************/
  364. void Write_IIC_Data(unsigned char IIC_Data)
  365. {
  366.    IIC_Start();
  367.    Write_IIC_Byte(0x78);
  368.         IIC_Wait_Ack();
  369.    Write_IIC_Byte(0x40);                        
  370.         IIC_Wait_Ack();
  371.    Write_IIC_Byte(IIC_Data);
  372.         IIC_Wait_Ack();
  373.    IIC_Stop();
  374. }
  375. void OLED_WR_Byte(unsigned dat,unsigned cmd)
  376. {
  377.         if(cmd)
  378.                         {

  379.    Write_IIC_Data(dat);

  380.                 }
  381.         else {
  382.    Write_IIC_Command(dat);

  383.         }
  384. }

  385. /********************************************
  386. // fill_Picture
  387. ********************************************/
  388. //
  389. void fill_picture(unsigned char fill_Data)
  390. {
  391.         unsigned char m,n;
  392.         for(m=0;m<8;m++)
  393.         {
  394.                 OLED_WR_Byte(0xb0+m,0);               
  395.                 OLED_WR_Byte(0x00,0);               
  396.                 OLED_WR_Byte(0x10,0);               
  397.                 for(n=0;n<128;n++)
  398.                         {
  399.                                 OLED_WR_Byte(fill_Data,1);
  400.                         }
  401.         }
  402. }
  403. //坐标设置
  404. void OLED_Set_Pos(unsigned char x, unsigned char y)
  405. {         OLED_WR_Byte(0xb0+y,OLED_CMD);
  406.         OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  407.         OLED_WR_Byte((x&0x0f),OLED_CMD);
  408. }
  409. //开启OLED显示
  410. void OLED_Display_On(void)
  411. {
  412.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  413.         OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  414.         OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  415. }
  416. //关闭OLED显示
  417. void OLED_Display_Off(void)
  418. {
  419.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  420.         OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  421.         OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  422. }
  423. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
  424. void OLED_Clear(void)
  425. {
  426.         u8 i,n;
  427.         for(i=0;i<8;i++)
  428.         {
  429.                 OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  430.                 OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  431.                 OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
  432.                 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  433.         } //更新显示
  434. }
  435. void OLED_On(void)
  436. {
  437.         u8 i,n;
  438.         for(i=0;i<8;i++)
  439.         {
  440.                 OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  441.                 OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  442.                 OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
  443.                 for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA);
  444.         } //更新显示
  445. }
  446. //在指定位置显示一个字符,包括部分字符
  447. //x:0~127
  448. //y:0~63
  449. //mode:0,反白显示;1,正常显示
  450. //size:选择字体 16/12
  451. void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size)
  452. {
  453.         unsigned char c=0,i=0;
  454.                 c=chr-' ';//得到偏移后的值
  455.                 if(x>Max_Column-1){x=0;y=y+2;}
  456.                 if(Char_Size ==16)
  457.                         {
  458.                         OLED_Set_Pos(x,y);
  459.                         for(i=0;i<8;i++)
  460.                         OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  461.                         OLED_Set_Pos(x,y+1);
  462.                         for(i=0;i<8;i++)
  463.                         OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  464.                         }
  465.                         else {
  466.                                 OLED_Set_Pos(x,y);
  467.                                 for(i=0;i<6;i++)
  468.                                 OLED_WR_Byte(F6x8[c][i],OLED_DATA);

  469.                         }
  470. }
  471. //m^n函数
  472. u32 oled_pow(u8 m,u8 n)
  473. {
  474.         u32 result=1;
  475.         while(n--)result*=m;
  476.         return result;
  477. }
  478. //显示2个数字
  479. //x,y :起点坐标
  480. //len :数字的位数
  481. //size:字体大小
  482. //mode:模式        0,填充模式;1,叠加模式
  483. //num:数值(0~4294967295);
  484. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
  485. {
  486.         u8 t,temp;
  487.         u8 enshow=0;
  488.         for(t=0;t<len;t++)
  489.         {
  490.                 temp=(num/oled_pow(10,len-t-1))%10;
  491.                 if(enshow==0&&t<(len-1))
  492.                 {
  493.                         if(temp==0)
  494.                         {
  495.                                 OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
  496.                                 continue;
  497.                         }else enshow=1;

  498.                 }
  499.                  OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
  500.         }
  501. }
  502. //显示一个字符号串
  503. void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size)
  504. {
  505.         unsigned char j=0;
  506.         while (chr[j]!='\0')
  507.         {
  508.                 OLED_ShowChar(x,y,chr[j],Char_Size);
  509.                 x+=8;
  510.                 if(x>120){x=0;y+=2;}
  511.             j++;
  512.         }
  513. }
  514. //显示汉字
  515. void OLED_ShowCHinese(u8 x,u8 y,u8 no)
  516. {
  517.         u8 t,adder=0;
  518.         OLED_Set_Pos(x,y);
  519.     for(t=0;t<16;t++)
  520.         {
  521.                 OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
  522.                 adder+=1;
  523.     }
  524.         OLED_Set_Pos(x,y+1);
  525.     for(t=0;t<16;t++)
  526.         {
  527.                 OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
  528.                 adder+=1;
  529.     }
  530. }

  531. //初始化SSD1306
  532. void OLED_Init(void)
  533. {
  534.   OLED_WR_Byte(0xAE,OLED_CMD);//--display off
  535.         OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  536.         OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  537.         OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
  538.         OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
  539.         OLED_WR_Byte(0x81,OLED_CMD); // contract control
  540.         OLED_WR_Byte(0xFF,OLED_CMD);//--128
  541.         OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
  542.         OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
  543.         OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  544.         OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
  545.         OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
  546.         OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
  547.         OLED_WR_Byte(0x00,OLED_CMD);//

  548.         OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
  549.         OLED_WR_Byte(0x80,OLED_CMD);//

  550.         OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
  551.         OLED_WR_Byte(0x05,OLED_CMD);//

  552.         OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
  553.         OLED_WR_Byte(0xF1,OLED_CMD);//

  554.         OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
  555.         OLED_WR_Byte(0x12,OLED_CMD);//

  556.         OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
  557.         OLED_WR_Byte(0x30,OLED_CMD);//

  558.         OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
  559.         OLED_WR_Byte(0x14,OLED_CMD);//

  560.         OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
  561. }

  562. //--------------------------------
  563. void Delay1us()               
  564. {
  565.         unsigned char i;
  566.         i = 4;
  567.         while (--i);
  568. }

  569. void Delay100ms(void)        
  570. {
  571.         unsigned char data i, j, k;

  572.         _nop_();
  573.         i = 7;
  574.         j = 23;
  575.         k = 105;
  576.         do
  577.         {
  578.                 do
  579.                 {
  580.                         while (--k);
  581.                 } while (--j);
  582.         } while (--i);
  583. }

  584. //---------------------------
  585. void ADC_Init(void)        
  586. {         
  587.     P_SW2 |= 0x80;      
  588.     ADCTIM = 0x3f;      
  589.     P_SW2 &= 0x7f;   

  590.     ADCCFG = 0x2f;      
  591.     ADC_CONTR = 0x80;
  592. }

  593. unsigned int ADC_OUT(unsigned char CH)
  594. {
  595.     unsigned int result;

  596.     ADC_CONTR = (ADC_CONTR & 0xF0) | (CH & 0x0F);

  597.     ADC_CONTR |= 0x40;      
  598.     _nop_();
  599.     _nop_();

  600.     while (!(ADC_CONTR & 0x20));   
  601.     ADC_CONTR &= ~0x20;            

  602.     result = ((unsigned int)ADC_RES << 8) | ADC_RESL;

  603.     return result;         
  604. }

  605. float ADC_Convert(unsigned char ch)//AD转换结果计算
  606. {
  607.         float AD_val=0;
  608.         char i;
  609.         for(i=0;i<6;i++)
  610.            {
  611.                    AD_val+=ADC_OUT(ch);
  612.                  }
  613.         AD_val=AD_val/6;//计算平均值
  614.         return AD_val;
  615. }
  616. //---------------------------------------------
  617. void gpio_init(void)
  618. {
  619.   P3M0 = 0x00;//P3.0,P3.1高阻,P3.2,P3.3准双向
  620.   P3M1 = 0x03;  
  621.   P5M0 = 0x10; //P5.4推挽 ,P5.5高阻
  622.         P5M1 = 0x20;
  623. }

  624. //-----------------------------
  625. void PCA_Init()
  626. {        
  627.         CCON=0x00;  //关闭PCA计数器,清除相关标志位
  628.         CMOD=0X08;//PCA时钟为系统时钟/1024//PWM频率=30MHZ/1024=29.29KHZ
  629.   CL  =0x00;  //计数器清零
  630.   CH  =0x00;
  631.         
  632. //-----------PWM2部分-----------------        
  633.   CCAPM2 = 0x40;  //失能PCA模块2_PWM输出
  634.   CCAP2L=0X00;    //捕获比较寄存器低8位,比较值
  635.   CCAP2H=0X00;    //捕获比较寄存器高8位,重装值
  636.   PCA_PWM2=0x00; //10位PWM输出=0XC0/8位PWM输出=0x00
  637.   CCAPM2=0x42; //使能PCA模块2_PWM输出
  638.                                 
  639.   CCON|=  1<<6;   //启动计数器
  640. }

  641. void PWM2_Set_Duty(u16 duty)   //P5.4
  642. {
  643.   PCA_PWM2&= ~(3<<4);        //清零重装值高2位
  644.         PCA_PWM2 = 0xc0|((duty>>4)&0x30);
  645.         CCAP2H=duty;          //重装值低8位
  646. }

  647. //------------------------------------------------------

  648. void PID_Init()
  649. {
  650.   pid.Sv=0;    //用户设定温度
  651.         pid.Kp=1;           //比例系数
  652.         pid.T=1000;    //PID计算周期
  653.   pid.Ti=26000;    //积分时间         
  654.         pid.Td=150;    //微分时间         
  655.         pid.OUT0=1;  
  656.         pid.SEk=0;
  657.         pid.pwmcycle=1023;
  658. }

  659. //OUT=(Kp*Ek) + (Kp*(T/Ti)∑Ek) + (Kp*(TD/T)(EK-Ek-1)) +OUT0
  660. unsigned int PID_Calculation()  //pid计算
  661. {
  662.          float DelEk;
  663.         float ti,ki;
  664.         float td;
  665.         float kd;
  666.         float out;
  667.         unsigned char index;

  668. /*-------------------------------------------------------*/
  669.          
  670.          pid.Ek=pid.Sv-pid.Pv;      //得到当前的偏差值
  671.          pid.Pout=pid.Kp*pid.Ek;    //比例输出
  672.          
  673.             
  674.          if(fabs(pid.Ek)<=30) //积分项不能过早介入,容易得到反效果。
  675.          {
  676.                  pid.SEk+=pid.Ek;        //历史偏差总和
  677.                  index=1;
  678.          }
  679.          else
  680.          {
  681.                  index=0;
  682.          }
  683.          
  684.          DelEk=pid.Ek-pid.Ek_1;  //最近两次偏差之差
  685.          
  686. /*--------------------------------------------------------*/
  687.          
  688.          ti=pid.T/pid.Ti;         
  689.          ki=ti*pid.Kp;                 
  690.          
  691.          pid.Iout=ki*pid.SEk*index;  //积分输出
  692.          
  693. /*--------------------------------------------------------*/
  694.         
  695.          td=pid.Td/pid.T;         
  696.                                                                                  
  697.          kd=pid.Kp*td;                 

  698.    pid.Dout=kd*DelEk;    //微分输出
  699.          
  700. /*--------------------------------------------------------*/

  701.    out= pid.Pout+pid.Iout+pid.Dout;
  702.          
  703.          
  704. //         out= pid.Pout + pid.Iout;
  705.          
  706.                                                                           
  707. /*-----------------------------*/

  708. if(out>pid.pwmcycle)
  709. {
  710.   pid.OUT=pid.pwmcycle;
  711. }
  712. else if(out<pid.OUT0)
  713. {
  714.   pid.OUT=pid.OUT0;
  715. }
  716. else
  717. {
  718.   pid.OUT=out;
  719. }
  720. pid.Ek_1=pid.Ek;  //更新偏差

  721. return  (u16)pid.OUT; //更新输出
  722. }

  723. //---------------------------------
  724. void Delay50ms(void)        //@6.000MHz
  725. {
  726.         unsigned char data i, j, k;

  727.         i = 2;
  728.         j = 134;
  729.         k = 152;
  730.         do
  731.         {
  732.                 do
  733.                 {
  734.                         while (--k);
  735.                 } while (--j);
  736.         } while (--i);
  737. }


  738. //-----------------------------
  739. void main(void)
  740. {
  741.         unsigned int temp_sz=0;
  742.         unsigned int adc_sz=0;
  743.         unsigned int Out=0;
  744.         
  745.         PID_Init();
  746.         gpio_init();
  747.         PCA_Init();        
  748.         ADC_Init();
  749.         Delay100ms();        
  750.         
  751.   EA=1;
  752.         
  753.         OLED_Init();
  754.         OLED_Clear();
  755.         
  756.         OLED_ShowCHinese(0,0,0);//设
  757.         OLED_ShowCHinese(16,0,1);//置
  758.         OLED_ShowCHinese(32,0,2);//温
  759.         OLED_ShowCHinese(48,0,3);//度
  760.         OLED_ShowString(64,0,":",16);
  761.         OLED_ShowCHinese(112,4,4);//℃
  762.         
  763. while(1)
  764. {
  765.             Delay50ms();
  766.         
  767.             pid.Sv=ADC_Convert(0);//采集设置温度P3.0
  768.                   pid.Pv=ADC_Convert(1);//采集实际温度P3.1
  769.                
  770.             adc_sz=pid.Sv;
  771.         
  772.             Out=PID_Calculation();
  773.         
  774.                         PWM2_Set_Duty(Out);

  775.                   temp_sz=adc_sz*500./1023;                                                   
  776.                
  777.                         sendBuf[0]=temp_sz/100%10;
  778.                   sendBuf[1]=temp_sz/10%10;
  779.                   sendBuf[2]=temp_sz%10;
  780.                         
  781.                   if(sendBuf[0] == 0)
  782.                   {
  783.                           OLED_ShowString(64,4," ",16);
  784.                   }else{
  785.                     OLED_ShowNum(64,4,sendBuf[0],1,16);
  786.                   }
  787.                         if(sendBuf[0] == 0 && sendBuf[1] == 0)
  788.                         {
  789.                                 OLED_ShowString(72,4," ",16);
  790.       }else{
  791.         OLED_ShowNum(72,4,sendBuf[1],1,16);
  792.                         }
  793.                     OLED_ShowNum(80,4,sendBuf[2],1,16);
  794.         }                                                               
  795. }
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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