Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Spider Task 0 //
- // Done by Manu Aatitya R P //
- // Controlling DC motor using Bluetooth //
- #include<avr/io.h>
- #include<avr/interrupt.h>
- /*
- #define F_CPU 16000000
- #define USART_BAUDRATE 9600
- #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE *16UL)))-1)
- */
- int ocr_value = 250;
- // ISR for usart interrupt routine
- ISR(USART_RX_vect)
- {
- char RecievedByte;
- RecievedByte = UDR0;
- UDR = RecievedByte;
- switch(RecievedByte)
- {
- case 'U': if(OCR0A <=244)
- OCR0A +=10;
- }
- }
- // Set up of Usart Module
- void usart_setup()
- {
- UCSR0B |= ((1<<RXEN0) | (1<<TXEN0));
- UCSR0C |=((1<<UCSZ01) | (1<<UCSZ00));
- UCSR0A |= 0x00;
- UBRR0L |=0x67;
- UCSR0B |=(1<<RXCIE);
- sei()'
- }
- void send_usart(unsigned char s)
- {
- while(UCSR0A != (UCSR0A | (1<<UDRE0)));
- UDR0 = s;
- }
- int main()
- {
- DDRB |= 0xff;
- usart_setup();
- unsigned char ch;
- while(1)
- {
- while(UCSR0A != (UCSR0A | (1<<RXC0)));
- ch = UDR0;
- if(ch == 'N')
- {
- PORTB |=(1<<PB5);
- PORTB &=(1<<PB4);
- send_usart('N');
- _delay_ms(1000);
- }
- else if (ch == 'F')
- {
- PORTB |=(1<<PB5) |(1<<PB4);
- send_usart('F');
- _delay_ms(1000);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment