RS232·Î Ãâ·ÂÀ» Á¦¾î
|
#include <mega128.h> #include
<delay.h> #include
<stdio.h> // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B #endasm #include <lcd.h> char rxd; // USART0 Receiver interrupt service
routine interrupt [USART0_RXC]
void uart0_rx_isr(void) { // Àü¼ÛÀü ¹®ÀÚ¸¦ ¹Þ´Â´Ù. rxd=getchar(); // LCD¿¡ ¹®ÀÚ¸¦ Ç¥½ÃÇÑ´Ù. lcd_gotoxy(0,0); lcd_putchar(rxd); // ¹®ÀÚ"1"=B0
Led On ¹®ÀÚ"2"=B1
Led On ¹®ÀÚ"3"=B2
Led On if(rxd==0x31) PORTB=~0x01; else if(rxd==0x32) PORTB=~0x02; else if(rxd==0x33) PORTB=~0x04; } void main(void) { // Port B initialization // Func0=Out Func1=Out Func2=Out
Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out // State0=0 State1=0 State2=0 State3=0
State4=0 State5=0 State6=0 State7=0 PORTB=0x00; DDRB=0xFF; // USART0 initialization // Communication Parameters: 8 Data, 1
Stop, No Parity // USART0 Receiver: On // USART0 Transmitter: On // USART0 Mode: Asynchronous // USART0 Baud rate: 9600 UCSR0A=0x00; UCSR0B=0xD8; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x67; // LCD module initialization lcd_init(16); // Global enable interrupts #asm("sei") while (1) { // Place your code here PORTB=~0x00;
delay_ms(100); }; }
|
Áß¿äÇÔ¼ö |
|