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.
43 lines
631 B
43 lines
631 B
10 years ago
|
//
|
||
|
// Example of UART with interrupts
|
||
|
//
|
||
|
|
||
10 years ago
|
#include <avr/io.h>
|
||
|
#include <util/delay.h>
|
||
|
#include <avr/pgmspace.h>
|
||
|
#include <avr/interrupt.h>
|
||
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#include "lib/uart.h"
|
||
10 years ago
|
#include "lib/stream.h"
|
||
10 years ago
|
|
||
|
|
||
|
// UART receive interrupt vector
|
||
|
ISR(USART_RX_vect)
|
||
|
{
|
||
|
uint8_t c = uart_rx();
|
||
|
|
||
|
// print character and it's code
|
||
10 years ago
|
uart_tx(c);
|
||
|
uart_tx(' ');
|
||
|
put_u8(uart, c);
|
||
|
put_nl(uart);
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
// Set up UART at speed 9600 baud
|
||
|
uart_init(9600);
|
||
|
// Enable receive ISR
|
||
|
uart_isr_rx(1);
|
||
|
// Enable interrupts
|
||
|
sei();
|
||
|
|
||
|
// Greeter string
|
||
10 years ago
|
put_str_P(uart, PSTR("UART receiver with ISR\r\n"));
|
||
10 years ago
|
|
||
|
while(1);
|
||
|
}
|