Line 7... |
Line 7... |
7 |
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //rcv TXD xmit RXD |
7 |
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //rcv TXD xmit RXD |
8 |
|
8 |
|
9 |
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni |
9 |
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni |
10 |
#define MPL3115_ADDR_W 0xC0 |
10 |
#define MPL3115_ADDR_W 0xC0 |
11 |
|
11 |
|
- |
|
12 |
#include "../MPL3115.h" |
12 |
|
13 |
|
13 |
void mpl3115_setA (void) //nastavení pro výku |
- |
|
14 |
{ |
- |
|
15 |
|
- |
|
16 |
|
- |
|
17 |
i2c_start(); //STANDBY mode |
- |
|
18 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
19 |
I2C_write(0x26); |
- |
|
20 |
I2C_write(0xB8); |
- |
|
21 |
i2c_stop(); |
- |
|
22 |
|
- |
|
23 |
i2c_start(); //PT_DATA_CFG set |
- |
|
24 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
25 |
I2C_write(0x13); |
- |
|
26 |
I2C_write(0x07); //hodnota |
- |
|
27 |
i2c_stop(); |
- |
|
28 |
|
- |
|
29 |
i2c_start(); //ACTIVE mode |
- |
|
30 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
31 |
I2C_write(0x26); |
- |
|
32 |
I2C_write(0xB9); |
- |
|
33 |
i2c_stop(); |
- |
|
34 |
} |
- |
|
35 |
|
- |
|
36 |
void mpl3115_setP (void) //nastavení pro tlak |
- |
|
37 |
{ |
- |
|
38 |
|
- |
|
39 |
|
- |
|
40 |
i2c_start(); //STANDBY mode |
- |
|
41 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
42 |
I2C_write(0x26); |
- |
|
43 |
I2C_write(0xB8); |
- |
|
44 |
i2c_stop(); |
- |
|
45 |
|
- |
|
46 |
i2c_start(); //PT_DATA_CFG set |
- |
|
47 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
48 |
I2C_write(0x13); |
- |
|
49 |
I2C_write(0x07); //hodnota |
- |
|
50 |
i2c_stop(); |
- |
|
51 |
|
- |
|
52 |
i2c_start(); //ACTIVE mode |
- |
|
53 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
54 |
I2C_write(0x26); |
- |
|
55 |
I2C_write(0x39); |
- |
|
56 |
i2c_stop(); |
- |
|
57 |
} |
- |
|
58 |
|
- |
|
59 |
|
- |
|
60 |
byte mpl3115_read (byte reg) |
- |
|
61 |
{ |
- |
|
62 |
byte i; |
- |
|
63 |
|
- |
|
64 |
i2c_start(); |
- |
|
65 |
I2C_Write(MPL3115_ADDR_W); |
- |
|
66 |
I2C_write(reg); |
- |
|
67 |
i2c_start(); |
- |
|
68 |
I2C_Write(MPL3115_ADDR_R); |
- |
|
69 |
i=i2c_read(0); |
- |
|
70 |
i2c_stop(); |
- |
|
71 |
|
- |
|
72 |
return i; |
- |
|
73 |
} |
- |
|
74 |
|
- |
|
75 |
|
- |
|
76 |
float mpl3115_T (void) //teplota ve stupnich |
- |
|
77 |
{ |
- |
|
78 |
int m; |
- |
|
79 |
float l, t; |
- |
|
80 |
|
- |
|
81 |
m = mpl3115_read (0x04); |
- |
|
82 |
l = (float)(mpl3115_read(0x05)>>4)/16.0; |
- |
|
83 |
t = (float)(M + L); |
- |
|
84 |
return t; |
- |
|
85 |
} |
- |
|
86 |
|
- |
|
87 |
float mpl3115_A (void) //vyska v m |
- |
|
88 |
{ |
- |
|
89 |
|
- |
|
90 |
int16 m, c; |
- |
|
91 |
float l, a; |
- |
|
92 |
|
- |
|
93 |
m = mpl3115_read (0x01); |
- |
|
94 |
c = mpl3115_read (0x02); |
- |
|
95 |
l = (float)(mpl3115_read(0x03)>>4)/16.0; |
- |
|
96 |
a = (float)((m << 8)|c) + l; |
- |
|
97 |
return a; |
- |
|
98 |
} |
- |
|
99 |
|
- |
|
100 |
|
- |
|
101 |
float mpl3115_P (void) //tlak v Pa |
- |
|
102 |
{ |
- |
|
103 |
unsigned int32 m; |
- |
|
104 |
unsigned int16 c; |
- |
|
105 |
unsigned int l; |
- |
|
106 |
float p, l1; |
- |
|
107 |
|
- |
|
108 |
m = mpl3115_read (0x01); |
- |
|
109 |
c = mpl3115_read (0x02); |
- |
|
110 |
l = mpl3115_read(0x03); |
- |
|
111 |
|
- |
|
112 |
l1= (float)(l>>4)/4.0; |
- |
|
113 |
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1; |
- |
|
114 |
|
- |
|
115 |
return p; |
- |
|
116 |
} |
- |
|
117 |
|
14 |
|
118 |
void main() |
15 |
void main() |
119 |
{ |
16 |
{ |
120 |
|
17 |
|
121 |
float p, t, a; |
18 |
float p, t, a; |