{"id":786,"date":"2017-10-18T19:03:22","date_gmt":"2017-10-18T19:03:22","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=786"},"modified":"2022-02-18T15:37:48","modified_gmt":"2022-02-18T15:37:48","slug":"us-delay","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic18\/xc8-compiler\/timers-and-delays-xc8-compiler\/us-delay","title":{"rendered":"uS Delay"},"content":{"rendered":"<p>\nThis works really well in XC8\n<\/p>\n<pre>\r\n<code>\r\n\/\/*******************************\r\n\/\/*******************************\r\n\/\/********** DELAY #uS **********\r\n\/\/*******************************\r\n\/\/*******************************\r\nvoid ds18b20_delay_us(volatile unsigned char us_count)\t\t\/\/input value will be in W. &quot;Volatile&quot; attribute prevents an &quot;unused&quot; warning.\r\n{\r\n#asm\r\ntemp_ds18b20_dlyloop:\r\n\taddlw   0xFF\t\t\t\t\t;1 clk  0xff=-1, 0xfe=-2, etc\t\t\t\/\/&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;SET AS NEEDED\r\n\tbtfsc   STATUS,0\t\t\t\t;1 clk   will be clear if W was smaller than 1,2,etc\r\n\tgoto    temp_ds18b20_dlyloop\t;2 clks\r\n#endasm\r\n}\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This works really well in XC8 \/\/******************************* \/\/******************************* \/\/********** DELAY #uS ********** \/\/******************************* \/\/******************************* void ds18b20_delay_us(volatile unsigned char us_count) \/\/input value will be in W. &quot;Volatile&quot; attribute prevents an &quot;unused&quot; warning. { #asm temp_ds18b20_dlyloop: addlw 0xFF ;1 clk 0xff=-1, 0xfe=-2, etc \/\/&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;SET AS NEEDED btfsc STATUS,0 ;1 clk will be clear if W was smaller [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-786","post","type-post","status-publish","format-standard","hentry","category-timers-and-delays-xc8-compiler"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/comments?post=786"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/786\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}