AVRly - AVR Development Resources

Example main routine demonstrating the USART driver. More...

#include <util/delay.h>
#include "usart.h"

Go to the source code of this file.

Macros

#define BUFFER_SIZE   4
 
#define DECIMAL_NUM   255
 
#define SHORT_DELAY   500
 
#define LONG_DELAY   4000
 

Functions

int main ()
 Main routine for the example application. More...
 

Variables

char receive_buffer [BUFFER_SIZE]
 Character array to store the received data. More...
 

Detailed Description

Example main routine demonstrating the USART driver.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Jason Duffy
Date
15th March 2022
See also

Definition in file main.c.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   4

Definition at line 36 of file main.c.

◆ DECIMAL_NUM

#define DECIMAL_NUM   255

Definition at line 37 of file main.c.

◆ SHORT_DELAY

#define SHORT_DELAY   500

Definition at line 38 of file main.c.

◆ LONG_DELAY

#define LONG_DELAY   4000

Definition at line 39 of file main.c.

Function Documentation

◆ main()

int main ( )

Main routine for the example application.

Definition at line 51 of file main.c.

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}
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
char receive_buffer[BUFFER_SIZE]
Character array to store the received data.
Definition: main.c:45

Variable Documentation

◆ receive_buffer

char receive_buffer[BUFFER_SIZE]

Character array to store the received data.

Definition at line 45 of file main.c.