{"id":284870,"date":"2017-04-12T16:45:04","date_gmt":"2017-04-12T12:45:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284870"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284870","title":{"rendered":"(\u041d\u0435) \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u044f\u043c protothreads \u043f\u043e\u0441\u0432\u044f\u0449\u0430\u0435\u0442\u0441\u044f: \u0412\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 1-Wire"},"content":{"rendered":"<p>\u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0448\u0438\u0432\u043a\u0443 \u043f\u043e\u0434 \u00ab\u0433\u043e\u043b\u043e\u0435 \u0436\u0435\u043b\u0435\u0437\u043e\u00bb. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 protothreads \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442, \u0442.\u043a. \u043c\u0443\u043b\u044c\u0442\u0438\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u041e\u0421. \u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u041d\u0443 \u0438, \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 RAM \u0438 \u044d\u043d\u0435\u0440\u0433\u043e\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u043d\u0430 \u0448\u0438\u043d\u0435 1-Wire. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0434\u043b\u044f \u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043c\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 <a href=\"#stm\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"#avr\">\u0437\u0434\u0435\u0441\u044c<\/a>.<br \/>  \u0414\u043b\u044f PnP-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0433\u043b\u0430 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0448\u0438\u043d\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u043c\u0435\u043d\u0430, \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u043e \u0438\u0445 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u0438\u044e.<br \/>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u043c\u0435\u043d\u0430 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u043c\u0435\u043d \u00ab\u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u044f\u0442\u00bb \u0438 \u043c\u0435\u0448\u0430\u0442\u044c \u043d\u0430\u043c \u043d\u0435 \u0431\u0443\u0434\u0443\u0442.<br \/>  \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u043e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u0438\u044e \u043d\u0430\u0434\u043e \u0437\u043d\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438) \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0430\u0447\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 (\u0438\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f EEPROM) \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c active pullup. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 parasite power \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 (\u043d\u0443 \u043b\u0438\u0431\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0438\u0437\u043a\u043e\u043e\u043c\u043d\u044b\u0435 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u044b, \u0447\u0442\u043e, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c).<br \/>  \u041d\u0443 \u0430 \u0443\u0436 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u043d\u0430\u043c \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e. \u0418\u043d\u0430\u0447\u0435 \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0438\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f?<\/p>\n<p>  <a name=\"probe\"><\/a>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u0448\u0438\u043d\u044b:  <\/p>\n<ol>\n<li>\u041f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 RESET \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 OVERDRIVE. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0431\u044b\u043b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d PRESENCE, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0443\u043c\u0435\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043f.3.<\/li>\n<li>\u041f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 RESET \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0431\u044b\u043b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d PRESENCE, \u0442\u043e \u043d\u0430 \u0448\u0438\u043d\u0435 1-Wire \u0438\u043c\u0435\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u0434\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043f.3. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u043a \u0448\u0438\u043d\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435\u0442.<\/li>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0430 \u0448\u0438\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u00ab\u0410\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u00bb \u0438 \u0437\u0430\u0442\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u00ab\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u0438\u044f\u00bb. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0435\u0436\u0438\u043c parasite power,<br \/>   \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u043b\u0430\u0433.<\/li>\n<\/ol>\n<p>  \u0410 \u0432\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0439. \u0415\u0433\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0432 <a href=\"#apn_187\">APPLICATION NOTE 187<\/a>, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u043b \u0435\u0435 \u0432 \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u0443\u044e.<\/p>\n<p>  \u041d\u0430 \u0432\u0441\u0435\u0445 \u044d\u0442\u0430\u043f\u0430\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0438\u0437-\u0437\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043c\u0435\u0445 \u043d\u0430 \u0448\u0438\u043d\u0435 1-Wire. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043b\u0438\u0431\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0443 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0435\u0441\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u043e <a href=\"#dunkels\">protothreads<\/a>. \u041a\u043e\u043c\u0443 \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u044b, \u043c\u043e\u0436\u0435\u0442, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"#continuation\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"#multitask\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u041f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0438\u043d\u044b \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>    PT_INIT(&ptSearchContext.pt);          \/* \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043e\u0431\u043c\u0435\u043d\u0430 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043f\u0438\u0442\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 *\/     while(PT_SCHEDULE(c = ptOneWireProbeBus(&ptSearchContext.pt, &nested))) {         if(PT_WAITING == c) {             \/* \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0447\u0435\u043c-\u043b\u0438\u0431\u043e \u0435\u0449\u0435 *\/             waitComplete();                          continue;         }     }          \/* \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0432\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c *\/     ptOneWireInitWalkROM(&ptSearchContext);          \/* \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u043a 1-Wire \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 *\/     while(PT_SCHEDULE(c = ptOneWireWalkROM(&ptSearchContext))) {         if(PT_WAITING == c) {             \/* \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0447\u0435\u043c-\u043b\u0438\u0431\u043e \u0435\u0449\u0435 *\/             waitComplete();                          continue;         }                  \/* \u041d\u0430 \u0448\u0438\u043d\u0435 1-Wire \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e.          * \u0415\u0433\u043e S\/N \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 ptSearchContext.romid          *\/         __no_operation();     }          \/* \u0412\u0441\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u044b *\/     __no_operation(); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 waitComplete() \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 protothreads (\u0430 \u0435\u0441\u043b\u0438 \u0438\u0445 \u043d\u0435\u0442, \u0442\u043e \u0432\u043e\u0439\u0442\u0438 \u0432 \u0440\u0435\u0436\u0438\u043c \u043f\u043e\u043d\u0438\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u043d\u0435\u0440\u0433\u043e\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f).<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0430\u043a\u0440\u043e\u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#define OVERDRIVE()                                                     \\     drv_onewire_context.overdrive          #define PRESENCE_DETECTED()                                             \\     drv_onewire_context.presence  #define PARASITE_POWER                                                  \\     drv_onewire_context.parasite          #define STATUS                                                          \\     drv_onewire_context.status          #define PT_WAIT_IO_COMPLETE()                                           \\     PT_WAIT_WHILE(TASK_CONTEXT, ONEWIRE_STATUS_PROGRESS == (dummy = drvOneWireStatus()))  #define IO_SUCCESS()                                                    \\     (ONEWIRE_STATUS_COMPLETE == dummy)  #define PT_TX_BITS(_v,_n) do {                                          \\     if(drvOneWireTxBits((_v),(_n))) {                                   \\         PT_WAIT_IO_COMPLETE(); } else {                                 \\         dummy = ONEWIRE_STATUS_ERROR; } } while(0)          #define PT_TX_BYTE(_v)                                                  \\     PT_TX_BITS((_v), 8)          #define PT_RX_BITS(_n)                                                  \\     PT_TX_BITS(~0,(_n))          #define PT_TX_BYTE_CONST(_v) do {                                       \\     PT_TX_BYTE((_v));                                                   \\     if(!IO_SUCCESS() || ((_v) != drvOneWireRxBits(8))) {                \\         STATUS = ONEWIRE_STATUS_ERROR; } } while(0) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<br \/>  PT_WAIT_IO_COMPLETE()<br \/>  \u041e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 protothread.<\/p>\n<p>  PT_TX_BITS(_v,_n)<br \/>  \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 _n \u0431\u0438\u0442 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f _v \u043d\u0430 \u0448\u0438\u043d\u0443 \u0441 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 protothread.<\/p>\n<p>  PT_TX_BYTE(_v)<br \/>  \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0431\u0430\u0439\u0442\u0430 _v \u043d\u0430 \u0448\u0438\u043d\u0443 \u0441 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 protothread.<\/p>\n<p>  PT_RX_BITS(_n) <br \/>  \u041f\u0440\u0438\u0435\u043c _n \u0431\u0438\u0442 \u0441 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 protothread.<\/p>\n<p>  PT_TX_BYTE_CONST(_v)<br \/>  \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0431\u0430\u0439\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u043a\u043e\u043d\u0441\u0442\u0430\u0442\u043d\u044b) \u043d\u0430 \u0448\u0438\u043d\u0443 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 protothread.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u00ab\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0432\u043e\u0434\u0430 \u0432\u044b\u0432\u043e\u0434\u0430\u00bb \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043d\u0435 \u0433\u043b\u0443\u0445\u043e\u0439 \u0446\u0438\u043a\u043b \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0430 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 protothread \u0441\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c PT_WAITING. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 protothreads \u0441 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>PT_THREAD(ptOneWireTargetAll(struct pt * _pt)) {     uint8_t dummy;          PT_BEGIN(TASK_CONTEXT);      PT_TX_BYTE_CONST(OP_SKIP_ROM);          PT_END(TASK_CONTEXT); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0448\u0438\u043d\u044b 1-Wire, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 protothreads.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0438\u043d\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>PT_THREAD(ptOneWireProbeBus(struct pt * _pt, struct pt * _nested)) {     uint8_t dummy;          PT_BEGIN(TASK_CONTEXT);          \/* Parasite power not detected *\/     PARASITE_POWER = 0;          \/* Try overdrive procedure first *\/     if(drvOneWireReset(1)) {         PT_WAIT_IO_COMPLETE();                  if(!IO_SUCCESS() || !PRESENCE_DETECTED()) {             \/* Overdrive RESET procedure failed *\/             if(drvOneWireReset(0)) {                 PT_WAIT_IO_COMPLETE();                          if(!IO_SUCCESS() || !PRESENCE_DETECTED()) {                     \/* No devices on the bus *\/                     PT_EXIT(TASK_CONTEXT);                 }             } else {                 \/* Hardware BUSY *\/                 PT_EXIT(TASK_CONTEXT);             }         }     } else {         \/* Hardware BUSY *\/         PT_EXIT(TASK_CONTEXT);     }          PT_SPAWN(TASK_CONTEXT, _nested, ptOneWireTargetAll(_nested));      if(ONEWIRE_STATUS_COMPLETE == STATUS) {         PT_TX_BYTE_CONST(OP_READ_POWER_SUPPLY);          if(IO_SUCCESS()) {             \/* Read one bit after command *\/             PT_RX_BITS(1);                  if(IO_SUCCESS()) {                 \/* Fetch bit value *\/                 int16_t value = drvOneWireRxBits(1);                              if(value &lt; 0) {                     \/* Rx bit decode failed *\/                     STATUS = ONEWIRE_STATUS_ERROR;                 } else {                     \/* If any device sent &quot;0&quot; then it used parasite power *\/                     PARASITE_POWER = value ? 0 : 1;                 }             }         }     }          PT_END(TASK_CONTEXT); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u043e\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 <a href=\"#probe\">\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/a>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>PT_THREAD(ptOneWireWalkROM(pt_onewire_search_context_t * _ctx)) {     PT_BEGIN(TASK_CONTEXT);          while(!LAST_DEVICE_FLAG) {         int16_t dummy;                  \/* initialize for search *\/         ID_BIT_NUMBER = 1;         LAST_ZERO = 0;         ROM_BYTE_NUMBER = 0;         ROM_BYTE_MASK = 1;                  \/* 1-Wire reset (dependent on OVERDRIVE flag) *\/         PT_ONEWIRE_RESET();                  if(!IO_SUCCESS() || !PRESENCE_DETECTED()) {             \/\/ reset the search             LAST_DISCREPANCY = 0;             LAST_DEVICE_FLAG = 0;             LAST_FAMILY_DISCREPANCY = 0;              \/* If presence not detected then no devices on the bus *\/             PT_EXIT(TASK_CONTEXT);         }          \/* issue the search command *\/         PT_TX_BYTE(OP_SEARCH_ROM);                  if(!IO_SUCCESS() || (OP_SEARCH_ROM != drvOneWireRxBits(8))) {             \/* Send command error, repeat procedure from RESET point *\/                          \/* Other solution is abort search procedure *\/                          continue;         }                  \/\/ loop to do the search         do {             \/\/ read a bit and its complement             PT_RX_BITS(2);                          if(!IO_SUCCESS()) {                 \/* Error while receiving 2 bits.                  * As ID_BIT_NUMBER less than 65 search procedure                  * resumed from state such as original task entry.                  *\/                 break;             }              if((RX_VALUE = drvOneWireRxBits(2)) &lt; 0) {                 __no_operation();                                  break;             }                          uint8_t id_bit = (RX_VALUE & 0x01) ? 1 : 0;             uint8_t cmp_id_bit = (RX_VALUE & 0x02) ? 1 : 0;              uint8_t search_direction;                          \/* check for no devices on 1-wire *\/             if ((id_bit == 1) && (cmp_id_bit == 1)) {                 \/* Same bit values equ &quot;1&quot; indicate no devices on the bus *\/                 break;             } else {                 \/* all devices coupled have 0 or 1 *\/                 if (id_bit != cmp_id_bit) {                     search_direction = id_bit;  \/* bit write value for search *\/                 } else {                     \/* if this discrepancy if before the LAST_DISCREPANCY                      on a previous next then pick the same as last time *\/                     if (ID_BIT_NUMBER &lt; LAST_DISCREPANCY) {                         search_direction = (ROMID_BYTE_REF(ROM_BYTE_NUMBER) & ROM_BYTE_MASK) ? 1 : 0;                     } else {                         \/* if equal to last pick 1, if not then pick 0 *\/                         search_direction = (ID_BIT_NUMBER == LAST_DISCREPANCY) ? 1 : 0;                     }                      \/* if 0 was picked then record its position in LAST_ZERO *\/                     if (search_direction == 0) {                         LAST_ZERO = ID_BIT_NUMBER;                     }                      \/* check for LAST_FAMILY_DISCREPANCY in family *\/                     if (LAST_ZERO &lt; 9) {                         LAST_FAMILY_DISCREPANCY = LAST_ZERO;                     }                                      }             }              \/* set or clear the bit in the ROM byte ROM_BYTE_NUMBER                with mask rom_byte_mask *\/             if (search_direction == 1) {                 ROMID_BYTE_REF(ROM_BYTE_NUMBER) |= ROM_BYTE_MASK;             } else {                 ROMID_BYTE_REF(ROM_BYTE_NUMBER) &= ~ROM_BYTE_MASK;             }              \/* serial number search direction write bit *\/             PT_TX_BITS(search_direction, 1);                          \/* search_direction not stored, therefore we can't check echo *\/              if(!IO_SUCCESS()) {                 \/* Sending direction failed.                  * As ID_BIT_NUMBER less than 65 search procedure                  * resumed from state such as original task entry.                  *\/                 break;             }              \/* increment the byte counter ID_BIT_NUMBER                and shift the mask rom_byte_mask *\/             ID_BIT_NUMBER++;             ROM_BYTE_MASK &lt;&lt;= 1;              \/* if the mask is 0 then go to new SerialNum byte ROM_BYTE_NUMBER and reset mask *\/             if (ROM_BYTE_MASK == 0) {                 ROM_BYTE_NUMBER++;                 ROM_BYTE_MASK = 1;             }         } while(ROM_BYTE_NUMBER &lt; 8);  \/* loop until through all ROM bytes 0-7 *\/          \/* if the search was successful then *\/         if(!(ID_BIT_NUMBER &lt; 65)) {             uint8_t i;                          \/* Calculate CRC *\/             uint8_t crc = 0;             for(i = 0;i &lt; sizeof(ROMID);i++) {                 crc = modOneWireUpdateCRC(crc, ROMID_BYTE_REF(i));             }                          if(crc) {                 \/* CRC error.                  * Repeat procedure from original point                  *\/                 continue;             }                          \/* search successful so set LAST_DISCREPANCY and LAST_DEVICE_FLAG *\/             LAST_DISCREPANCY = LAST_ZERO;              \/\/ check for last device             if (LAST_DISCREPANCY == 0) {                 LAST_DEVICE_FLAG = 1;             }              \/* Next device detection complete *\/         } else {             \/* I\/O error.              * Retry procedure from original point              *\/             continue;         }                  if(!ROMID.id.familyCode) {             \/* familyCode \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d 0! *\/             break;         }                  \/* Return detected device S\/N *\/         PT_YIELD(TASK_CONTEXT);     }      \/* Reset state for next scan loop (if need) *\/     ptOneWireInitWalkROM(CONTEXT);          PT_END(TASK_CONTEXT); }  \/*  * Initialize device search procedure  *\/ void ptOneWireInitWalkROM(pt_onewire_search_context_t * _ctx) {     \/* Prepare ptOneWireWalkROM() for first call  *\/     LAST_DISCREPANCY = 0;     LAST_DEVICE_FLAG = 0;     LAST_FAMILY_DISCREPANCY = 0;      \/* Initialize protothreads data *\/     PT_INIT(TASK_CONTEXT); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0442 <a href=\"#apn_187\">Maxim<\/a> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u043c \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043c\u0430\u043a\u0440\u043e\u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412\u0441\u0435 \u044d\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0440\u043e\u0433\u043e\u043d\u043a\u043e\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0437\u0430\u043d\u044f\u043b\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0441\u0430. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0431\u0435\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0438 protothreads?<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0434\u043b\u044f STM8L-Discovery board \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d \u043d\u0430 <a href=\"#code\">github<\/a>. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u0441 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b HIGH_LEVEL.<\/p>\n<p>  \u0421\u043f\u0438\u0441\u043e\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b:<\/p>\n<ol>\n<li><a name=\"code\"><\/a><a href=\"https:\/\/github.com\/vedga\/1-wire\">\u041a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 github<\/a><\/li>\n<li><a name=\"stm\"><\/a><a href=\"https:\/\/habrahabr.ru\/post\/326114\/\">\u041f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 1-Wire master \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 PWM \u0438 ICP \u0434\u043b\u044f STM8L \u0438 STM32<\/a><\/li>\n<li><a name=\"avr\"><\/a><a href=\"https:\/\/habrahabr.ru\/post\/322710\/\">\u041f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 1-Wire master \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 PWM \u0438 ICP \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 AVR AtMega<\/a><\/li>\n<li><a name=\"dunkels\"><\/a><a href=\"http:\/\/dunkels.com\/adam\/pt\/index.html\">Protothreads from Adam Dunkels<\/a><\/li>\n<li><a name=\"continuation\"><\/a>\u0425\u0430\u0431\u0440 \u043e\u0442 <a href=\"https:\/\/habrahabr.ru\/users\/ldir\/\" class=\"user_link\">ldir<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/143318\/\">\u041c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439<\/a><\/li>\n<li><a name=\"multitask\"><\/a>\u0425\u0430\u0431\u0440 \u043e\u0442 <a href=\"https:\/\/habrahabr.ru\/users\/lifev\/\" class=\"user_link\">LifeV<\/a> <a href=\"https:\/\/habrahabr.ru\/company\/embox\/blog\/244361\/\">Protothread \u0438 \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c<\/a><\/li>\n<li><a name=\"apn_187\"><\/a><a href=\"https:\/\/www.maximintegrated.com\/en\/app-notes\/index.mvp\/id\/187\">APPLICATION NOTE 187. 1-Wire Search Algorithm<\/a><\/li>\n<\/ol>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/326320\/\"> https:\/\/habrahabr.ru\/post\/326320\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0448\u0438\u0432\u043a\u0443 \u043f\u043e\u0434 \u00ab\u0433\u043e\u043b\u043e\u0435 \u0436\u0435\u043b\u0435\u0437\u043e\u00bb. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 protothreads \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442, \u0442.\u043a. \u043c\u0443\u043b\u044c\u0442\u0438\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u041e\u0421. \u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u041d\u0443 \u0438, \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 RAM \u0438 \u044d\u043d\u0435\u0440\u0433\u043e\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284870","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284870"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284870\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}