SHARE
TWEET

Untitled

a guest Nov 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <atmel_start.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4. #include <usart_basic.h>
  5. #include "UART.h"
  6.  
  7.  
  8. void UART_INIT(void)
  9. {
  10.     UCSR0A |= _BV(U2X0);
  11.    
  12.     UBRR0H = 0X00;
  13.     UBRR0L = 207;
  14.    
  15.     UCSR0C |= 0X06;
  16.    
  17.     UCSR0B |= _BV(RXEN0);
  18.     UCSR0B |= _BV(TXEN0);
  19. }
  20.  
  21. unsigned char UART_receive(void)
  22. {
  23.     while(!(UCSR0A & (1<<RXC0)));
  24.     return UDR0;
  25. }
  26.  
  27. void UART_transmit(unsigned char data)
  28. {
  29.     while( !(UCSR0A & (1<<UDRE0)));
  30.     UDR0 = data;
  31. }
  32.  
  33. int main(void)
  34. {
  35.     unsigned char data;
  36.     atmel_start_init();
  37.        
  38.     UART_INIT();
  39.     while (1) {
  40.         data = UART_receive();
  41.         UART_transmit(data);
  42.         if (data == '1')
  43.         {
  44.             LEDGreen_set_level(false);
  45.         }
  46.         else if(data == '2')
  47.         {
  48.             LEDYellow_set_level(false);
  49.         }
  50.         else if (data == '3')
  51.         {
  52.             LEDGreen_set_level(false);
  53.             LEDYellow_set_level(false);
  54.         }
  55.         else
  56.         {
  57.             LEDGreen_set_level(true);
  58.             LEDYellow_set_level(true);
  59.         }
  60.     }
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top