для датчика температуры и влажности кодирование имеет ошибки

Это мой код ниже. Я пытался выявить ошибки. Например: они попросили меня поставить двоеточие в строке, и хотя я это сделал, произошла та же ошибка. Это мои коды, я знаю, что это немного трудно идентифицировать ошибки, но если кто-то понимает это, пожалуйста, дайте мне знать, я был бы очень признателен. Я делаю это для проекта, и я никогда не использовал эти коды раньше.

#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

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector