Last active
March 30, 2017 09:18
-
-
Save hans00/8322e47efa5d4e989e67d43ee6ae768c to your computer and use it in GitHub Desktop.
Revisions
-
hans00 revised this gist
Mar 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ #endif #if F_CPU == 16000000L #define dd4tick __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t") #define delayOneUs() { dd4tick; dd4tick; dd4tick; dd4tick; } #endif #define delay2Us() { delayOneUs(); delayOneUs(); } #define delay5Us() { delay2Us(); delay2Us(); delayOneUs(); } -
hans00 created this gist
Mar 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ // 優化效率 #define ddtick __asm__("nop\n\t") #if F_CPU == 20000000L #define dd5tick __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t") #define delayOneUs() { dd5tick; dd5tick; dd5tick; dd5tick; } #endif #if F_CPU == 16000000L #define dd4tick __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t") #define delayOneUs() { dd5tick; dd5tick; dd5tick; dd5tick; } #endif #define delay2Us() { delayOneUs(); delayOneUs(); } #define delay5Us() { delay2Us(); delay2Us(); delayOneUs(); } int ping() { pinMode(PING_PIN, OUTPUT); digitalWrite(PING_PIN, LOW); delay2Us(); digitalWrite(PING_PIN, HIGH); delay5Us(); digitalWrite(PING_PIN, LOW); pinMode(PING_PIN, INPUT); return pulseIn(PING_PIN, HIGH) / 29 / 2; }