diff --git a/rtl837x_common.h b/rtl837x_common.h index 57c0e6a..daea67a 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -88,6 +88,7 @@ void print_string(__code char *p); void print_long(__xdata uint32_t a); void print_short(uint16_t a); void print_byte(uint8_t a); +void itoa(uint8_t v); void print_sfr_data(void); void print_phy_data(void); void phy_write_mask(uint16_t phy_mask, uint8_t dev_id, uint16_t reg, uint16_t v); diff --git a/rtlplayground.c b/rtlplayground.c index 8bc0730..1690b7c 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -172,6 +172,22 @@ void write_char(char c) } +void itoa(uint8_t v) +{ + uint8_t t = (v / 100); + // when print_zeros is not zero, we know that a non-zero number has printed. + // That have to print all the next numbers. + uint8_t print_zeros = t; + if (print_zeros) + write_char('0' + t); + t = (v / 10) % 10; + print_zeros |= t; + if (print_zeros) + write_char('0' + t); + write_char('0' + (v % 10)); +} + + void print_string(__code char *p) { while (*p)