AVRly - AVR Development Resources
main.c
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 main.c
25 * @ingroup usart
26 * @author Jason Duffy
27 * @date 15th March 2022
28 * @brief Example main routine demonstrating the USART driver.
29 * @bug No known bugs.
30 * @see
31 */
32
33#include <util/delay.h>
34#include "usart.h"
35
36#define BUFFER_SIZE 4
37#define DECIMAL_NUM 255
38#define SHORT_DELAY 500
39#define LONG_DELAY 4000
40
41
42/**
43 * Character array to store the received data.
44 */
45char receive_buffer[BUFFER_SIZE];
46
47
48/**
49 * Main routine for the example application.
50 */
51int main()
52{
53 // Setup and initialisation routines.
54 init_usart();
55 usart_print_string("USART Initialised\n\n\n");
56
57 // Loop forever.
58 while (1)
59 {
60 // ------- Echo demonstration. -------- //
61 usart_print_string("Type any three characters.\n");
63 usart_print_string("\nYou entered: ");
64
65 for (uint8_t index = 0; index < (BUFFER_SIZE - 1); ++index)
66 {
67 //char data = receive_buffer[index];
69 }
70 usart_print_string("\n\n\n");
71
72
73 // -------- Data format demonstration. -------- //
74 usart_print_string("Lets start with the decimal number ");
75 usart_print_byte(DECIMAL_NUM);
76 _delay_ms(SHORT_DELAY);
78 usart_print_string("In 8 bit binary format, that's: ");
79 usart_print_binary_byte(DECIMAL_NUM);
80 _delay_ms(SHORT_DELAY);
82 usart_print_string("In hexadecimal format, that's: ");
83 usart_print_hex_byte(DECIMAL_NUM);
84 usart_print_string("\n\n\n");
85 _delay_ms(LONG_DELAY);
86 }
87
88 return 0;
89}
90
91
92/*** end of file ***/
void usart_print_string(const char myString[])
Utility function to transmit a string.
Definition: usart.c:74
void usart_print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
Definition: usart.c:121
void usart_read_string(char myString[], uint8_t maxLength)
Define a string variable, pass it to this function.
Definition: usart.c:92
void usart_print_binary_byte(uint8_t byte)
Prints a byte out in 1s and 0s.
Definition: usart.c:169
void usart_print_char(char byte)
Prints a byte out as its 1-character ascii equivalent.
Definition: usart.c:145
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 usart_print_hex_byte(uint8_t byte)
Prints a byte out in hexadecimal format.
Definition: usart.c:207
int main()
Main routine to be executed on the MCU.
Definition: main.c:45
char receive_buffer[BUFFER_SIZE]
Character array to store the received data.
Definition: main.c:45
Driver file providing core USART communication between the target MCU and your PC.