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);

      };

}

 

처음

중요함수