Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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))); //UART 데이터 수신
  24. return UDR0;
  25. }
  26.  
  27. void UART_transmit(unsigned char data)
  28. {
  29. while( !(UCSR0A & (1<<UDRE0))); //UART 데이터 송신
  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); //수신된 값이 1이면 LEDGreen On
  45. }
  46. else if(data == '2')
  47. {
  48. LEDYellow_set_level(false); //수신된 값이 2면 LEDYellow On
  49. }
  50. else if (data == '3')
  51. {
  52. LEDGreen_set_level(false);
  53. LEDYellow_set_level(false); //수신된 값이 3이면 LED All On
  54. }
  55. else
  56. {
  57. LEDGreen_set_level(true);
  58. LEDYellow_set_level(true); //그 외 값이면 LED ALL OFF
  59. }
  60. }
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement