Work shop

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
AkiraK
Date:
Wed May 29 08:02:17 2013 +0000
Commit message:
Hidaka High School;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r eac725262a54 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 29 08:02:17 2013 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#define c2f(h, l, n, e) float(short(h << 8| 1)) / (1 << 16 - n + e)
+
+int main() {
+    I2C i2c(p28, p27);
+    char id = 0x60 << 1, data[16];
+    
+    data[0] = 0x12, data[1] = 0x01;
+    i2c.write(id, data, 2);
+    wait_ms(1);
+    
+    data[0] = 0;
+    i2c.write(id, data, 1, true);
+    i2c.read(id, data, 16);
+    float padc = data[0] << 2 | data[1] >> 6;
+    float tadc = data[2] << 2 | data[3] >> 6;
+    float a0 = c2f(data[4], data[5], 16, 3);
+    float b1 = c2f(data[6], data[7], 16, 13);
+    float b2 = c2f(data[8], data[9], 16, 14);
+    float c12 = c2f(data[10], data[11], 14, 22);
+    float c11 = c2f(data[12], data[13], 11, 21);
+    float c22 = c2f(data[14], data[15], 11, 25);
+    float pcomp = a0 + (b1 + c11 * padc + c12 * tadc) * padc + (b2 + c22 * tadc) * tadc;
+    
+    printf("pressure = %4.0f hpa\n", pcomp * 650 / 1023 + 500);    
+}
diff -r 000000000000 -r eac725262a54 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 29 08:02:17 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file