You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
837 B
49 lines
837 B
10 years ago
|
//
|
||
|
// Example of basic UART usage
|
||
|
//
|
||
|
|
||
10 years ago
|
#include <avr/io.h>
|
||
|
#include <avr/pgmspace.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "lib/uart.h"
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
// Enable UART with baud rate 9600
|
||
|
uart_init(9600);
|
||
|
|
||
|
// --- some examples of printing functions ---
|
||
|
|
||
|
|
||
|
// Printing a string
|
||
|
uart_puts("Simple UART example!\r\n");
|
||
|
|
||
10 years ago
|
// Use _pgm for strings in program memory
|
||
|
// (PSTR macro is defined in avr/pgmspace.h)
|
||
10 years ago
|
uart_puts_P(PSTR("Program memory string example\r\n"));
|
||
10 years ago
|
|
||
|
// print a char. This is an alias for uart_tx
|
||
|
uart_putc('a');
|
||
|
|
||
10 years ago
|
// For printing numbers, please check "uart_stream.c" example
|
||
10 years ago
|
|
||
|
|
||
|
// --- receive example ---
|
||
|
|
||
|
// Example of listening for input
|
||
|
while(1) {
|
||
10 years ago
|
|
||
10 years ago
|
// If something is received
|
||
|
if (uart_rx_ready()) {
|
||
10 years ago
|
|
||
10 years ago
|
// Get the received byte
|
||
|
char c = uart_rx();
|
||
10 years ago
|
|
||
10 years ago
|
// Send it back, twice
|
||
|
uart_tx(c);
|
||
|
uart_tx(c);
|
||
|
}
|
||
|
}
|
||
|
}
|