-
- /*
- * * Bluetooth_Dongle_test.cpp
- * *
- * * Created: 18.01.2014 16:59:18
- * * Author: h0d3nt3uf3l
- * */
-
-
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
-
-
- #define BAUD 9600
- //#define MYUBRR F_CPU/16/BAUD-1
- #define MYUBRR ((uint16_t) ((F_CPU / ((BAUD) * 16.0)) + .5) - 1)
-
-
- uint8_t data;
-
-
- void USART_Init(unsigned int ubrr)
- {
- /*Set baud rate*/
- UBRRH = (unsigned char)(ubrr>>8);
- UBRRL = (unsigned char)(ubrr);
- /* Enable receiver and transmitter & Interrupts for RX & TX*/
- UCSRB = (1<<RXEN) | (1<<TXEN) | (1<<RXCIE) | (1<< TXCIE);
- /* Set frame format: 8data, 1stop bit */
- UCSRC = (1<<UCSZ0) | (1<<UCSZ1);
-
- }
-
- void USART_transmit()
- {
- UDR = (data);
- }
-
- int main(void)
- {
- DDRD |= (1 << PD6) | (1 << PD7);
- //led test
- PORTD |= (1 << PD6); // Turn on LED1
- PORTD |= (1 << PD7); // Turn on LED2
- _delay_ms(3000);
- PORTD &= ~(1 << PD6); // Turn off LED1
- PORTD &= ~(1 << PD7); // Turn off LED2
-
- sei();
-
- USART_Init(MYUBRR);
- _delay_ms(10);
-
- while(1)
- ;
- }
-
- ISR(USART_RXC_vect) //Receive complete
- {
- data = UDR;
- USART_transmit();
- PORTD |= (1 << PD6); // Turn on LED1
- PORTD &= ~(1 << PD7); // Turn off LED2
- }
-
- ISR(USART_TXC_vect) //Transmit complete
- {
- data = 0;
- PORTD &= ~(1 << PD6); // Turn off LED1
- PORTD |= (1 << PD7); // Turn on LED2
- }
-