50 #include "dev/ds1629.h"
52 #define SDA_HIGH (P5OUT |= 0x01)
53 #define SDA_LOW (P5OUT &= 0xFE)
54 #define SCL_HIGH (P5OUT |= 0x02)
55 #define SCL_LOW (P5OUT &= 0xFD)
57 #define BUS_WRITE 0x9E
59 #define ACC_CLOCK 0xC0
60 #define ACC_CLOCK_ALARM 0xC7
63 #define ACC_CSRAM 0x17
65 #define CSR_OS1 (0x80)
66 #define CSR_OS0 (0x40)
69 #define CSR_CNV (0x04)
70 #define CSR_POL (0x02)
71 #define CSR_1SH (0x01)
72 #define CSR_DEFAULT (CSR_OS1 + CSR_OS0 + CSR_A1 + CSR_CNV + CSR_1SH + CSR_POL)
81 typedef union {
unsigned int u;
signed int s; } temp_t;
110 cl_writeOnBus(u8_t byte)
116 byte = byte << 1; _NOP();
122 if(P5IN & 0x01) ack = 0;
else ack = 1;
130 cl_readFromBus(u16_t ack)
138 if(P5IN & 0x01) byte |= 0x01;
else byte &= 0xFE;
149 getReg16bit(u8_t acc, u16_t bitmask)
153 while(!cl_writeOnBus(BUS_WRITE));
156 cl_writeOnBus(BUS_READ);
157 config = cl_readFromBus(1);
158 config = config << 8;
159 config += cl_readFromBus(0);
169 setCSReg(u8_t setting)
172 while(!cl_writeOnBus(BUS_WRITE));
173 cl_writeOnBus(ACC_CSR);
174 cl_writeOnBus(setting);
183 System_startConversion(
void)
186 while(!cl_writeOnBus(BUS_WRITE));
195 u8_t csr = getReg16bit(ACC_CSR,0xFF00) >> 8;
196 if(csr!=CSR_DEFAULT) setCSReg(CSR_DEFAULT);
200 while(!cl_writeOnBus(BUS_WRITE));
201 cl_writeOnBus(ACC_CLOCK);
216 System_startConversion();
226 temperature.u = getReg16bit(ACC_RT,0xFFFF);
227 return temperature.s;