// read temperature uint8_t TSIC::getTemperature(uint16_t *temp_value16){ uint16_t temp_value1 = 0; uint16_t temp_value2 = 0; if(m_vcc_pin!=NO_VCC_PIN) TSIC_ON(); delayMicroseconds(50); // wait for stabilization if(TSIC::readSens(&temp_value1)){} // get 1st byte else TSIC_EXIT(); if(TSIC::readSens(&temp_value2)){} // get 2nd byte else TSIC_EXIT(); if(checkParity(&temp_value1)){} // parity-check 1st byte else TSIC_EXIT(); if(checkParity(&temp_value2)){} // parity-check 2nd byte else TSIC_EXIT(); if(m_vcc_pin!=NO_VCC_PIN) TSIC_OFF(); // turn off sensor *temp_value16 = (temp_value1 << 8) + temp_value2; return 1; }
void updateStatusOfSensor(Sensor sensor) { UINT8 byte3; UINT8 i; SensorStatus res; if(!isSensorReadReady) { prepareForSensorRead(); } res.sensor = sensor; CLOCK_PORT = 1; SPI_TIME_OFFSET readTime = ReadTimer1(); selectSensor(sensor); // Waiting 500 ns for sensor to be ready (Period = 83 ns => about 7 cycles, waiting 20) SPI_TIME_OFFSET res.position = 0; for(i=0 ; i<13 ; i++) { res.position <<= 1; CLOCK_PORT = 1; SPI_TIME_OFFSET_UP CLOCK_PORT = 0; SPI_TIME_OFFSET res.position += DATA_IN; } byte3 = 0; for(i=0 ; i<6 ; i++) { byte3 <<= 1; CLOCK_PORT = 1; SPI_TIME_OFFSET_UP CLOCK_PORT = 0; SPI_TIME_OFFSET byte3 += DATA_IN; } SPI_TIME_OFFSET LATA |= 0x3F; // Return to waiting state SPI_TIME_OFFSET CLOCK_PORT = 1; res.error = 0; if(OCF) { res.error += SENSOR_ERROR_OCF_NOT_FINISHED; } if(COF) { res.error += SENSOR_ERROR_OVERFLOW; } if(LIN) { res.error += SENSOR_ERROR_LINEARITY; } if(MAGDEC) { res.error += SENSOR_ERROR_MAG_DEC; } if(MAGINC) { res.error += SENSOR_ERROR_MAG_INC; } if(!checkParity(res.position,byte3)) { res.error += SENSOR_ERROR_PARITY; } if(res.error == 0 || res.error == 48) { updateSensorStatus(res,sensor); } }
int main() { unsigned int X = 8; unsigned char n=2; char Exercise; char testing = 'Y'; while (testing == 'Y' || testing == 'y') { printf("Please choose one of the optional scenarios: \n"); printf("\t* 1 * - setBit\n"); printf("\t* 2 * - clearBit\n"); printf("\t* 3 * - isPowerOfTwo\n"); printf("\t* 4 * - checkOneBitSet\n"); printf("\t* 5 * - checkParity\n"); Exercise = getchar(); printf("\nOld value : %x\n", X); showbits(X); switch (Exercise) { case '1': //Ex 2B1: while (getchar() != '\n'); printf("\nposition n=%d : \n", n); printf("\nEx 2B1 - setBit\n"); setBit(X, n); break; case '2'://Ex 2B2: while (getchar() != '\n'); printf("\nposition n=%d : \n", n); printf("\nEx 2B2 - clearBit\n"); clearBit(X, n); break; case '3'://Ex 2B3: while (getchar() != '\n'); printf("\nEx 2B3 - isPowerOfTwo\n"); printf("\n(isPowerOfTwo)\nX = %x\nis PowerOf Two?\nYES->(1);\nNO ->(0);\nRESULT: %d\n", X, isPowerOfTwo(X)); break; case '4'://Ex 2B4: while (getchar() != '\n'); printf("Ex 2B4 - checkOneBitSet\n"); //isn't this the same function as power of 2?. printf("\n(checkOneBitSet)\nX = %x\nYES->(1);\nNO ->(0);\nRESULT: %d\n", X, isPowerOfTwo(X)); break; case '5'://Ex 2B5: while (getchar() != '\n'); printf("\nEx 2B5:\ncheckParity:\n%d\n", checkParity(X)); break; } printf("Press any key to continue ... :) \n"); while (getchar() != '\n'); do { printf("Do you want to continue: 'Y' or 'y' and 'N' or 'n':\t"); testing = getchar(); while (getchar() != '\n'); } while ((testing != 'Y') && (testing != 'N') && (testing != 'y') && (testing != 'n')); //testing = 'N'; } //getchar(); //Ex 2B6: printf("\nEx 2B6 swap\n"); int a = 5, b = 3; printf("\nOld: a = %d, b = %d\n", a, b); //bynary a = a^b; b = b^a; a = a^b; printf("\nNew(Binary ^) :\n a = %d, b = %d\n", a, b); //decimal a = 5; b = 3; a = a + b; b = a - b; a = a - b; printf("\nNew(Decimal '+', '-') A shiukd be max INT / 2 or it'll lose data from overflow :\n a = %d, b = %d\n", a, b); getchar(); return 0; }
boolean MSFTime::checkValid() { boolean result = true; if( getBit( mABits, 52 )) { #ifdef EXTRA_DEBUG Serial.println("bit 52A not 0!"); #endif result = false; } if( ! getBit( mABits, 53 )) { #ifdef EXTRA_DEBUG Serial.println("bit 53A not 1!"); #endif result = false; } if( ! getBit( mABits, 54 )) { #ifdef EXTRA_DEBUG Serial.println("bit 54A not 1!"); #endif result = false; } if( ! getBit( mABits, 55 )) { #ifdef EXTRA_DEBUG Serial.println("bit 55A not 1!"); #endif result = false; } if( ! getBit( mABits, 56 )) { #ifdef EXTRA_DEBUG Serial.println("bit 56A not 1!"); #endif result = false; } if( ! getBit( mABits, 57 )) { #ifdef EXTRA_DEBUG Serial.println("bit 57A not 1!"); #endif result = false; } if( ! getBit( mABits, 58 )) { #ifdef EXTRA_DEBUG Serial.println("bit 58A not 1!"); #endif result = false; } if( getBit( mABits, 59 )) { #ifdef EXTRA_DEBUG Serial.println("bit 59A not 0!"); #endif result = false; } if( ! checkParity( mABits, 17, 24, getBit( mBBits, 54 ))) result = false; if( ! checkParity( mABits, 25,35, getBit( mBBits, 55 ))) result = false; if( ! checkParity( mABits, 36,38, getBit( mBBits, 56 ))) result = false; if( ! checkParity( mABits, 39, 51, getBit( mBBits, 57 ))) result = false; return result; }