📄 readtemp.lst
字号:
C51 COMPILER V7.07 READTEMP 08/26/2006 11:15:05 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE READTEMP
OBJECT MODULE PLACED IN ReadTemp.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ReadTemp.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1
2 /*********************************************************************************************************
-****
3 * 函数名称 :
4 * 功能描述 :
5 * 实际参数 :
6 * 返回值 :
7 * 说明 :
8 **********************************************************************************************************
-****/
9
10 #include "define.h"
11
12 uchar Road_Dat ; // 路数
13 uchar Read_Number ; // 读温度次数
14 uchar Relay_Number = 0 ; // 每通一个继电器,读温度次数
15 uchar Old_Read_Number = 0 ;
16
17 uint xdata All_Temp0[5][12] ; // 5段温度,每段12个数值(求平均,头尾去掉两个)
18 uint xdata All_Temp1[5][12] ;
19
20 uchar xdata Thermocouple_Open[10] ; // 5路热电偶断开标志
21
22 uint xdata Fact_Temp[10] ; // 5路最终平均后的实际温度
23
24 uint xdata New_Temp[10] ; // 瞬间值(最新读出的温度值)
25
26 /*********************************************************************************************************
-****
27 * 函数名称 :
28 * 功能描述 :
29 * 实际参数 :
30 * 返回值 : 平均后的实际温度值
31 * 说明 : 排序,从小到大,在求平均值,
32 **********************************************************************************************************
-****/
33
34 uint FactTempDat(uint *addata,uchar a)
35 {
36 1 uchar i,j ;
37 1 uint t ; // 排序中的暂存器
38 1 uint average_data = 0 ;
39 1
40 1 for(i = 0;i < a;i++)
41 1 {
42 2 for(j = 0;j < (a -1)-i;j++)
43 2 {
44 3 if(addata[j] > addata[j + 1])
45 3 {
46 4 t = addata[j];
47 4 addata[j] = addata[j + 1];
48 4 addata[j + 1] = t;
49 4 }
50 3 }
51 2 }
C51 COMPILER V7.07 READTEMP 08/26/2006 11:15:05 PAGE 2
52 1
53 1 for (i = CLE_TEMPDAT;i < (a - CLE_TEMPDAT);i++) // 去掉头尾CLE_TEMPDAT个数值求平均值
54 1 {
55 2 average_data += *(addata + i) ; // 求和
56 2 }
57 1
58 1 j = (a - (CLE_TEMPDAT * 2)) ;
59 1 t = average_data / j ;
60 1 if ((average_data%j) >= (j >> 1)) // 四舍五入
61 1 t++ ;
62 1
63 1 addata[3] = t ; // 在下次求平均用
64 1 for(i = 0;i < 6;i++)
65 1 {
66 2 addata[a-1-i] = addata[a-4-i] ; // 把排列在中间的数值移到后面,为下次求平均用
67 2 }
68 1 return(t) ;
69 1 }
70 /*********************************************************************************************************
-****
71 * 函数名称 :
72 * 功能描述 :
73 * 实际参数 :
74 * 返回值 :
75 * 说明 : 读出MAX6675温度数据,低0位是热电藕开路标志,1为开路,低1,2为小数点,其余换算出来的就是十进制数
76 **********************************************************************************************************
-****/
77
78 uint Read_Max6675(void)
79 {
80 1 uchar c ;
81 1 uint temp_dat = 0 ; /* 存储读取的温度 */
82 1
83 1 SCK = 1 ; /* 下降沿输出数据 */
84 1 _nop_() ;
85 1
86 1 SCK = 0 ;
87 1 _nop_() ;
88 1 /* 第一位为0,输出数据高位开始 */
89 1 for(c=0;c<14;c++) /* 读出14个数据高位在前 */
90 1 {
91 2 temp_dat <<= 1 ;
92 2 if(SO == 1)
93 2 temp_dat |= 0x01 ;
94 2
95 2 SCK = 1 ; /* 下降沿输出数据 */
96 2 _nop_() ;
97 2
98 2 SCK = 0 ;
99 2 _nop_() ;
100 2 }
101 1 SCK = 1 ;
102 1 _nop_() ;
103 1
104 1 if((temp_dat & 0x01) == 1) /* 断线检测 */
105 1 temp_dat = 0x01 ; // 断线,温度为0度
106 1
107 1 return(temp_dat) ;
108 1 }
109
110 /*********************************************************************************************************
-****
C51 COMPILER V7.07 READTEMP 08/26/2006 11:15:05 PAGE 3
111 * 函数名称 : void NewTemp(uint temp0_dat,uint temp1_dat)
112 * 功能描述 :
113 * 实际参数 :
114 * 返回值 :
115 * 说明 : 求瞬间温度,每次继电器打通的平均值(每打通一次,读两次温度,才换下个继电器)
116 **********************************************************************************************************
-****/
117
118 void NewTemp(uint temp0_dat,uint temp1_dat)
119 {
120 1 uint temp_dat ;
121 1 uchar d ;
122 1
123 1 // 第一个MAX6675
124 1 if (!(temp0_dat & 0x0001))
125 1 {
126 2 temp_dat = (All_Temp0[Road_Dat][Read_Number] + All_Temp0[Road_Dat][Read_Number - 1]) ; // 放大十倍,
-0.25度
127 2 temp_dat >>= 1 ; // 去掉断线标志(保留了小数点位,所以实际的温度为增大了4倍)
128 2 New_Temp[Road_Dat] = temp_dat / 2 ; // 此温度值是大了4倍
129 2 if (Thermocouple_Open[Road_Dat] == 0x22)
130 2 Thermocouple_Open[Road_Dat] = 0x00 ; // 没断线标志,0x00为不加热,0x11为加热
131 2 }
132 1 else
133 1 {
134 2 New_Temp[Road_Dat] = 0 ; // 有断线,温度为0
135 2
136 2 Thermocouple_Open[Road_Dat] = 0x22 ; // 断线标志,为0x22
137 2
138 2 for (d = 0;d < 12;d++)
139 2 All_Temp0[Road_Dat][d] = 0 ; // 全清零
140 2 }
141 1
142 1 // 第二个MAX6675
143 1 if (!(temp1_dat & 0x0001))
144 1 {
145 2 temp_dat = (All_Temp1[Road_Dat][Read_Number] + All_Temp1[Road_Dat][Read_Number - 1]) ; // 放大十倍,
-0.25度
146 2 temp_dat >>= 1 ;
147 2 New_Temp[Road_Dat + 5] = temp_dat / 2 ;
148 2 if (Thermocouple_Open[Road_Dat + 5] == 0x22) ; // 没断线标志,为0
149 2 Thermocouple_Open[Road_Dat + 5] = 0x00 ;
150 2 }
151 1 else
152 1 {
153 2 New_Temp[Road_Dat + 5] = 0 ;
154 2
155 2 Thermocouple_Open[Road_Dat + 5] = 0x22 ; // 断线标志,为0x22
156 2
157 2 for (d = 0;d < 12;d++)
158 2 All_Temp1[Road_Dat][d] = 0 ; // 全清零
159 2 }
160 1 }
161
162 /*********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -