Piszę funkcję wyświetlającą mi wszystkie numery seryjne urządzeń podłączonych pod 1 Wire. Mam problem pewnie błachy, jeżeli ktoś wie co jest nie tak niech piszę. Zaznaczam, że funkcję do wysyłania czy odbierania danych są sprawdzone i działają poprawnie. I tak do magistrali mam podłączone dwa czujniki DS18B20. Na podstawie algorytmu który jest w fazie czysto testowej próbuję odczytać numery tych dwóch czujników. W momencie krytycznym czyli tym w którym wybieram czy chcę czujnik numer 1 czy 0 (Czyli wtedy kiedy otrzymuję odebrane dwa bity o wartości 0 0) wszystko działa po zmienieniu parametru Bit odczytuję poprawnie numer czujnika. Problem następuję gdy chcę zrobić to automatycznie czyli aby od razu adresy obu czujników były wyświetlanie. Niestety nie mogę tego dokonać drugi czujnik ma błędy w swoim numerze seryjnym
Tutaj mój kod:
Kod: Zaznacz cały
while(1)
{
Search();
for(i = 1; i <= 8; i++)
{
lcd_locate(0,0);
lcd_str(" ");
lcd_locate(0,0);
lcd_int(buf[i-1]);
_delay_ms(5000);
}
_delay_ms(1000);
lcd_locate(1,0);
lcd_str("2");
}
}
void Search(void)
{
uint8_t bitA = 0, bitB = 0;
uint8_t currentBit = 0;
uint8_t Bit = 0;
Reset = One_Wire_Reset_Pulse();
One_Wire_Send_Byte(0xF0);
for(currentBit = 0; currentBit < 64; currentBit++)
{
bitA = One_Wire_Read_Bit();
bitB = One_Wire_Read_Bit();
if(bitA == 1 && bitB == 0) Bit = 2;
if(bitA == 0 && bitB == 1) Bit = 1;
//if((bitA == 0)&& (bitB == 0))Bit = 1; Kiedy tak zrobię to działa ale wyświetla jeden numer seryjny
//if((bitA == 0)&& (bitB == 0))Bit = 2; Kiedy tak zrobię to działa ale wyświetla jeden numer seryjny
if((bitA == 0)&& (bitB == 0)) -- To jest mój niby automat który powinien kontrolować i odpowiadać za wysyłanie dwóch numerów
{
Bit = 1;
if(Bit_numer == currentBit)
{
Bit = 2;
Bit_numer = 100;
}
else
{
Bit_numer = currentBit;
}
}
if((currentBit >= 0 )&&(currentBit <= 7))
{
if(Bit == 2) (buf[0] |= 0x01 << (currentBit));
}
if((currentBit >= 8 )&&(currentBit <= 15))
{
if(Bit == 2) (buf[1] |= 0x01 << (currentBit -8));
}
if((currentBit >= 16 )&&(currentBit <= 23))
{
if(Bit == 2) (buf[2] |= 0x01 << (currentBit -16));
}
if((currentBit >= 24 )&&(currentBit <= 31))
{
if(Bit == 2) (buf[3] |= 0x01 << (currentBit -24));
}
if((currentBit >= 32 )&&(currentBit <= 39))
{
if(Bit == 2) (buf[4] |= 0x01 << (currentBit -32));
}
if((currentBit >= 40 )&&(currentBit <= 47 ))
{
if(Bit == 2) (buf[5] |= 0x01 << (currentBit -40));
}
if((currentBit >= 48 )&&(currentBit <= 55 ))
{
if(Bit == 2) (buf[6] |= 0x01 << (currentBit -48));
}
if((currentBit >= 56 )&&(currentBit <= 63 ))
{
if(Bit == 2) (buf[7] |= 0x01 << (currentBit -56));
}
switch (Bit)
{
case 1:
One_Wire_Send_Bit(0);
break;
case 2:
One_Wire_Send_Bit(1);
break;
}
}
}