void setup() { serial_t Serial; // configure ADC to take temperature samples see [2] ADC10CTL0 = 0; ADC10CTL1 = INCH_10 | ADC10DIV_3; ADC10CTL0 = SREF_1 | ADC10SHT_3 | REFON | ADC10ON | ADC10IE; Serial.begin(9600); unsigned sample; while(1) { // enable ADC sample, sleep till complete ADC10CTL0 |= (ENC |ADC10SC); __bis_SR_register(LPM3_bits | GIE); __nop(); // make debugger happy see [1] sample = ADC10MEM; //Serial << "RAW=" << sample << " "; // output F and C temps #ifdef USE_FIX16 // working variables for calculations // convert sample to C = sample*0.413 - 277.75 Fix16 c = (Fix16(int16_t(sample)) * Fix16(0.14663/0.355)) - Fix16(277.75); Serial << _FIX16(c + 0.005f, 2) << "C" << " "; // convert sample to F = C*9/5 + 32 Fix16 f = (c * Fix16(9.0/5.0)) + Fix16(32); Serial << _FIX16(f + 0.0005f, 3) << "F" << endl; #endif #ifdef USE_INTEGER_MATH int conversion; conversion = ((27069L * sample) - 18169625L) >> 16; Serial << conversion << "C "; conversion = ((48724L * sample ) - 30634388L) >> 16; Serial << conversion << "F" << endl; #endif delay(5000); } }
inline void setup() { serial Serial; Serial.begin(BAUD_RATE); Fix16 angle; // use fix16_t for calculations Serial << "Table of Sin(a)" << endl; for (angle = (int16_t)-90; angle <= (int16_t)90; angle += (int16_t)1) { fix16_t sin_value = angle.sind(); // calc sine from degrees Serial << "angle = " << _FIX16(angle, 0) << " sin = " << _FIX16(sin_value, 4) /* 5 is max with fix16_t */ << endl; } while(1); // stop here when done., press reset button to see again }