Problem with comparison.
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.c
0,0 → 1,144
#define VERSION "0.1"
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $"
 
#include "main.h"
 
#use i2c(master, sda=PIN_B0, scl=PIN_B1)
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
 
#define MPL3115_ADDR_R 0xC1 //addresa pro cteni
#define MPL3115_ADDR_W 0xC0
 
 
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()
{
 
float p, t, a;
printf("Tlakomer nebo vyskomer \r\n",);
while(TRUE)
{
mpl3115_setP(); //nastaveni pro tlak a teplotu
delay_ms (500);
t=mpl3115_T();
p=mpl3115_P();
mpl3115_setA(); //nastaveni pro vysku a teplotu
delay_ms (500);
a=mpl3115_A();
 
 
printf("Teplota: %1.4f\r\n", t);
printf("Tlak: %10.4f(Pa)\r\n", p);
printf("Výška: %10.4f(m)\r\n", a);
 
delay_ms (1000);
}
}
 
 
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.hex
0,0 → 1,284
:1000000008308A00002800005436E135EF366539A3
:10001000203765316F10F63CF335EF366539A006B1
:100020000A00D43270366F3A611DA0123117343392
:100030000D0500005436E1353A10A5183017343359
:100040002828E1140D0500015634FD349A346B3430
:1000500061343A3420342534313430342E3434345D
:10006000663428346D3429340D340A340034831650
:100070008611831286110830F8003E280000F81718
:100080004F28F813BA0C03188615031C861178172D
:100090004F287813F80B42284D28000086153F3072
:1000A0008400840B51280000F81B4128781B492844
:1000B0000800831603178C170C140000000083122D
:1000C0000C087F3903199D280313AD0003170D0891
:1000D0000313AE0003170F080313AF002D08BA0077
:1000E00037202E0803178D0003132F0803178F00E6
:1000F00083168C170C140000000083120C0D0E0DDB
:100100007F3903199D280313AD0003170D0803134E
:10011000AE0003170F080313AF002D08BA003720F5
:100120002E0803178D0003132F0803178F008D0A65
:1001300003198F0A03135928031703138A150A1288
:1001400021280830F8000000861083168610000071
:100150008312BE0D0610031CB028831606148312EA
:100160000318B5288316061083128316861483128B
:10017000861CB828F80BA32800008610831686106A
:10018000000006140000000086148312861CC62896
:10019000F801000006187814861083168610831262
:1001A000061083160610831208008316061400003A
:1001B00086140000831206108316061000008312B6
:1001C000861083168610C0308312BE00A120263010
:1001D000BE00A120B830BE00A1208316061000008A
:1001E00086148312861CF2280000F628000083166D
:1001F0000614000006140000861400008312061086
:100200008316061000008312861083168610C030F5
:100210008312BE00A1201330BE00A1200730BE0013
:10022000A12083160610000086148312861C16294E
:1002300000001A29000083160614000006140000AE
:100240008614000083120610831606100000831225
:10025000861083168610C0308312BE00A12026307F
:10026000BE00A1203930BE00A12083160610000078
:1002700086148312861C3A2900003E29000083164A
:100280000614000083128A150A1224282E308400D6
:1002900083130008031959290230F800F701F70BFE
:1002A0004F29F80B4E299730F700F70B5529800B93
:1002B0004C290800831606140000861400008312DF
:1002C000061083160610000083128610831686100F
:1002D000C0308312BE00A1203C08BE00A1208316BE
:1002E00006140000861400008312861C752906106F
:1002F0008316061000008312861083168610C13004
:100300008312BE00A120F7010830BF007708C000AB
:1003100083160614000086148312861C8D29061885
:100320000314061C0310F80D0000831686108312B8
:100330008610BF0B8829831606140000831206104E
:1003400040080319A629831606108312000083169D
:1003500086148312861CAA29000086108316861034
:100360000000831206108316061078088312BD0061
:1003700083160610000086148312861CBD29000017
:10038000C129000083160614000083123D08F800FE
:1003900008008E30F7003E08F8003D08F900FA0129
:1003A000F808031DDD297908F800F9010830F70283
:1003B000F808031DDD29F701E5290310F81BE429DE
:1003C000F90DF80DF703DD29F813080041080319AA
:1003D000AB2ACD0045080319AB2ACD02031CF52931
:1003E0007F30CD070318AB2AFB298130CD02031CD7
:1003F000AB2A0319AB2A4D08F700F801F901FA01FD
:10040000CC014208CB00CB174308CA004408C900FE
:100410001930CD004808C90203181E2A0130CA024B
:1004200003181E2ACB0203181E2ACC0203181E2A08
:10043000CC0ACB0ACA0A4808C907502A4708CA0288
:100440000318392A0130CB020318392ACC020318C9
:10045000392ACC0ACB0A4708CA074808C907031C2F
:10046000502ACA0A031D502ACB0A031D502ACC0A5F
:10047000502A46088038CB0203184F2A0130CC029C
:1004800003184F2ACC0A46088038CB074708CA070A
:10049000031C2D2ACB0A031D2D2ACC0A2D2A7A14DF
:1004A000CD0B532A5E2A0310C90DCA0DCB0DCC0DFE
:1004B0000310FA0DF90DF80DCE0D0A2A4E1C662A0E
:1004C0000310F80CF90CFA0CCE0C692AF703031987
:1004D000AB2ACE1B922A0310C90DCA0DCB0DCC0D31
:1004E0004808C90203187E2A0130CA0203187E2A6E
:1004F000CB0203187E2ACC02031CA12A4708CA0299
:100500000318892A0130CB020318892ACC02031C64
:10051000A12A46088038CB020318922A0130CC0267
:10052000031CA12AFA0A031DA12AF90A031DA12A04
:10053000F80A031DA12AF70A0319AB2AF80CF90CD3
:10054000FA0C4208CD004608CD06CD1FA92AF8179F
:10055000AF2AF813AF2AF701F801F901FA010800F0
:1005600080308318C806CD01CE014408CC0048086D
:10057000CC0643080319A02BCB00F700470803194A
:10058000A92BCB020319452B031C032B4808D100D0
:10059000D1174908D0004A08CF00CE010310D10C72
:1005A000D00CCF0CCE0CCB0BCD2ACC1FDA2A4D149D
:1005B000BD2B4D104B104D16463084008313D22BAB
:1005C0004D12CC1BED2A4B1CF82AD10CD00CCF0CB1
:1005D000CE0CF70A0319B82BF82AD11BFB2A0310FB
:1005E000CE0DCF0DD00DD10DF7030319B82BED2A89
:1005F0004D17652B4D134408CC00CC1F012BD11790
:10060000B12BD113B12B4708CB00F7004308CB0225
:100610004408D100D1174508D0004608CF00CE01CC
:100620000310D10CD00CCF0CCE0CCB0B0F2BCC1F4E
:100630001C2BCD14BD2BCD104B10CD164A30840091
:100640008313D22BCD12CC1B2F2B4B1C3A2BD10C4E
:10065000D00CCF0CCE0CF70A0319B82B3A2BD11BB8
:100660003D2B0310CE0DCF0DD00DD10DF703031987
:10067000B82B2F2BCD17652BCD134808CC00CC1FE2
:10068000432BD117B12BD113B12B4808D100D1176F
:100690004908D0004A08CF00CC1F522BD1134D156A
:1006A000BD2B4D11CE014B10463084008313D22B4D
:1006B000CC1B7B2B4408CC004B1C652BD10CD00CE5
:1006C000CF0CCE0CF70A0319B82BCE1F762BCF0A0E
:1006D000031D762BD00A031D762BD10A031D762B22
:1006E000D10CD00CCF0CF70A0319B82B4D1BFA2AEA
:1006F000CD1B3C2B9A2B8030D106D11F832BBD2BD9
:100700004808CC00902B4408CC00D108031D902B46
:10071000D008031D902BCF08031D902BF701B12BA0
:10072000D11B9A2B0310CE0DCF0DD00DD10DF70B91
:10073000902BB82BCC1F9E2BD117B12BD113B12BE3
:100740004708F7004808D1004908D0004A08CF0000
:10075000B12B4308F7004408D1004508D0004608F3
:10076000CF005108F8005008F9004F08FA00F02BAC
:10077000F701F801F901FA01F02BCE01CF09D009F8
:10078000D109CE09CE0A031DCB2BCF0A031DCB2BDB
:10079000D00A0319D10A4D18D92ACD181B2B4D198F
:1007A000512B802B0008CF07031CDC2BD00A031D24
:1007B000DC2BD10A03194B1484030008D007031C57
:1007C000E42BD10A03194B1484030008801F803ADC
:1007D000D10703184B144D1AE02ACD1A222B582B9F
:1007E00008000430BC005A217808AD000530BC0078
:1007F0005A21780EF7000F30F7057708BE01BD00CB
:10080000C9217708B6007808B7007908B8007A08D7
:10081000B900C4007908C3007808C2007708C10095
:10082000C801C701C6018330C500E6217A08B100BE
:100830007908B0007808AF007708AE00BE012D0837
:10084000BD00C92183107A08C6007908C500780860
:10085000C4007708C3003108CA003008C9002F0857
:10086000C8002E08C700B0227A08B5007908B40085
:100870007808B3007708B2003208F7003308F800B0
:100880003408F9003508FA008A150A1230280130B8
:10089000BC005A21B001AF01AE017808AD000230B2
:1008A000BC005A21B2017808B1000330BC005A21C3
:1008B0007808B300330EF7000F30F7057708BE0154
:1008C000BD00C9217708BD007808BE007908BF00C7
:1008D0007A08C000C4007908C3007808C20077080D
:1008E000C100C801C701C6018130C500E6217A08F0
:1008F000BB007908BA007808B9007708B800BD01D4
:100900002D0DBE002E0DBF002F0DC000BE0DBF0D62
:10091000C00DFC30BE05310DF900320DFA00F90DA5
:10092000FA0DFC30F9057908BD047A08BE04330ECF
:10093000F700F70CF70C0330F70577083D04F700D4
:100940003E08F8003F08F9004008FA007A08C6009F
:100950007908C5007808C4007708C300B630F700EE
:10096000FA01F901F8014308440445044604031D53
:10097000BB2CF701C82C0310F81BC72CC30DC40DEA
:10098000C50DC60DFA0DF90DF80DF70BBB2CF813BC
:100990007708BD007808BE007908BF007A08C0005B
:1009A00083107A08C6007908C5007808C400770863
:1009B000C3003B08CA003A08C9003908C800380813
:1009C000C700B0227A08B7007908B6007808B500E9
:1009D0007708B4003408F7003508F8003608F90045
:1009E0003708FA008A150A123B28831606140000FD
:1009F000861400008312061083160610000083126E
:100A0000861083168610C0308312BE00A1202630C7
:100A1000BE00A120B830BE00A12083160610000041
:100A200086148312861C122D0000162D00008316DA
:100A3000061400000614000086140000831206103D
:100A40008316061000008312861083168610C030AD
:100A50008312BE00A1201330BE00A1200730BE00CB
:100A6000A12083160610000086148312861C362DE2
:100A700000003A2D00008316061400000614000042
:100A800086140000831206108316061000008312DD
:100A9000861083168610C0308312BE00A120263037
:100AA000BE00A120B930BE00A120831606100000B0
:100AB00086148312861C5A2D00005E2D00008316BA
:100AC0000614000083128A150A1246280130BC0061
:100AD0005A21AE017808AD000230BC005A21B001A5
:100AE0007808AF000330BC005A21780EF7000F30B1
:100AF000F7057708BE01BD00C9217708B90078085D
:100B0000BA007908BB007A08BC00C4007908C300A9
:100B10007808C2007708C100C801C701C601833048
:100B2000C500E6217A08B4007908B3007808B2005D
:100B30007708B1002D08BB00BA013A082F04F7006E
:100B40002D083004FA007708BD007A08BE00C921DC
:100B50007708BA007808BB007908BC007A08BD00A5
:100B600083107A08C6007908C5007808C4007708A1
:100B7000C3003408CA003308C9003208C80031086D
:100B8000C700B0227A08B8007908B7007808B60024
:100B90007708B5003508F7003608F8003708F9007F
:100BA0003808FA008A150A125228831603178C1780
:100BB0000C14000000000318042E83120C087F3967
:100BC0000313AE0003170D080313AF0003170F083C
:100BD0000313B0002E08BA0037202F0803178D002A
:100BE0000313300803178F0083168C170C140000B2
:100BF000000083120313AD0BFE2D012E8316031785
:100C0000042E232E8316031783120C0D0E0D7F392D
:100C10000313AE0003170D080313AF0003170F08EB
:100C20000313B0002E08BA0037202F0803178D00D9
:100C30000313300803178F008D0A03198F0A03105E
:100C40000313AD0BD52D0800F701F801F901FA01E6
:100C5000C201C301C401C501410840043F043E0470
:100C60000319622E2030C6000310BA0DBB0DBC0D57
:100C7000BD0DC20DC30DC40DC50D41084502031DB8
:100C80004B2E40084402031D4B2E3F084302031D18
:100C90004B2E3E084202031C5C2E3E08C2023F0857
:100CA000031C3F0FC3024008031C400FC40241084D
:100CB000031C410FC5020314F70DF80DF90DFA0DD1
:100CC000C60B342E42308400831308000408B2009F
:100CD0003108B4000319F82E3008BD002F08BC00FD
:100CE0002E08BB002D08BA00C101C0012030BF0092
:100CF0008230BE003A080319EA2EC2003E080319EA
:100D0000EA2EC20703188B2E7F30C202031CEA2E84
:100D10000319EA2E8F2E8130C2070318EA2E4208EB
:100D2000F700F801F901FA013B08C600C6173C08B4
:100D3000C5003D08C4001830C200C301441CB82ED1
:100D40004108FA07031CAA2EF90A031DAA2EF80A65
:100D50000319C3174008F907031CB12EF80A031939
:100D6000C3173F08BC00BC173C08F8070318C3179B
:100D7000C30DF80CF90CFA0CC60CC50CC40C03100E
:100D8000C20B9D2E0130F7070318EA2EF81BCF2E59
:100D9000C60DFA0DF90DF80DF7030319EA2EC61F5B
:100DA000E02EFA0A031DE02EF90A031DE02EF80AD0
:100DB000031DE02EF80CF90CFA0CF70A0319EA2EC1
:100DC0003B08C3003F08C306C31FE82EF817EE2EEA
:100DD000F813EE2EF701F801F901FA017A08B000D4
:100DE0007908AF007808AE007708AD00B40B6C2E20
:100DF0003008BD002F08BC002E08BB002D08BA002B
:100E00003A08B63CBA00FA013B08BE00BB17031013
:100E1000BB0CBC0CBD0CFA0CF90CF80CF70CBA0BA3
:100E2000072FBE1F1E2FF709F809F909FA09F70A5B
:100E30000319F80A0319F90A0319FA0A7A08B00023
:100E40007908AF007808AE007708AD00B01F352FE5
:100E5000B203B216AD09AE09AF09B009AD0A031964
:100E6000AE0A0319AF0A0319B00A3B30B9009A3031
:100E7000B800CA30B700B6010A30B400310803190F
:100E8000B20A3008BD002F08BC002E08BB002D0898
:100E9000BA003908C1003808C0003708BF0036085A
:100EA000BE0024260008AD00840A0008AE00840AB3
:100EB0000008AF00840A0008B000FD308407F7087E
:100EC000031D752F310A34020319752F32080319D7
:100ED000772F0F39340203196F2F0318A72FB21B76
:100EE000A72F321B772F2030A32F2030B205B21E40
:100EF000852FB2123108031DB2037708B2002D30DE
:100F0000BA0037203208F700B20131083402031D5D
:100F1000932F7708B2002E30BA0037203208F7003E
:100F20002030B20500303030B21EA32FB21231088B
:100F3000031DB2037708B2002D30BA003720320803
:100F4000F700B2013030F7077708BA0037203908C8
:100F5000BD003808BC003708BB003608BA00C10124
:100F6000C001BF010A30BE0024267A08B900790802
:100F7000B8007808B7007708B600B40B412F080016
:100F8000831603178C170C140000000083120D0841
:100F90000313AE0003170F080313AF0003170C0869
:100FA0000313BA0037202E0803178D0003132F08F0
:100FB00003178F008D0A03198F0A0313AD0BC02F7F
:020FC000080027
:10100000840183131F308305713083168F000F080E
:10101000861183128615831603170908C0398900C3
:1010200003131F129F1200300317880083128701D9
:101030008801890104308D0000308F008A1103136C
:1010400059288A158A11D5288A150230AD00FA3040
:10105000AE008A1146218A15AD0B27288A11F12B83
:101060008A157A08A8007908A7007808A6007708EA
:10107000A5008A11472C8A157A08A4007908A300D4
:101080007808A2007708A1008A11F52C8A15023091
:10109000AD00FA30AE008A1146218A15AD0B492801
:1010A0008A11662D8A157A08AC007908AB00780899
:1010B000AA007708A900113003178D0000308F00B7
:1010C000031009300313AD008A11D5258A15893024
:1010D00084002808B0002708AF002608AE002508C5
:1010E000AD000430B1008A1166268A150D30BA00B1
:1010F0008A1137208A150A30BA008A1137208A15DA
:101100001A3003178D0000308F00031006300313D0
:10111000AD008A11D5258A15093084002408B00055
:101120002308AF002208AE002108AD000430B10052
:101130008A1166268A15203003178D0000308F0033
:10114000031006300313AD008A11D5258A1524300B
:1011500003178D0000308F0007300313AD008A1194
:10116000C0278A15093084002C08B0002B08AF0076
:101170002A08AE002908AD000430B1008A116626A5
:101180008A15313003178D0000308F0005300313AE
:10119000AD008A11C0278A150430AD00FA30AE00C8
:0E11A0008A1146218A15AD0BCE282228630045
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=152C CREATED="14-V-13 19:38"
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.pjt
0,0 → 1,26
[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=
[Target Data]
OptionString=-p +FM
FileList=Z:\home\kaklik\svnMLAB\Modules\Sensors\ALTIMET01A\SW\MPL3115\PIC16F887\main.c
[Units]
Count=1
1=main (main)
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.err
0,0 → 1,2
Memory usage: ROM=27% RAM=5% - 15%
0 Errors, 0 Warnings.
/Modules/Sensors/ALTIMET01A/SW/MPL3115/PIC16F887/main.h
0,0 → 1,19
#include <16F887.h>
#device adc=8
 
#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)