Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * delay utilite for STM8 family
- * COSMIC and SDCC
- * Terentiev Oleg
- * t.oleg@ymail.com
- */
- #ifndef _UTIL_DELAY_H_
- #define _UTIL_DELAY_H_ 1
- #ifndef F_CPU
- #error F_CPU is not defined!
- #endif
- #define T_COUNT(x) ((((unsigned long long)F_CPU * (unsigned long long)x / 1000000UL))/7)
- /*
- * Func delayed N cycles, where N = 3 + ( ticks * 3 )
- * so, ticks = ( N - 3 ) / 3, minimum delay is 6 CLK
- * when tick = 1, because 0 equels 65535
- */
- /*(( F_CPU * x / 1000000UL )-5)/5)*/
- void inline _delay_cycl(uint16_t __ticks )
- {
- __asm__("nop\n nop\n");
- do
- {
- __ticks--;
- }
- while ( __ticks );
- __asm__("nop\n");
- }
- void inline _delay_us(uint16_t __us )
- {
- _delay_cycl( (uint16_t) T_COUNT(__us) );
- }
- void inline _delay_ms( volatile uint16_t __ms )
- {
- while ( __ms-- )
- {
- _delay_us( 1000 );
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement