这是我下面的代码。我试图找出错误。例如:他们要求我在一行上加上一个冒号,尽管我这样做了,但发生了同样的错误。这些是我的代码,我知道识别错误有点困难,但如果有人理解这一点,请告诉我,我将不胜感激。我为一个项目做这个,我以前从未使用过这个代码。
#use "1_Wire_Configure.Lib" // edit this library or make a copy of it
// to define your hardware
void main ()
{ int presence, CRC, i, j, k;
float Deg, Volts[4];
char GetROMaddress[10];
int DevNbr;
int Resolution;
OWConfigure();
i = OWInit();
i = OWReset();
if ( i != OW_ERR_SUCCESS ) // only meaningful for DS2480 interface
{
printf ( "Failed to initialize the 1-Wire Interface!\n\r" );
exit(1);
}
do // repeat loop
{
i = OWSearchROM (); // find all the devices on the bus
if ( i != OW_ERR_SUCCESS )
{
printf ( "No units or too many units found on bus!\n\r" );
exit (2);
}
OWDisplayROM(); // display them
// DS2450
j = DevNbr = 0; // init for the loop
while ( j < OW_DeviceCount ) // for each device in the table
{
if ( OW_ROMtable[j++][0] == OW_F_DS2450 ) // if DS2450
{
for ( i=0; i<=3; i++ ) // init each channel: 16 bits, 5V range
{
k = DS2450_Init (DevNbr, i, 16 , OW_OPT_RANGE_HI );
}
k = DS2450_Convert ( DevNbr, OW_CHA|OW_CHB|OW_CHC|OW_CHD,
OW_SETA|OW_SETB|OW_SETC|OW_SETD );
OWMsDelay (10); // allow time for A/D conversions
k = DS2450_ADRead ( DevNbr, Volts );
printf ( "DS2450 #%d: Volts: ", DevNbr );
for (i=0; i<=3; i++ ) printf ( "%8.3f", Volts[i] );
printf ( "\n\r" );
DevNbr++; // next DS2450
} // if DS2450
} // for each device in the table
// DS2406
j = DevNbr = 0;
while ( j < OW_DeviceCount ) // for each device in the table
{
if ( OW_ROMtable[j++][0] == OW_F_DS2406 ) // if DS2406
{
DS2406_PIO ( DevNbr, 1 ); // turn on output A
i = DS2406_Status (DevNbr); // read the status byte
printf ( "DS2406 #%d: status = 0x%02X", DevNbr, (char)i );
OWMsDelay (500);
DS2406_PIO ( DevNbr, 0 ); // turn off output A
i = DS2406_Status (DevNbr); // read the status byte
printf ( " status = 0x%02X\n\r", (char)i );
DevNbr++; // next DS2406
} // if DS2406
} // for each device in the table
// DS18S20
j = DevNbr = 0;
while ( j < OW_DeviceCount ) // for each device in the table
{
if ( OW_ROMtable[j++][0] == OW_F_DS18S20 ) // if DS18S20
{
if ( DevNbr == 0 ) // if "1st" unit
{
DS18S20_Convert ( -1 ); // initiate a reading on all units
OWMsDelay ( 750 ); // allow at least 750msec for conversion
}
i = DS18S20_Read ( DevNbr, OW_OPT_DEGF, &Deg ); // get temperature
printf ( "DS18S20 #%d: Temp = %6.2fF\n\r", DevNbr, Deg );
DevNbr++; // next DS18S20
} // if DS18S20
} // for each device in the table
// DS18B20
Resolution = OW_OPT_9_BITS;
j = DevNbr = 0;
while ( j < OW_DeviceCount ) // for each device in the table
{
if ( OW_ROMtable[j++][0] == OW_F_DS18B20 ) // if DS18B20
{
DS18B20_Convert ( DevNbr, Resolution ); // initiate a reading
DevNbr++; // next DS18B20
} // if DS18B20
} // for each device in the table
OWMsDelay ( (1<<Resolution)*100 ); // time for conversion
j = DevNbr = 0;
while ( j < OW_DeviceCount ) // for each device in the table
{
if ( OW_ROMtable[j++][0] == OW_F_DS18B20 ) // if DS18B20
{
i = DS18B20_Read ( DevNbr, OW_OPT_DEGF, &Deg ); // get the temperature
printf ( "DS18B20 #%d: Temp = %6.2fF\n\r", DevNbr, Deg );
DevNbr++; // next DS18B20
} // if DS18B20
} // for each device in the table
printf ( "\n\rPress 'r' to repeat:\n\n" );
} while ( getchar() == 'r' ); // repeat loop
}
//From the bildr article http://bildr.org/2012/11/hih4030-arduino/
int const HIH4030_Pin = A0; //analog pin 0
void setup(){
Serial.begin(9600);
}
void loop(){
//To properly caculate relative humidity, we need the temperature.
float temperature = 25; //replace with a thermometer reading if you have it
float relativeHumidity = getHumidity(temperature);
Serial.println(relativeHumidity);
}
float getHumidity(float degreesCelsius){
//caculate relative humidity
float supplyVolt = 5.0;
// read the value from the sensor:
int HIH4030_Value = analogRead(HIH4030_Pin);
float voltage = HIH4030_Value/1023. * supplyVolt; // convert to voltage value
enter code here
// convert the voltage to a relative humidity
// - the equation is derived from the HIH-4030/31 datasheet
// - it is not calibrated to your individual sensor
// Table 2 of the sheet shows the may deviate from this line
float sensorRH = 161.0 * voltage / supplyVolt - 25.8;
float trueRH = sensorRH / (1.0546 - 0.0026 * degreesCelsius); //temperature adjustment
return trueRH;
}
enter code here