mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add itoa function
This commit is contained in:
@@ -88,6 +88,7 @@ void print_string(__code char *p);
|
|||||||
void print_long(__xdata uint32_t a);
|
void print_long(__xdata uint32_t a);
|
||||||
void print_short(uint16_t a);
|
void print_short(uint16_t a);
|
||||||
void print_byte(uint8_t a);
|
void print_byte(uint8_t a);
|
||||||
|
void itoa(uint8_t v);
|
||||||
void print_sfr_data(void);
|
void print_sfr_data(void);
|
||||||
void print_phy_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);
|
void phy_write_mask(uint16_t phy_mask, uint8_t dev_id, uint16_t reg, uint16_t v);
|
||||||
|
|||||||
@@ -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)
|
void print_string(__code char *p)
|
||||||
{
|
{
|
||||||
while (*p)
|
while (*p)
|
||||||
|
|||||||
Reference in New Issue
Block a user