모형자동차 제어

#include <mega128.h>  

#include <stdio.h>

 

char rxd;

 

// USART0 Receiver interrupt service routine

interrupt [USART0_RXC] void uart0_rx_isr(void)

{

   // 전송전 문자를 받는다.

   rxd=getchar();

   // 문자"0"=정지  문자"1"=전진  문자"2"=좌회전  문자"3"=우회전  문자"4"=후진

   if(rxd==0x30)

      PORTC=~0x00;

   else if(rxd==0x31)

      PORTC=~0x05;

   else if(rxd==0x32)

      PORTC=~0x09;

   else if(rxd==0x33)

      PORTC=~0x06;

   else if(rxd==0x34)

      PORTC=~0x0a;

}

 

// Declare your global variables here

 

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

PORTC=0x00;

DDRC=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;

 

// Global enable interrupts

#asm("sei") 

 

while (1)

      {

      // Place your code here

      };

}

처음

중요함수