Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <atmel_start.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include <usart_basic.h>
- #include "UART.h"
- void UART_INIT(void)
- {
- UCSR0A |= _BV(U2X0);
- UBRR0H = 0X00;
- UBRR0L = 207;
- UCSR0C |= 0X06;
- UCSR0B |= _BV(RXEN0);
- UCSR0B |= _BV(TXEN0);
- }
- unsigned char UART_receive(void)
- {
- while(!(UCSR0A & (1<<RXC0))); //UART 데이터 수신
- return UDR0;
- }
- void UART_transmit(unsigned char data)
- {
- while( !(UCSR0A & (1<<UDRE0))); //UART 데이터 송신
- UDR0 = data;
- }
- int main(void)
- {
- unsigned char data;
- atmel_start_init();
- UART_INIT();
- while (1) {
- data = UART_receive();
- UART_transmit(data);
- if (data == '1')
- {
- LEDGreen_set_level(false); //수신된 값이 1이면 LEDGreen On
- }
- else if(data == '2')
- {
- LEDYellow_set_level(false); //수신된 값이 2면 LEDYellow On
- }
- else if (data == '3')
- {
- LEDGreen_set_level(false);
- LEDYellow_set_level(false); //수신된 값이 3이면 LED All On
- }
- else
- {
- LEDGreen_set_level(true);
- LEDYellow_set_level(true); //그 외 값이면 LED ALL OFF
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement