36#include <util/setbaud.h>
42static void transmit_byte(uint8_t data);
43static uint8_t receive_byte(
void);
57 UCSR0A |= (1 << U2X0);
59 UCSR0A &= ~(1 << U2X0);
63 UCSR0B = (1 << TXEN0) | (1 << RXEN0);
65 UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
79 transmit_byte(myString[i]);
97 while (count < (maxLength - 1))
99 response = receive_byte();
100 transmit_byte(response);
102 if (response ==
'\r')
109 myString[count] = response;
126 transmit_byte(
'0' + (
byte / 100));
130 transmit_byte(
'0' + ((
byte / 10) % 10));
132 transmit_byte(
'0' + (
byte % 10));
163 transmit_byte(
'0' + (word / 10000));
164 transmit_byte(
'0' + ((word / 1000) % 10));
165 transmit_byte(
'0' + ((word / 100) % 10));
166 transmit_byte(
'0' + ((word / 10) % 10));
167 transmit_byte(
'0' + (word % 10));
178 for (bit = 7; bit < 255; bit--)
180 if (bit_is_set(
byte, bit))
200 return (
'0' + nibble);
204 return (
'A' + nibble - 10);
216 nibble = (
byte & 0b11110000) >> 4;
218 nibble =
byte & 0b00001111;
238 thisChar = receive_byte();
239 transmit_byte(thisChar);
241 while (thisChar !=
'\r');
244 return (100 * (hundreds -
'0') + 10 * (tens -
'0') + ones -
'0');
253static void transmit_byte(uint8_t data)
256 loop_until_bit_is_set(UCSR0A, UDRE0);
262static uint8_t receive_byte(
void)
265 loop_until_bit_is_set(UCSR0A, RXC0);
void usart_print_decimal_digit(uint8_t byte)
Prints a byte out as its 1-digit ascii equivalent.
void usart_print_string(const char myString[])
Utility function to transmit a string.
void usart_print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
void usart_read_string(char myString[], uint8_t maxLength)
Define a string variable, pass it to this function.
void usart_print_binary_byte(uint8_t byte)
Prints a byte out in 1s and 0s.
void usart_print_word(uint16_t word)
Prints a word (16-bits) out as its 5-digit ascii equivalent.
char usart_nibble_to_hex_character(uint8_t nibble)
Convert a nibble to a hex character.
uint8_t usart_get_number(void)
Takes in up to three ascii digits, converts them to a byte when press enter.
void usart_print_char(char byte)
Prints a byte out as its 1-character ascii equivalent.
void init_usart(void)
Takes the defined BAUD and F_CPU, calculates the bit-clock multiplier, configures the hardware USART ...
void usart_print_hex_byte(uint8_t byte)
Prints a byte out in hexadecimal format.
Driver file providing core USART communication between the target MCU and your PC.