-
Notifications
You must be signed in to change notification settings - Fork 0
/
MS4525.c
94 lines (83 loc) · 1.99 KB
/
MS4525.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "SPD6000.h"
#include "intrins.h"
#include "math.h"
#include "global_var.h"
#include "MS4525.h"
#define SMOTH_NUMBER 3
//#define ZER0_SIZE 3
#define INTEGRAL_MAX 19
/*向传感器读取压差值*/
unsigned char MS4525DO_read(unsigned char * p,unsigned char* temperature)
{
unsigned char error = 0;
SS2= 0;
SCL = 1; //SDP600 系列传感器(从机) 可以拉低SCL线来强制主机进入等待状态。传感器通过释放SCL线指示内部处理已完成
*p = SPI_ReadByte(); //读取传感器第一个字节数据
*(p+1) = SPI_ReadByte(); //读取传感器数据第二个字节数据
*temperature = SPI_ReadByte();
*(temperature+1) = SPI_ReadByte();
SS2 = 1;
if((((*p)&0xc0) == 0xc0) || (((*p)&0x40) == 0x40))
{
error = 1;
}
*p = (*p)&0x3f;
return error;
}
void data_read_4525(Ms4515* date)
{
int dat1;
unsigned int temper;
if(MS4525DO_read((unsigned char*)&dat1,(unsigned char*)&temper) == 0)
{
if(dat1<=1638)
{
dat1 = 1638;
}
/* if(dat1>=14746)
{
dat1 = 14746;
} */
date->pressure = (dat1)*0.00789-12.928;// date->pressure = ((dat1)*0.07751938-635)-g_fZero;
if(date->pressure< 0.0)
{
date->pressure = 0.0;
}
temper = temper/32;
date->temperature = temper*0.0977-50;
if(date->temperature > 150.0)
{
date->temperature = 150.0;
}
else if(date->temperature < -50.0)
{
date->temperature = -50.0;
}
}
}
float date_Smooth_4525(float *tmp)
{
// static float pressre[SMOTH_NUMBER] = {0.0,0.0,0.0};
// float sum = 0;
static float sum_old = 0;
float ret ;
// char j=0;
// static char i = 0;
Ms4515 date1;
data_read_4525(&date1);
*tmp = date1.temperature;
// pressre[i] = date1.pressure;
// i++;
/* if(i == SMOTH_NUMBER)
{
i= 0;
}
for(j=0;j<SMOTH_NUMBER;j++)
{
sum = sum+pressre[j];
} */
// sum = sum/SMOTH_NUMBER;
ret = ((INTEGRAL_MAX+1-g_cIntegral)*date1.pressure+g_cIntegral*sum_old)/(INTEGRAL_MAX+1);
sum_old = ret;
return ret;
}