Hardware Reference
In-Depth Information
PTM |
5
BIT1;
// enable TC72 data transfer
putcspi0(0x02);
// send MSB temperature read address
hi_byte
5
getcspi0();
// read the temperature high byte
lo_byte
5
getcspi0();
// save the temperature low byte and clear SPIF
PTM &
5
,
BIT1;
// disable TC72 data transfer
lo_byte &
5
0xC0;
// make sure the lower 6 bits are 0s
result
5
(int)hi_byte * 256
1
(int)lo_byte;
if (hi_byte & 0x80) {
// temperature is negative
result
5
2
result;
// take the two's complement of result
result
..5
6;
temp
5
result & 0x0003;
// place the lowest 2 bits in temp
result
..5
2;
// get rid of fractional part
*ptr
115
0x2D;
// store the minus sign
int2alpha(result, ptr);
}
else {
// temperature is positive
result
..5
6;
temp
5
result & 0x0003;
// save fractional part
result
..5
2;
// get rid of fractional part
int2alpha(result, ptr);
// convert to ASCII string
}
while(*bptr){ // search the end of the string
bptr
11
;
};
switch (temp){
// add fractional digits to the temperature
case 0:
break;
case 1:
// fractional part is 25
*bptr
115
0x2E;
// add decimal point
*bptr
115
0x32;
*bptr
115
0x35;
*bptr
5
'\0';
break;
case 2:
// fractional part is 5
*bptr
115
0x2E;
// add decimal point
*bptr
115
0x35;
*bptr
5
'\0';
break;
case 3:
// fractional part is 75
*bptr
115
0x2E;
// add decimal point
*bptr
115
0x37;
*bptr
115
0x35;
*bptr
5
'\0';
break;
default:
break;
}
}
▲
Search WWH ::
Custom Search