34#include <util/setbaud.h>
39static void transmit_byte(uint8_t data);
40static uint8_t receive_byte(
void);
54 UCSR0A |= (1 << U2X0);
56 UCSR0A &= ~(1 << U2X0);
60 UCSR0B = (1 << TXEN0) | (1 << RXEN0);
62 UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
71 transmit_byte(myString[i]);
85 while (count < (maxLength - 1))
87 response = receive_byte();
88 transmit_byte(response);
97 myString[count] = response;
108 transmit_byte(
'0' + (
byte / 100));
109 transmit_byte(
'0' + ((
byte / 10) % 10));
110 transmit_byte(
'0' + (
byte % 10));
116 transmit_byte(
'0' + (word / 10000));
117 transmit_byte(
'0' + ((word / 1000) % 10));
118 transmit_byte(
'0' + ((word / 100) % 10));
119 transmit_byte(
'0' + ((word / 10) % 10));
120 transmit_byte(
'0' + (word % 10));
127 for (bit = 7; bit < 255; bit--)
129 if (bit_is_set(
byte, bit))
145 return (
'0' + nibble);
149 return (
'A' + nibble - 10);
157 nibble = (
byte & 0b11110000) >> 4;
159 nibble =
byte & 0b00001111;
175 thisChar = receive_byte();
176 transmit_byte(thisChar);
178 while (thisChar !=
'\r');
181 return (100 * (hundreds -
'0') + 10 * (tens -
'0') + ones -
'0');
186static void transmit_byte(uint8_t data)
189 loop_until_bit_is_set(UCSR0A, UDRE0);
194static uint8_t receive_byte(
void)
197 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.