Page 537 - 2
P. 537

{
                            while(!(UCSR1A & 0x20));
                            UDR1 = ' ';
                        }
                    }
                    dig = 0;
            }


            ----------------------------------------------------
              나. RECIVE   코드


            #include <mega128.h>
            #include <delay.h>






            #define MIN 167          // 1 ms
            #define MAX 3334          // 20ms


            #define MOT1 PORTC.0
            #define MOT2 PORTC.1
            #define MOT3 PORTC.2
            #define MOT4 PORTC.3
            #define MOT5 PORTC.4         // PORTC 0~4  까지 연결 되있는 서보모터 선




            int count = 0;          //  서보모터를 구동시키기 위한 변수




            unsigned int angle[5] = {0,0,0,0,0};           // 통신을 통해 데이터를 받고 저장하는 변수 (                 서보모
            터의 각도를 의미 )


            void main()
            {
            int temp[5],i,flag = 0;
            char data = 0, now = 0, past = 0;     //  수신을 할 때 데이터를 정리하기 위한 변수,                data
            // flag 를 받아 상 하위비트를 걸러내는 변수,             now, past
            DDRD = 0xff;
            DDRC = 0xff;
            DDRF = 0xcf;
            PORTD = 0x01;


            UCSR1A = 0x00;
            UCSR1B = 0x18;        //  수신기 송신기,     Enable  설정
            UCSR1C = 0x06;        // 8Bit  데이터 전송 설정


                                                         - 537 -
   532   533   534   535   536   537   538   539   540   541   542