Last active
March 30, 2017 09:18
-
-
Save hans00/8322e47efa5d4e989e67d43ee6ae768c to your computer and use it in GitHub Desktop.
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 characters
| // 優化效率 | |
| #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() { dd4tick; dd4tick; dd4tick; dd4tick; } | |
| #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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment