Advertisement
ktostam450

[ARDUINO] USART zapalanie LED

May 8th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <avr/io.h>
  2.  
  3. #define BAUDRATE 9600UL
  4. #define PRESCALE (((F_CPU / (BAUDRATE * 16UL))) - 1)
  5.  
  6. #define LED_PIN (1<<5)
  7. #define LED_PORT PORTB
  8. #define LED_DDR DDRB
  9.  
  10. int main (void)
  11. {
  12.     uint8_t cmd;
  13.     LED_DDR |= LED_PIN;
  14.     UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
  15.     UBRR0 = PRESCALE;
  16.     for(;;) {
  17.         while ( !(UCSR0A & (1<<RXC0)) );
  18.         cmd = UDR0;
  19.         if (cmd == '1') {
  20.             LED_PORT |= LED_PIN;
  21.         } else if (cmd == '0') {
  22.             LED_PORT &= ~LED_PIN;
  23.         } else {
  24.             LED_PORT ^= LED_PIN;
  25.         }              
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement