Created
May 16, 2019 12:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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