AVRly - AVR Development Resources
usart.h
Go to the documentation of this file.
1/******************************************************************************
2 @copyright Copyright © 2022 by Jason Duffy.
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21******************************************************************************/
22
23/**
24 * @file usart.h
25 * @ingroup mcp48x2
26 * @author Jason Duffy
27 * @date 15th March 2022
28 * @brief Driver file providing core USART communication between the target MCU
29 * and your PC.
30 * @bug No known bugs.
31 * @see
32 */
33
34
35#ifndef BAUD // If not defined in Makefile
36#define BAUD 9600 // Set a safe default baud rate
37#endif
38
39#ifndef USART_DOT_H
40#define USART_DOT_H
41
42#include <stdint.h>
43
44//These are defined for convenience
45#define USART_HAS_DATA bit_is_set(UCSR0A, RXC0)
46#define USART_READY bit_is_set(UCSR0A, UDRE0)
47
48
49/**
50 * Takes the defined BAUD and F_CPU, calculates the bit-clock multiplier,
51 * configures the hardware USART.
52 */
53void init_usart(void);
54
55
56/**
57 * Utility function to transmit an entire string from RAM.
58 */
59void print_string(const char myString[]);
60
61
62/**
63 * Define a string variable, pass it to this function. The string will contain
64 * whatever you typed over serial.
65 */
66void read_string(char myString[], uint8_t maxLength);
67
68
69/**
70 * Prints a byte out as its 3-digit ascii equivalent.
71 */
72void print_byte(uint8_t byte);
73
74
75/**
76 * Prints a word (16-bits) out as its 5-digit ascii equivalent.
77 */
78void print_word(uint16_t word);
79
80
81/**
82 * Prints a byte out in 1s and 0s.
83 */
84void print_binary_byte(uint8_t byte);
85
86
87// !!
88// TODO: find implementation for this and define difference to function below
89// !!
90/**
91 * Convert nibble to hex.
92 */
93char nibble_to_hex(uint8_t nibble);
94
95
96/**
97 * Convert nibble to hex character.
98 */
99char nibble_to_hex_character(uint8_t nibble);
100
101
102/**
103 * Prints a byte out in hexadecimal.
104 */
105void print_hex_byte(uint8_t byte);
106
107
108/**
109 * Takes in up to three ascii digits, converts them to a byte when press enter.
110 */
111uint8_t get_number(void);
112
113
114#endif // USART_DOT_H
115
116/*** end of file ***/
void init_usart(void)
Takes the defined BAUD and F_CPU, calculates the bit-clock multiplier, configures the hardware USART ...
Definition: usart.c:50
void print_word(uint16_t word)
Prints a word (16-bits) out as its 5-digit ascii equivalent.
Definition: usart.c:115
void print_string(const char myString[])
Utility function to transmit an entire string from RAM.
Definition: usart.c:67
uint8_t get_number(void)
Takes in up to three ascii digits, converts them to a byte when press enter.
Definition: usart.c:165
void print_binary_byte(uint8_t byte)
Prints a byte out in 1s and 0s.
Definition: usart.c:125
char nibble_to_hex_character(uint8_t nibble)
Convert nibble to hex character.
Definition: usart.c:142
void read_string(char myString[], uint8_t maxLength)
Define a string variable, pass it to this function.
Definition: usart.c:81
char nibble_to_hex(uint8_t nibble)
Convert nibble to hex.
void print_hex_byte(uint8_t byte)
Prints a byte out in hexadecimal.
Definition: usart.c:155
void print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
Definition: usart.c:106