ManU_47

Untitled

Jul 13th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. // Spider Task 0                          //
  2. // Done by Manu Aatitya R P              //
  3. // Controlling DC motor using Bluetooth  //
  4.  
  5. #include<avr/io.h>
  6. #include<avr/interrupt.h>
  7.  
  8. /*
  9. #define F_CPU 16000000
  10. #define USART_BAUDRATE 9600
  11. #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE *16UL)))-1)
  12.  
  13. */
  14.  
  15. int ocr_value = 250;
  16.  
  17. // ISR for usart interrupt routine
  18. ISR(USART_RX_vect)
  19. {
  20.   char RecievedByte;
  21.   RecievedByte = UDR0;
  22.   UDR = RecievedByte;
  23.   switch(RecievedByte)
  24.   {
  25.     case 'U': if(OCR0A <=244)
  26.                   OCR0A +=10;
  27.   }
  28. }
  29.  
  30. // Set up of Usart Module
  31. void usart_setup()
  32. {
  33.   UCSR0B |= ((1<<RXEN0) | (1<<TXEN0));
  34.   UCSR0C |=((1<<UCSZ01) | (1<<UCSZ00));
  35.   UCSR0A |= 0x00;
  36.   UBRR0L |=0x67;
  37.   UCSR0B |=(1<<RXCIE);
  38.   sei()'
  39. }
  40.  
  41. void send_usart(unsigned char s)
  42. {
  43.  while(UCSR0A != (UCSR0A | (1<<UDRE0)));
  44.  UDR0 = s;
  45. }
  46.  
  47. int main()
  48. {
  49.  DDRB |= 0xff;
  50.  usart_setup();
  51.  unsigned char ch;
  52.  while(1)
  53.  {
  54.    while(UCSR0A != (UCSR0A | (1<<RXC0)));
  55.    ch = UDR0;
  56.    if(ch == 'N')
  57.    {
  58.      PORTB |=(1<<PB5);
  59.      PORTB &=(1<<PB4);
  60.      send_usart('N');
  61.      _delay_ms(1000);
  62.    }
  63.    else if (ch == 'F')
  64.    {
  65.      PORTB |=(1<<PB5) |(1<<PB4);
  66.      send_usart('F');
  67.      _delay_ms(1000);
  68.    }
  69.    
  70.  }
  71.  return 0;
  72. }
Add Comment
Please, Sign In to add comment