Line 1... |
Line 1... |
1 |
//Jan Chroust 15.4.2013 |
1 |
#define VERSION "0.1" |
2 |
|
- |
|
- |
|
2 |
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" |
3 |
|
3 |
|
4 |
#include "main.h" |
4 |
#include "main.h" |
5 |
|
5 |
|
6 |
#define EEPROM_SDA PIN_B0 |
- |
|
7 |
#define EEPROM_SCL PIN_B1 |
- |
|
8 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
6 |
#use i2c(master, sda=PIN_B0, scl=PIN_B1) |
9 |
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD |
7 |
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD |
10 |
|
8 |
|
11 |
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni |
9 |
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni |
12 |
#define MPL3115_ADDR_W 0xC0 |
10 |
#define MPL3115_ADDR_W 0xC0 |
13 |
|
11 |
|
Line 78... |
Line 76... |
78 |
float mpl3115_T (void) //teplota ve stupnich |
76 |
float mpl3115_T (void) //teplota ve stupnich |
79 |
{ |
77 |
{ |
80 |
int m; |
78 |
int m; |
81 |
float l, t; |
79 |
float l, t; |
82 |
|
80 |
|
83 |
m= mpl3115_read (0x04); |
81 |
m = mpl3115_read (0x04); |
84 |
l= (float)(mpl3115_read(0x05)>>4)/16.0; |
82 |
l = (float)(mpl3115_read(0x05)>>4)/16.0; |
85 |
t = (float)(M + L); |
83 |
t = (float)(M + L); |
86 |
return t; |
84 |
return t; |
87 |
} |
85 |
} |
88 |
|
86 |
|
89 |
float mpl3115_A (void) //vyska v m |
87 |
float mpl3115_A (void) //vyska v m |
90 |
{ |
88 |
{ |
91 |
|
89 |
|
92 |
int16 m, c; |
90 |
int16 m, c; |
93 |
float l, a; |
91 |
float l, a; |
94 |
|
92 |
|
95 |
m= mpl3115_read (0x01); |
93 |
m = mpl3115_read (0x01); |
96 |
c= mpl3115_read (0x02); |
94 |
c = mpl3115_read (0x02); |
97 |
l= (float)(mpl3115_read(0x03)>>4)/16.0; |
95 |
l = (float)(mpl3115_read(0x03)>>4)/16.0; |
98 |
a = (float)((m << 8)|c) + l; |
96 |
a = (float)((m << 8)|c) + l; |
99 |
return a; |
97 |
return a; |
100 |
} |
98 |
} |
101 |
|
99 |
|
102 |
|
100 |
|
Line 105... |
Line 103... |
105 |
unsigned int32 m; |
103 |
unsigned int32 m; |
106 |
unsigned int16 c; |
104 |
unsigned int16 c; |
107 |
unsigned int l; |
105 |
unsigned int l; |
108 |
float p, l1; |
106 |
float p, l1; |
109 |
|
107 |
|
110 |
m= mpl3115_read (0x01); |
108 |
m = mpl3115_read (0x01); |
111 |
c= mpl3115_read (0x02); |
109 |
c = mpl3115_read (0x02); |
112 |
l=mpl3115_read(0x03); |
110 |
l = mpl3115_read(0x03); |
113 |
|
111 |
|
114 |
l1= (float)(l>>4)/4.0; |
112 |
l1= (float)(l>>4)/4.0; |
115 |
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1; |
113 |
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1; |
116 |
|
114 |
|
117 |
return p; |
115 |
return p; |
Line 133... |
Line 131... |
133 |
mpl3115_setA(); //nastaveni pro vysku a teplotu |
131 |
mpl3115_setA(); //nastaveni pro vysku a teplotu |
134 |
delay_ms (500); |
132 |
delay_ms (500); |
135 |
a=mpl3115_A(); |
133 |
a=mpl3115_A(); |
136 |
|
134 |
|
137 |
|
135 |
|
138 |
printf("Teplota: %10.4f(stupne)\r\n", t); |
136 |
printf("Teplota: %1.4f\r\n", t); |
139 |
printf("Tlak: %10.4f(Pa)\r\n", p); |
137 |
printf("Tlak: %10.4f(Pa)\r\n", p); |
140 |
printf("Výka: %10.4f(m)\r\n", a); |
138 |
printf("Výka: %10.4f(m)\r\n", a); |
141 |
|
139 |
|
142 |
delay_ms (1000); |
140 |
delay_ms (1000); |
143 |
} |
141 |
} |
144 |
|
- |
|
145 |
|
- |
|
146 |
} |
142 |
} |
147 |
|
143 |
|
148 |
|
144 |
|