/Modules/Sensors/ALTIMET01A/SW/MPL3115/MPL3115.c
0,0 → 1,105
void mpl3115_setA (void) //nastavení pro výšku
{
 
i2c_start(); //STANDBY mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB8);
i2c_stop();
i2c_start(); //PT_DATA_CFG set
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x13);
I2C_write(0x07); //hodnota
i2c_stop();
i2c_start(); //ACTIVE mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB9);
i2c_stop();
}
void mpl3115_setP (void) //nastavení pro tlak
{
 
i2c_start(); //STANDBY mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB8);
i2c_stop();
i2c_start(); //PT_DATA_CFG set
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x13);
I2C_write(0x07); //hodnota
i2c_stop();
i2c_start(); //ACTIVE mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0x39);
i2c_stop();
}
 
 
byte mpl3115_read (byte reg)
{
byte i;
i2c_start();
I2C_Write(MPL3115_ADDR_W);
I2C_write(reg);
i2c_start();
I2C_Write(MPL3115_ADDR_R);
i=i2c_read(0);
i2c_stop();
return i;
}
 
 
float mpl3115_T (void) //teplota ve stupnich
{
int m;
float l, t;
m = mpl3115_read (0x04);
l = (float)(mpl3115_read(0x05)>>4)/16.0;
t = (float)(M + L);
return t;
}
 
float mpl3115_A (void) //vyska v m
{
 
int16 m, c;
float l, a;
m = mpl3115_read (0x01);
c = mpl3115_read (0x02);
l = (float)(mpl3115_read(0x03)>>4)/16.0;
a = (float)((m << 8)|c) + l;
return a;
}
 
 
float mpl3115_P (void) //tlak v Pa
{
unsigned int32 m;
unsigned int16 c;
unsigned int l;
float p, l1;
m = mpl3115_read (0x01);
c = mpl3115_read (0x02);
l = mpl3115_read(0x03);
 
l1= (float)(l>>4)/4.0;
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1;
 
return p;
}
 
/Modules/Sensors/ALTIMET01A/SW/MPL3115/MPL3115.h
0,0 → 1,10
//microchip pic library for Freescale MPL3115 barometer sensor
 
/*void mpl3115_setA (void) //setup sensor for altitude measurement
void mpl3115_setP (void) //setup sensor for preasure measurement
float mpl3115_T (void) //temperature in Celsius degrees
float mpl3115_A (void) //altitude in metres
float mpl3115_P (void) //preassure in pascals
*/
 
#include "MPL3115.c"
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.c
9,112 → 9,9
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni
#define MPL3115_ADDR_W 0xC0
 
#include "../MPL3115.h"
 
void mpl3115_setA (void) //nastavení pro výšku
{
 
i2c_start(); //STANDBY mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB8);
i2c_stop();
i2c_start(); //PT_DATA_CFG set
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x13);
I2C_write(0x07); //hodnota
i2c_stop();
i2c_start(); //ACTIVE mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB9);
i2c_stop();
}
void mpl3115_setP (void) //nastavení pro tlak
{
 
i2c_start(); //STANDBY mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0xB8);
i2c_stop();
i2c_start(); //PT_DATA_CFG set
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x13);
I2C_write(0x07); //hodnota
i2c_stop();
i2c_start(); //ACTIVE mode
I2C_Write(MPL3115_ADDR_W);
I2C_write(0x26);
I2C_write(0x39);
i2c_stop();
}
 
 
byte mpl3115_read (byte reg)
{
byte i;
i2c_start();
I2C_Write(MPL3115_ADDR_W);
I2C_write(reg);
i2c_start();
I2C_Write(MPL3115_ADDR_R);
i=i2c_read(0);
i2c_stop();
return i;
}
 
 
float mpl3115_T (void) //teplota ve stupnich
{
int m;
float l, t;
m = mpl3115_read (0x04);
l = (float)(mpl3115_read(0x05)>>4)/16.0;
t = (float)(M + L);
return t;
}
 
float mpl3115_A (void) //vyska v m
{
 
int16 m, c;
float l, a;
m = mpl3115_read (0x01);
c = mpl3115_read (0x02);
l = (float)(mpl3115_read(0x03)>>4)/16.0;
a = (float)((m << 8)|c) + l;
return a;
}
 
 
float mpl3115_P (void) //tlak v Pa
{
unsigned int32 m;
unsigned int16 c;
unsigned int l;
float p, l1;
m = mpl3115_read (0x01);
c = mpl3115_read (0x02);
l = mpl3115_read(0x03);
 
l1= (float)(l>>4)/4.0;
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1;
 
return p;
}
 
void main()
{
 
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.hex
281,4 → 281,4
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=79AB CREATED="06-VI-13 00:24"
;CRC=79AB CREATED="25-VIII-13 15:29"
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.pjt
17,9 → 17,11
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=main.c
2=main.h
3=C:\Program Files (x86)\PICC\devices\16F887.h
4=
2=..\MPL3115.h
3=main.h
4=C:\Program Files (x86)\PICC\devices\16F887.h
5=..\MPL3115.c
6=
[Target Data]
OptionString=-p +FM
FileList=Z:\home\kaklik\svnMLAB\Modules\Sensors\ALTIMET01A\SW\MPL3115\PIC16F887\main.c