1. byte roms_onewire[1][3] =
  2. {
  3. {0x08, 0xC3, 0xC5},
  4. //{0xC5, 0xC3, 0x08},
  5. };
  6. void FirstDoorSwitchOneHandler(bool apply)
  7. {
  8. SetPIOStatus(0, 1, apply);
  9. }
  10. void FirstDoorSwitchTwoHandler(bool apply)
  11. {
  12. SetPIOStatus(0, 2, apply);
  13. }
  14. void SetPIOStatus(byte device, byte pin, bool apply)
  15. {
  16. if (selected_device_1wire == device)
  17. SendCommand(device, COMMAND_1WIRE_RESUME);
  18. SendCommand(device, COMMAND_1WIRE_PIO_WRITE);
  19. if (apply)
  20. {
  21. SendCommand(device, pin);
  22. SendCommand(device, ~pin);
  23. }
  24. else
  25. {
  26. SendCommand(device, 0x00);
  27. SendCommand(device, 0xFF);
  28. }
  29. }
  30. void SendCommand(byte device, byte command)
  31. {
  32. byte i;
  33. if (selected_device_1wire != device)
  34. {
  35. w1_init();
  36. w1_write(COMMAND_1WIRE_MATCH_ROM);
  37. w1_write(0x3A);
  38. w1_write(roms_onewire[device][0]);
  39. w1_write(roms_onewire[device][1]);
  40. w1_write(0x01);
  41. for (i = 0; i < 3; ++i)
  42. w1_write(0x00);
  43. w1_write(roms_onewire[device][2]);
  44. }
  45. selected_device_1wire = device;
  46. w1_write(command);
  47. }