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;
124 transmit_byte(
'0' + (
byte / 100));
125 transmit_byte(
'0' + ((
byte / 10) % 10));
126 transmit_byte(
'0' + (
byte % 10));
157 transmit_byte(
'0' + (word / 10000));
158 transmit_byte(
'0' + ((word / 1000) % 10));
159 transmit_byte(
'0' + ((word / 100) % 10));
160 transmit_byte(
'0' + ((word / 10) % 10));
161 transmit_byte(
'0' + (word % 10));
172 for (bit = 7; bit < 255; bit--)
174 if (bit_is_set(
byte, bit))
194 return (
'0' + nibble);
198 return (
'A' + nibble - 10);
210 nibble = (
byte & 0b11110000) >> 4;
212 nibble =
byte & 0b00001111;
232 thisChar = receive_byte();
233 transmit_byte(thisChar);
235 while (thisChar !=
'\r');
238 return (100 * (hundreds -
'0') + 10 * (tens -
'0') + ones -
'0');
247static void transmit_byte(uint8_t data)
250 loop_until_bit_is_set(UCSR0A, UDRE0);
256static uint8_t receive_byte(
void)
259 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.