Krv Perera
Newbie level 2
- Joined
- Oct 8, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 19
// This code waits for a character and transmits the character back (with interrupts)
Above is my code but my Interrupts not working as I intended
Code dot - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #define F_CPU 16000000UL #include <avr/io.h> #include <stdint.h> // needed for uint8_t #include <util/delay.h> #include <avr/interrupt.h> #define FOSC 16000000 // Clock Speed #define BAUD 9600 #define MYUBRR FOSC/16/BAUD -1 volatile char ReceivedChar; int main( void ) { //cli(); DDRB = 0xFF; //LED off PORTB = 0x00; UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter //RX interrupt enabled UCSR0C |= (1 << UCSZ01);// | (1 << UCSZ00); // Set frame: 8data, 1 stp /*Set baud rate */ UBRR0H = (( MYUBRR ) >> 8); UBRR0L = MYUBRR; UCSR0B |= (1 << RXCIE0); sei(); while(1) { if( ReceivedChar == 'C' || ReceivedChar == 'c'){ PORTB |= (1<<PORTB5); _delay_ms(500); } PORTB = 0x00; _delay_ms(500); PORTB = 0xFF; _delay_ms(500); // Main loop } } ISR (USART0_RX_vect , ISR_BLOCK) { ReceivedChar = UDR0; UDR0 = ReceivedChar; //sei(); }
Above is my code but my Interrupts not working as I intended