![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
kjlj
main.cpp@0:b2168af3001f, 2019-12-17 (annotated)
- Committer:
- formulas
- Date:
- Tue Dec 17 18:15:44 2019 +0000
- Revision:
- 0:b2168af3001f
irthermo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
formulas | 0:b2168af3001f | 1 | #include "mbed.h" |
formulas | 0:b2168af3001f | 2 | |
formulas | 0:b2168af3001f | 3 | #define IrThermo_Addr (0x5A<<1) |
formulas | 0:b2168af3001f | 4 | #define Tamb 0x06 |
formulas | 0:b2168af3001f | 5 | #define Tobj 0x07 |
formulas | 0:b2168af3001f | 6 | I2C i2c(D14, D15); |
formulas | 0:b2168af3001f | 7 | Serial pc(USBTX, USBRX); |
formulas | 0:b2168af3001f | 8 | |
formulas | 0:b2168af3001f | 9 | int temperature=0; |
formulas | 0:b2168af3001f | 10 | char data_read[2]; |
formulas | 0:b2168af3001f | 11 | char data_write[1]= {Tobj}; |
formulas | 0:b2168af3001f | 12 | char data_write1[1]={Tamb}; |
formulas | 0:b2168af3001f | 13 | char data_add[1]= {(0x2E)}; |
formulas | 0:b2168af3001f | 14 | |
formulas | 0:b2168af3001f | 15 | char counter = 0; |
formulas | 0:b2168af3001f | 16 | uint32_t cc=0; |
formulas | 0:b2168af3001f | 17 | uint32_t cc1=0; |
formulas | 0:b2168af3001f | 18 | int main() { |
formulas | 0:b2168af3001f | 19 | //i2c.start(); |
formulas | 0:b2168af3001f | 20 | while(1) { |
formulas | 0:b2168af3001f | 21 | i2c.write(IrThermo_Addr, data_write, 1, 1); |
formulas | 0:b2168af3001f | 22 | i2c.read(IrThermo_Addr, data_read, 2, 0); |
formulas | 0:b2168af3001f | 23 | temperature = (int) ((int)data_read[1] << 8) | data_read[0]; |
formulas | 0:b2168af3001f | 24 | temperature = (temperature * 0.02 - 273.15); |
formulas | 0:b2168af3001f | 25 | pc.printf("Tobj=%d, ",temperature); |
formulas | 0:b2168af3001f | 26 | |
formulas | 0:b2168af3001f | 27 | i2c.write(IrThermo_Addr,data_write1 , 1, 1); |
formulas | 0:b2168af3001f | 28 | i2c.read(IrThermo_Addr, data_read, 2, 0); |
formulas | 0:b2168af3001f | 29 | temperature = (int) ((int)data_read[1] << 8) | data_read[0]; |
formulas | 0:b2168af3001f | 30 | temperature = (temperature * 0.02 - 273.15); |
formulas | 0:b2168af3001f | 31 | pc.printf("Tamb=%d\n",temperature); |
formulas | 0:b2168af3001f | 32 | |
formulas | 0:b2168af3001f | 33 | } |
formulas | 0:b2168af3001f | 34 | } |
formulas | 0:b2168af3001f | 35 |