35#include <util/setbaud.h>
40static void transmit_byte(uint8_t data);
41static uint8_t receive_byte(
void);
55 UCSR0A |= (1 << U2X0);
57 UCSR0A &= ~(1 << U2X0);
61 UCSR0B = (1 << TXEN0) | (1 << RXEN0);
63 UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
72 transmit_byte(myString[i]);
86 while (count < (maxLength - 1))
88 response = receive_byte();
89 transmit_byte(response);
98 myString[count] = response;
109 transmit_byte(
'0' + (
byte / 100));
110 transmit_byte(
'0' + ((
byte / 10) % 10));
111 transmit_byte(
'0' + (
byte % 10));
117 transmit_byte(
'0' + (word / 10000));
118 transmit_byte(
'0' + ((word / 1000) % 10));
119 transmit_byte(
'0' + ((word / 100) % 10));
120 transmit_byte(
'0' + ((word / 10) % 10));
121 transmit_byte(
'0' + (word % 10));
128 for (bit = 7; bit < 255; bit--)
130 if (bit_is_set(
byte, bit))
146 return (
'0' + nibble);
150 return (
'A' + nibble - 10);
158 nibble = (
byte & 0b11110000) >> 4;
160 nibble =
byte & 0b00001111;
176 thisChar = receive_byte();
177 transmit_byte(thisChar);
179 while (thisChar !=
'\r');
182 return (100 * (hundreds -
'0') + 10 * (tens -
'0') + ones -
'0');
187static void transmit_byte(uint8_t data)
190 loop_until_bit_is_set(UCSR0A, UDRE0);
195static uint8_t receive_byte(
void)
198 loop_until_bit_is_set(UCSR0A, RXC0);
void init_usart(void)
Takes the defined BAUD and F_CPU, calculates the bit-clock multiplier, configures the hardware USART ...
void print_word(uint16_t word)
Prints a word (16-bits) out as its 5-digit ascii equivalent.
void print_string(const char myString[])
Utility function to transmit an entire string from RAM.
uint8_t get_number(void)
Takes in up to three ascii digits, converts them to a byte when press enter.
void print_binary_byte(uint8_t byte)
Prints a byte out in 1s and 0s.
char nibble_to_hex_character(uint8_t nibble)
Convert nibble to hex character.
void read_string(char myString[], uint8_t maxLength)
Define a string variable, pass it to this function.
void print_hex_byte(uint8_t byte)
Prints a byte out in hexadecimal.
void print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
Driver file providing core USART communication between the target MCU and your PC.