Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 16, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/3d11662211b90e15ad7c6e65df0b6ec0 to your computer and use it in GitHub Desktop.
Save avr-programmierung/3d11662211b90e15ad7c6e65df0b6ec0 to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz Funktionen zum Senden und Empfangen eines Bytes per USART-Rx-Interrupt
/*
* usart_interrupt_demo_01.c
* Funktionen zum Senden und Empfangen eines Bytes per USART-Rx-Interrupt
* Controller: ATmega88 @ 8MHz
*/
#include <avr/interrupt.h> // Headerdatei für Interrupts einbinden
...
...
void USART_Init( uint16_t ubrr)
{
/* Enable receiver, transmitter & Rx-interrupt */
UCSR0B = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0);
}
...
...
volatile uint8_t data; // global variable data (volatile for ISR)
int main( void )
{
...
...
sei(); // activate global interrupts
...
...
while(1)
{
// andere Aufgaben erledigen...
}
}
ISR(USART_RX_vect) // ISR Rx data
{
USART_Transmit(data = USART_Receive()); // receive on byte, send it
PORTB = data; // and write to Port B
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment