Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- void setup();
- void uart_putByte(uint8_t byte);
- void uart_putString(uint8_t* str);
- uint8_t uart_getByte();
- int main(){
- //Ruft setup
- setup();
- while(1) {
- for(uint8_t i=1; i<10; i++ ) {
- uart_putByte( '0' + i);
- _delay_ms( 1000 );
- }
- _delay_ms( 1000 );
- uart_putByte( '\n');
- uart_putString("UART TEST BItches!\n");
- uint8_t rec = uart_getByte();
- uart_putString("Got: ");
- uart_putByte(rec);
- }
- return 0;
- }
- void setup(){
- //UBBRL und UBBRH mit dem Wert aus dem Datenblatt laden
- UBRRH = 0x00;
- UBRRL = 7;
- //->Even parity
- //->1 Stop Bit
- //->8 Bits an Daten
- //UCSRA laden
- UCSRA = 0x00;
- //UCSRB laden
- UCSRB = (1<<RXEN) | (1<<TXEN);
- //UCSRC laden
- UCSRC = (1<<URSEL) | (1<<UCSZ0) | (1<<UCSZ1) | (1<<UPM1);
- }
- void uart_putByte(uint8_t byte){
- //Warten bis UDR leer ist -> Bit in UCSRA
- while( !( UCSRA & ( 1<<UDRE )));
- //Daten in UDR laden
- UDR = byte;
- }
- void uart_putString(uint8_t* str) {
- while(str != 0){
- uart_putByte(*(str++));
- }
- }
- uint8_t uart_getByte(){
- //Warten bis Empfangen komplett ist -> Bit in UCSRA
- while( !( UCSRA & ( 1<<RXC ) ) );
- //Daten aus UDR lesen
- return UDR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement