-
-/* print string stored in data memory(SRAM)
- * print_P("hello world");
- * This consumes precious SRAM memory space for string.
- */
-void print_S(const char *s)
-{
- uint8_t c;
- while (1) {
- c = *s++;
- if (!c) break;
- if (c == '\n') sendchar('\r');
- sendchar(c);
- }
-}
-
-/* print string stored in program memory(FLASH)
- * print_P(PSTR("hello world");
- * This consumes relatively abundant FLASH memory area not SRAM.
- */
-void print_P(const char *s)
-{
- uint8_t c;
- while (1) {
- c = pgm_read_byte(s++);
- if (!c) break;
- if (c == '\n') sendchar('\r');
- sendchar(c);
- }
-}
-
-void print_CRLF(void)
-{
- sendchar('\r'); sendchar('\n');
-}
-
-
-#define SIGNED 0x80
-#define BIN 2
-#define OCT 8
-#define DEC 10
-#define HEX 16
-
-static inline
-char itoc(uint8_t i)
-{
- return (i < 10 ? '0' + i : 'A' + i - 10);
-}
-
-static inline
-void print_int(uint16_t data, uint8_t base)
-{
- char buf[7] = {'\0'};
- char *p = &buf[6];
- if ((base & SIGNED) && (data & 0x8000)) {
- data = -data;
- buf[0] = '-';
- }
- base &= ~SIGNED;
- uint16_t n;
- do {
- n = data;
- data /= base;
- *(--p) = itoc(n - data*base);
- } while (data);
- if (buf[0]) *(--p) = buf[0];
- print_S(p);
-}
-
-void print_dec(uint16_t data)
-{
- print_int(data, DEC);
-}
-
-void print_decs(int16_t data)
-{
- print_int(data, DEC|SIGNED);
-}
-
-
-static inline
-void print_hex4(uint8_t data)