float readTemperature(bit mode) { byte tempH, tempL; float returnData; initDS18B20(); writeOneByte( 0xCC ); // 跳过读序号列号的操作 writeOneByte( 0x44 ); // 启动温度转换 if( mode ) { delayMS(800); //12位分辨率,需要750ms测温 } initDS18B20(); writeOneByte( 0xCC ); //跳过读序号列号的操作 writeOneByte( 0xBE ); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度 tempL = readOneByte(); //低位 tempH = readOneByte(); //高位 if( tempH & 0x80 ) returnData=(~( tempH * 256 + tempL) + 1) * (-0.0625); //零度以下, 温度转换,把高位低位做相应的运算转换为实际的温度 else returnData=( tempH * 256 + tempL ) * 0.0625; //零度以上 return( returnData ); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // CompressedFilter::WriteToFile(): // Writes the compressed filter to the specified open file. // errorT CompressedFilter::WriteToFile (FILE * fp) { ASSERT (fp != NULL); writeFourBytes (fp, CFilterSize); writeFourBytes (fp, CFilterCount); writeFourBytes (fp, CompressedLength); byte * pb = CompressedData; for (uint i=0; i < CompressedLength; i++, pb++) { writeOneByte (fp, *pb); } return OK; }
uint8_t TwoWire::endTransmission(void) { if (tx_buf_overflow) return EDATA; // Serial.begin(9600); i2c_start(port); i2c_shift_out(port, (tx_addr << 1) | I2C_WRITE); if (!i2c_get_ack(port)) return ENACKADDR; // shift out the address we're transmitting to for (uint8_t i = 0; i < tx_buf_idx; i++) { uint8_t ret = writeOneByte(tx_buf[i]); if (ret) return ret; // SUCCESS is 0 } i2c_stop(port); tx_buf_idx = 0; tx_buf_overflow = false; return SUCCESS; }
errorT TreeCache::WriteFile (const char * fname) { #ifdef WINCE /*FILE **/Tcl_Channel fp; fileNameT fullname; strCopy (fullname, fname); strAppend (fullname, TREEFILE_SUFFIX); // fp = fopen (fullname, "wb"); fp = my_Tcl_OpenFileChannel(NULL, fullname, "w", 0666); if (fp == NULL) { return ERROR_FileOpen; } my_Tcl_SetChannelOption(NULL, fp, "-encoding", "binary"); my_Tcl_SetChannelOption(NULL, fp, "-translation", "binary"); #else FILE * fp; fileNameT fullname; strCopy (fullname, fname); strAppend (fullname, TREEFILE_SUFFIX); fp = fopen (fullname, "wb"); if (fp == NULL) { return ERROR_FileOpen; } #endif writeFourBytes (fp, TREEFILE_MAGIC); writeTwoBytes (fp, SCID_VERSION); writeFourBytes (fp, CacheSize); writeFourBytes (fp, NumInUse); writeFourBytes (fp, LowestTotal); writeFourBytes (fp, LowestTotalIndex); for (uint count = 0; count < NumInUse; count++) { // Write this cached position: cachedTreeT * ctree = &(Cache[count]); writeOneByte (fp, ctree->toMove); for (squareT sq=0; sq < 64; sq++) { writeOneByte (fp, ctree->board[sq]); } // Write the moves: writeFourBytes (fp, ctree->tree.moveCount); writeFourBytes (fp, ctree->tree.totalCount); uint numMoves = ctree->tree.moveCount; for (uint i=0; i < numMoves; i++) { // Write this move node: treeNodeT * tnode = &(ctree->tree.node[i]); writeSimpleMove (fp, &(tnode->sm)); writeString (fp, tnode->san, 8); for (uint res = 0; res < 4; res++) { writeFourBytes (fp, tnode->freq[res]); } writeFourBytes (fp, tnode->total); writeFourBytes (fp, tnode->score); writeTwoBytes (fp, tnode->ecoCode); writeFourBytes (fp, tnode->eloCount); writeFourBytes (fp, tnode->eloSum); writeFourBytes (fp, tnode->perfCount); writeFourBytes (fp, tnode->perfSum); writeFourBytes (fp, tnode->yearCount); writeFourBytes (fp, tnode->yearSum); } // Write the compressed filter: ctree->cfilter->WriteToFile (fp); } #ifdef WINCE my_Tcl_Close(NULL, fp); #else fclose (fp); #endif return OK; }
void WriteCursor2ReadQueue::writeFillWriteByte(ByteType Byte) { if (isIndexAtEndOfPage()) writeFillBuffer(1); updateGuaranteedBeforeEob(); writeOneByte(Byte); }