ATtiny85 Template Code
Code snippets for the ATtiny85
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
uart_print.c
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------*
2 * Formatted serial output functions
3 *---------------------------------------------------------------------------*
4 * 14-Apr-2014 ShaneG
5 *
6 * Provides some simple formatted output functions for serial communications.
7 *--------------------------------------------------------------------------*/
8 #include "../hardware.h"
9 #include "softuart.h"
10 #include "utility.h"
11 
12 // Only if enabled
13 #ifdef UART_ENABLED
14 
22 void uartPrint(const char *cszString) {
23  while(*cszString) {
24  uartSend(*cszString);
25  cszString++;
26  }
27  }
28 
36 void uartPrintP(const char *cszString) {
37  uint8_t ch;
38  while((ch = pgm_read_byte_near(cszString))!='\0') {
39  uartSend(ch);
40  cszString++;
41  }
42  }
43 
50 void uartInt(uint16_t value) {
51  bool emit = false;
52  // Special case for 0
53  if(value==0) {
54  uartSend('0');
55  return;
56  }
57  // Emit the value, skip leading zeros
58  for(uint16_t divisor = 10000; divisor > 0; divisor = divisor / 10) {
59  uint8_t digit = value / divisor;
60  value = value % divisor;
61  if((digit>0)||emit) {
62  uartSend('0' + digit);
63  emit = true;
64  }
65  }
66  }
67 
74 void uartHex(uint16_t value) {
75  uartSend(hexChar(value >> 12));
76  uartSend(hexChar(value >> 8));
77  uartSend(hexChar(value >> 4));
78  uartSend(hexChar(value));
79  }
80 
81 #endif /* UART_ENABLED */
82 
void uartInt(uint16_t value)
Definition: uart_print.c:50
void uartPrint(const char *cszString)
Definition: uart_print.c:22
void uartPrintP(const char *cszString)
Definition: uart_print.c:36
char hexChar(uint8_t value)
Definition: utility.c:37
void uartHex(uint16_t value)
Definition: uart_print.c:74
void uartSend(char ch)
Definition: uart_send.c:52