/Modules/Sensors/ALTIMET01A/SW/MPL115A1/PIC/PIC16F887/MPL115A1.c
0,0 → 1,125
/*
MPL115A1 SDN - +3.3V (always power on)
MPL115A1 #CS - PIN_C2
MPL115A1 DOUT - PIN_C4
MPL115A1 DIN - PIN_C5
MPL115A1 SCLK - PIN_C3
MPL115A1 GND - GND
MPL115A1 VDD - +3.3V
*/
 
 
// SPI mode definitions.
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
 
float a0; // correctiaon coefficients
float b1;
float b2;
float c12;
 
 
void MPL_init()
{
unsigned int8 a0_MSB, a0_LSB;
unsigned int8 b1_MSB, b1_LSB;
unsigned int8 b2_MSB, b2_LSB;
unsigned int8 c12_MSB, c12_LSB;
 
output_low(CSN_SPI);
 
spi_write(0x88); // get MSB for a0
a0_MSB = spi_read(0x00);
spi_write(0x8A); // get LSB for a0
a0_LSB = spi_read(0x00);
 
spi_write(0x8C); // get MSB for b1
b1_MSB = spi_read(0x00);
spi_write(0x8E); // get LSB for b1
b1_LSB = spi_read(0x00);
 
spi_write(0x90); // get MSB for b2
b2_MSB = spi_read(0x00);
spi_write(0x92); // get LSB for b2
b2_LSB = spi_read(0x00);
 
spi_write(0x94); // get MSB for c12
c12_MSB = spi_read(0x00);
spi_write(0x96); // get LSB for c12
c12_LSB = spi_read(0x00);
 
spi_read(0x00);
output_high(CSN_SPI);
// translate to floating point number
a0 = ((unsigned int16) a0_MSB << 5) + (a0_LSB >> 3) + (a0_LSB & 0x07)/8.0;
b1 = ((((b1_MSB & 0x1F) * 0x100) + b1_LSB) / 8192.0) - 3;
b2 = ((((unsigned int16) (b2_MSB - 0x80) << 8) + b2_LSB)/ 16384.0) - 2;
c12 =(((c12_MSB * 0x100) + c12_LSB)/16777216.0);
}
 
float MPL_get_pressure()
{
unsigned int8 LSB_data, MSB_data;
unsigned int16 ADC_pressure, ADC_temperature;
float Pcomp;
 
output_low(CSN_SPI); //Start temperature and pressure conversion
spi_write(0x24);
spi_write(0x00);
output_high(CSN_SPI);
 
delay_ms(10);
output_low(CSN_SPI); // get MSB for Pressure
spi_write(0x80);
MSB_data = spi_read(0x00);
spi_write(0x82); // get LSB for Pressure
LSB_data = spi_read(0x00);
output_high(CSN_SPI);
 
ADC_pressure = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable
 
output_low(CSN_SPI);
spi_write(0x84);
MSB_data = spi_read(0x00);
spi_write(0x86); // get LSB for Temperature
LSB_data = spi_read(0x00);
spi_read(0x00);
output_high(CSN_SPI);
 
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable
Pcomp = (a0 + (b1 + c12 * ADC_temperature) * ADC_pressure + b2 * ADC_temperature ); // compute relative compensated pressure
 
return (Pcomp * ((115.0 - 50.0)/1023.0) + 50.0); // return absolute pressure
}
 
float MPL_get_temperature()
{
unsigned int8 LSB_data, MSB_data;
unsigned int16 ADC_temperature;
 
output_low(CSN_SPI); //Start temperature and pressure conversion
spi_write(0x22);
spi_write(0x00);
output_high(CSN_SPI);
 
delay_ms(10);
output_low(CSN_SPI);
spi_write(0x84);
MSB_data = spi_read(0x00);
spi_write(0x86); // get LSB for Temperature
LSB_data = spi_read(0x00);
spi_read(0x00);
output_high(CSN_SPI);
 
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable
return ( ((float) ADC_temperature - 498.0)/-5.35) + 25.0; // return temperature in deg C
}
 
/Modules/Sensors/ALTIMET01A/SW/MPL115A1/PIC/PIC16F887/main.c
0,0 → 1,30
#include <main.h>
 
/*
MPL115A1 SDN - +3.3V (always power on)
MPL115A1 #CS - PIN_C2
MPL115A1 DOUT - PIN_C4
MPL115A1 DIN - PIN_C5
MPL115A1 SCLK - PIN_C3
MPL115A1 GND - GND
MPL115A1 VDD - +3.3V
*/
 
#define CSN_SPI PIN_C2
#include "MPL115A1.c"
 
void main()
{
printf("Start \r\n");
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
output_high(CSN_SPI);
delay_ms(100);
 
MPL_init(); // get correction coefficients from the sensor
 
while(true)
{
printf("%f %f \r\n", MPL_get_pressure(), MPL_get_temperature());
delay_ms(500);
}
}
/Modules/Sensors/ALTIMET01A/SW/MPL115A1/PIC/PIC16F887/main.hex
0,0 → 1,280
:1000000007308A001C2F0000533A613974100D0527
:10001000000083168613831286130830F800102818
:100020000000F8172128F813C60C03188617031CC4
:100030008613781721287813F80B14281F2800003E
:1000400086173F308400840B23280000F81B1328F8
:10005000781B1B280800831603178C170C1400004C
:10006000000083120C087F3903196F280313B100B5
:1000700003170D080313B20003170F080313B3008F
:100080003108C6000920320803178D000313330816
:1000900003178F0083168C170C14000000008312C6
:1000A0000C0D0E0D7F3903196F280313B1000317D0
:1000B0000D080313B20003170F080313B300310830
:1000C000C6000920320803178D00031333080317F5
:1000D0008F008D0A03198F0A03132B2803170313AC
:1000E0008A110A12402F3B30840083130008031941
:1000F00086280230F800F701F70B7C28F80B7B28E4
:100100009730F700F70B8228800B792808008E3093
:10011000F7004208F8004108F900FA01F808031D49
:100120009B287908F800F9010830F702F808031D48
:100130009B28F701A3280310F81BA228F90DF80D3E
:10014000F7039B28F81308003E0803196929CA0021
:10015000420803196929CA02031CB3287F30CA0761
:1001600003186929B9288130CA02031C69290319B7
:1001700069294A08F700F801F901FA01C9013F08A5
:10018000C800C8174008C7004108C6001930CA0097
:100190004508C6020318DC280130C7020318DC2812
:1001A000C8020318DC28C9020318DC28C90AC80AD7
:1001B000C70A4508C6070E294408C7020318F728CE
:1001C0000130C8020318F728C9020318F728C90A22
:1001D000C80A4408C7074508C607031C0E29C70AF2
:1001E000031D0E29C80A031D0E29C90A0E2943083A
:1001F0008038C80203180D290130C90203180D29DF
:10020000C90A43088038C8074408C707031CEB28FD
:10021000C80A031DEB28C90AEB287A14CA0B112956
:100220001C290310C60DC70DC80DC90D0310FA0D0A
:10023000F90DF80DCB0DC8284B1C24290310F80C20
:10024000F90CFA0CCB0C2729F70303196929CB1BEE
:1002500050290310C60DC70DC80DC90D4508C602AB
:1002600003183C290130C70203183C29C8020318AF
:100270003C29C902031C5F294408C7020318472907
:100280000130C80203184729C902031C5F2943082B
:100290008038C802031850290130C902031C5F29A5
:1002A000FA0A031D5F29F90A031D5F29F80A031DD5
:1002B0005F29F70A03196929F80CF90CFA0C3F08B1
:1002C000CA004308CA06CA1F6729F8176D29F81320
:1002D0006D29F701F801F901FA010800803083184F
:1002E000C606CB01CC014208CA004608CA0641082E
:1002F00003195E2AC900F70045080319672AC902D5
:100300000319032A031CC1294608CF00CF17470849
:10031000CE004808CD00CC010310CF0CCE0CCD0C84
:10032000CC0CC90B8B29CA1F98294B147B2A4B1064
:1003300049104B16443084008313902A4B12CA1B79
:10034000AB29491CB629CF0CCE0CCD0CCC0CF70A2E
:100350000319762AB629CF1BB9290310CC0DCD0D70
:10036000CE0DCF0DF7030319762AAB294B17232A9D
:100370004B134208CA00CA1FBF29CF176F2ACF13D9
:100380006F2A4508C900F7004108C9024208CF009A
:10039000CF174308CE004408CD00CC010310CF0C8A
:1003A000CE0CCD0CCC0CC90BCD29CA1FDA29CB142D
:1003B0007B2ACB104910CB16483084008313902A37
:1003C000CB12CA1BED29491CF829CF0CCE0CCD0C41
:1003D000CC0CF70A0319762AF829CF1BFB29031046
:1003E000CC0DCD0DCE0DCF0DF7030319762AED29D7
:1003F000CB17232ACB134608CA00CA1F012ACF17DE
:100400006F2ACF136F2A4608CF00CF174708CE00B8
:100410004808CD00CA1F102ACF134B157B2A4B1159
:10042000CC014910443084008313902ACA1B392A16
:100430004208CA00491C232ACF0CCE0CCD0CCC0C90
:10044000F70A0319762ACC1F342ACD0A031D342A51
:10045000CE0A031D342ACF0A031D342ACF0CCE0C3A
:10046000CD0CF70A0319762A4B1BB829CB1BFA29A6
:10047000582A8030CF06CF1F412A7B2A4608CA005F
:100480004E2A4208CA00CF08031D4E2ACE08031D7B
:100490004E2ACD08031D4E2AF7016F2ACF1B582A7A
:1004A0000310CC0DCD0DCE0DCF0DF70B4E2A762AB5
:1004B000CA1F5C2ACF176F2ACF136F2A4508F7008F
:1004C0004608CF004708CE004808CD006F2A4108F3
:1004D000F7004208CF004308CE004408CD004F0883
:1004E000F8004E08F9004D08FA00AE2AF701F801AD
:1004F000F901FA01AE2ACC01CD09CE09CF09CC0908
:10050000CC0A031D892ACD0A031D892ACE0A0319A4
:10051000CF0A4B189729CB18D9294B190F2A3E2AF5
:100520000008CD07031C9A2ACE0A031D9A2ACF0A77
:100530000319491484030008CE07031CA22ACF0A1A
:100540000319491484030008801F803ACF07031859
:1005500049144B1A9E29CB1AE029162A080030119B
:100560003008831687008312071113088830930020
:100570008316140C031CB92A8312130893018316E3
:10058000140C031CC02A83121308B10013088A300C
:1005900093008316140C031CCA2A831213089301B8
:1005A0008316140C031CD12A83121308B2001308FB
:1005B0008C3093008316140C031CDB2A831213085F
:1005C00093018316140C031CE22A83121308B30050
:1005D00013088E3093008316140C031CEC2A83122C
:1005E000130893018316140C031CF32A83121308B7
:1005F000B4001308903093008316140C031CFD2ADA
:100600008312130893018316140C031C042B83120A
:100610001308B5001308923093008316140C031CC2
:100620000E2B8312130893018316140C031C152B35
:1006300083121308B6001308943093008316140C29
:10064000031C1F2B8312130893018316140C031C25
:10065000262B83121308B7001308963093008316D5
:10066000140C031C302B8312130893018316140CF3
:10067000031C372B83121308B80013089301831649
:10068000140C031C402B8312301130088316870092
:1006900083120715BA013108B900B90DBA0DB90DA9
:1006A000BA0DB90DBA0DB90DBA0DB90DBA0DE030CC
:1006B000B905320CF700F70CF70C1F30F705770877
:1006C000B9070318BA0A32080739C201C1008720E6
:1006D0007A08C1007908C0007808BF007708BE001A
:1006E000C501C401C3018230C200A4207708BD0047
:1006F0007808BE007908BF007A08C0003A08C20036
:100700003908C100872083107A08C4007908C30023
:100710007808C2007708C1004008C8003F08C70039
:100720003E08C6003D08C5006E217A08A30079087E
:10073000A2007808A1007708A00033081F39FA0149
:10074000BA00B9013408B9070318BA0A3A08C20056
:100750003908C10087207A08C1007908C0007808EC
:10076000BF007708BE00C501C401C3018C30C200C0
:10077000A4207708B9007808BA007908BB007A0885
:10078000BC0083147A08C4007908C3007808C2004A
:100790007708C100C801C7014030C6008030C500DD
:1007A0006E217A08A7007908A6007808A5007708C6
:1007B000A40080303502BA01B900BA00B901360888
:1007C000B9070318BA0A3A08C2003908C1008720DD
:1007D0007A08C1007908C0007808BF007708BE0019
:1007E000C501C401C3018D30C200A4207708B9003F
:1007F0007808BA007908BB007A08BC0083147A082C
:10080000C4007908C3007808C2007708C100C80195
:10081000C701C6018030C5006E217A08AB00790897
:10082000AA007808A9007708A800FA013708BA00DA
:10083000B9013808B9070318BA0A3A08C2003908DA
:10084000C10087207A08C1007908C0007808BF007D
:100850007708BE00C501C401C3019730C200A420BF
:100860007A08AF007908AE007808AD007708AC00D0
:100870008A110A12602F46080319AB2CCE004A08D1
:100880000319AB2CCE0703184C2C7F30CE02031C6F
:10089000AB2C0319AB2C502C8130CE070318AB2C9A
:1008A0004E08F700F801F901FA014708D200D21703
:1008B0004808D1004908D0001830CE00CF01501CA4
:1008C000792C4D08FA07031C6B2CF90A031D6B2CBD
:1008D000F80A0319CF174C08F907031C722CF80A01
:1008E0000319CF174B08C800C8174808F8070318A2
:1008F000CF17CF0DF80CF90CFA0CD20CD10CD00C90
:100900000310CE0B5E2C0130F7070318AB2CF81B3D
:10091000902CD20DFA0DF90DF80DF7030319AB2C3D
:10092000D21FA12CFA0A031DA12CF90A031DA12C28
:10093000F80A031DA12CF80CF90CFA0CF70A03199C
:10094000AB2C4708CF004B08CF06CF1FA92CF817B8
:10095000AF2CF813AF2CF701F801F901FA010800E8
:1009600030113008831687008312071113082430D2
:1009700093008316140C031CBA2C831213089301E2
:100980008316140C031CC12C8312301130088316FB
:100990008700831207150A30BB007320301130081E
:1009A0008316870083120711130880309300831683
:1009B000140C031CD82C8312130893018316140CF7
:1009C000031CDF2C83121308B2001308823093003B
:1009D0008316140C031CE92C83121308930183164D
:1009E000140C031CF02C83121308B10030113008D2
:1009F0008316870083120715BC013208BB00BC00B8
:100A0000BB013108BB070318BC0A3C0CB4003B0C0B
:100A1000B300B40CB30CB40CB30CB40CB30CB40CE6
:100A2000B30CB40CB30C0330B4053011300883168A
:100A30008700831207111308843093008316140C67
:100A4000031C1F2D8312130893018316140C031C1F
:100A5000262D83121308B2001308863093008316E4
:100A6000140C031C302D8312130893018316140CED
:100A7000031C372D83121308B1001308930183164A
:100A8000140C031C402D831230113008831687008C
:100A900083120715BC013208BB00BC00BB01310842
:100AA000BB070318BC0A3C0CB6003B0CB500B60CE7
:100AB000B50CB60CB50CB60CB50CB60CB50CB60C2A
:100AC000B50C0330B6053608C2003508C1008720D2
:100AD0002F08C9002E08C8002D08C7002C08C60022
:100AE0007A08CD007908CC007808CB007708CA00D6
:100AF0003B2483102708C4002608C3002508C20031
:100B00002408C1007A08C8007908C7007808C60020
:100B10007708C5006E217708BB007808BC0079080B
:100B2000BD007A08BE003408C2003308C100872027
:100B30003E08C9003D08C8003C08C7003B08C60085
:100B40007A08CD007908CC007808CB007708CA0075
:100B50003B2483102308C4002208C3002108C200DC
:100B60002008C1007A08C8007908C7007808C600C4
:100B70007708C5006E217708BB007808BC007908AB
:100B8000BD007A08BE003608C2003508C1008720C3
:100B90002B08C9002A08C8002908C7002808C60071
:100BA0007A08CD007908CC007808CB007708CA0015
:100BB0003B2483103E08C4003D08C3003C08C2002B
:100BC0003B08C1007A08C8007908C7007808C60049
:100BD0007708C5006E217A08BA007908B90078084C
:100BE000B8007708B7003A08C9003908C8003808C3
:100BF000C7003708C6008830CD002030CC00023056
:100C0000CB007B30CA003B247708BB007808BC00CF
:100C10007908BD007A08BE0083107A08C4007908FC
:100C2000C3007808C2007708C100C801C701483076
:100C3000C6008430C5006E218A110A12612F30115E
:100C4000300883168700831207111308223093009F
:100C50008316140C031C292E831213089301831688
:100C6000140C031C302E83123011300883168700B9
:100C7000831207150A30BB00732030113008831629
:100C80008700831207111308843093008316140C15
:100C9000031C472E8312130893018316140C031CA4
:100CA0004E2E83121308B600130886309300831665
:100CB000140C031C582E8312130893018316140C72
:100CC000031C5F2E83121308B500130893018316CB
:100CD000140C031C682E8312301130088316870011
:100CE00083120715BA013608B900BA00B9013508F0
:100CF000B9070318BA0A3A0CB800390CB700B80C97
:100D0000B70CB80CB70CB80CB70CB80CB70CB80CC7
:100D1000B70C0330B8053808C2003708C100872077
:100D20007708B9007808BA007908BB007A08BC00D7
:100D300083147A08C4007908C3007808C2007708D1
:100D4000C100C801C7017930C6008730C5006E21D7
:100D50007708B9007808BA007908BB007A08BC00A7
:100D6000C1007908C0007808BF007708BE003330A2
:100D7000C500C400AB30C3008130C200A420770896
:100D8000B9007808BA007908BB007A08BC00831063
:100D90007A08C4007908C3007808C2007708C10047
:100DA000C801C7014830C6008330C5006E218A11D2
:100DB0000A126A2FF701F801F901FA01CE01CF01F9
:100DC000D001D1014D084C044B044A040319182FDB
:100DD0002030D2000310C60DC70DC80DC90DCE0DB1
:100DE000CF0DD00DD10D4D085102031D012F4C0820
:100DF0005002031D012F4B084F02031D012F4A080B
:100E00004E02031C122F4A08CE024B08031C4B0F44
:100E1000CF024C08031C4C0FD0024D08031C4D0F91
:100E2000D1020314F70DF80DF90DFA0DD20BEA2ECD
:100E30004E30840083130800840183131F30830520
:100E4000713083168F000F0886138312861783165E
:100E500003170908C039890003131F129F120030BD
:100E6000031788008312870188018901FF3003136B
:100E7000B000043003178D0000308F0003132B28BF
:100E80009412B0123008831687008312301630088F
:100E9000831687008312B011300883168700223032
:100EA000831294004030831694008312301130086E
:100EB00083168700831207156430BB007320AF2AA6
:100EC000B02C7708B1007808B2007908B3007A082E
:100ED000B4001F2E7708B5007808B6007908B7006F
:100EE0007A08B800893084003408BC003308BB009D
:100EF0003208BA003108B9000230BD008A1500205E
:100F00008A112030C6000920893084003808BC00CE
:100F10003708BB003608BA003508B9000230BD00FA
:100F20008A1500208A112030C60009200D30C60025
:100F300009200A30C60009200230B100FA30BB0097
:0A0F40007320B10B9E2F602F630099
:101000000408BE003D08C000031921283C08C9009F
:101010003B08C8003A08C7003908C600CD01CC011A
:101020002030CB008230CA008A113B248A157A080E
:10103000BC007908BB007808BA007708B900C00B7B
:1010400006283C08C9003B08C8003A08C700390810
:10105000C6004608B63CC600FA014708CA00C717D2
:101060000310C70CC80CC90CFA0CF90CF80CF70CDF
:10107000C60B3028CA1F4728F709F809F909FA09E9
:10108000F70A0319F80A0319F90A0319FA0A7A0880
:10109000BC007908BB007808BA007708B900BC1F0B
:1010A0005E28BE03BE16B909BA09BB09BC09B90A54
:1010B0000319BA0A0319BB0A0319BC0A3B30C5005D
:1010C0009A30C400CA30C300C2010A30C0003D08D3
:1010D0000319BE0A3C08C9003B08C8003A08C7000B
:1010E0003908C6004508CD004408CC004308CB00B1
:1010F0004208CA008A11DA268A150008B900840A53
:101100000008BA00840A0008BB00840A0008BC007A
:10111000FD308407F708031DA0283D0A400203198B
:10112000A0283E080319A2280F39400203199A2863
:101130000318DA28BE1BDA283E1BA2282030D42848
:101140002030BE05BE1EB228BE123D08031DBE03E0
:101150007708BE002D30C6008A1109208A153E0886
:10116000F700BE013D084002031DC2287708BE00FB
:101170002E30C6008A1109208A153E08F70020305B
:10118000BE0500303030BE1ED428BE123D08031DFF
:10119000BE037708BE002D30C6008A1109208A15CB
:1011A0003E08F700BE013030F7077708C6008A1105
:1011B00009208A154508C9004408C8004308C7002B
:1011C0004208C600CD01CC01CB010A30CA008A1109
:1011D000DA268A157A08C5007908C4007808C300A1
:0A11E0007708C200C00B6A2808005F
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=77E3 CREATED="24-II-13 20:07"
/Modules/Sensors/ALTIMET01A/SW/MPL115A1/PIC/PIC16F887/main.pjt
0,0 → 1,31
[PROJECT]
Target=main.hex
Development_Mode=
Processor_Text=PIC16F887
ToolSuite=CCS
Processor=0x887F
[main]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=main.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=main.c
2=MPL115A1.c
3=
4=
5=..\ds1820.c
6=..\1wire.c
7=
[Target Data]
OptionString=-p +FM
FileList=D:\MLAB\Modules\Sensors\ALTIMET01A\SW\PIC\PIC16F887\main.c
[Units]
Count=1
1=main (main)
/Modules/Sensors/ALTIMET01A/SW/MPL115A1/PIC/PIC16F887/main.h
0,0 → 1,20
#include <16F887.h>
#device adc=10
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
 
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8)