1
\$\begingroup\$

Is there _delay_ms() active waiting function in SDCC for STM8 MCU?

(I only found delay100tcy() for pic16 in includes) If it doesn't exist, what is the simplest implementation? FCPU macro is known.

\$\endgroup\$
2
\$\begingroup\$

Adapted from here:

#define T_COUNT(x) (( F_CPU * x / 1000000UL )-5)/5)

static inline void _delay_cycl( unsigned short __ticks )
{
    __asm__("nop\n nop\n"); 
    do {    
      __ticks--;
    } while ( __ticks );
    __asm__("nop\n");

static inline void _delay_us( const unsigned short __us )
{
    _delay_cycl( (unsigned short)( T_COUNT(__us) );
}

static inline void _delay_ms( unsigned short __ms )
{
    while ( __ms-- )
    {
        _delay_us( 1000 );
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.