Page 121 - MDP2020-3
P. 121

················································································  명장양성프로젝트  【MDP】  과제발표회  자료집  Ⅲ    |  115


                    PORTC.5  =  0;


                    //2.  초음파  센서에서  초음파  출력
                    //3.  거리  측정
                    //3-1  상승  엣지  감지  --  인터럽트
                    //3-2  하강  엣지  감지  --  인터럽트
            }



            interrupt  [EXT_INT4]  void  echo_start()  //상승  엣지  감지  --  인터럽트
            {
                    //카운터  시작
                    TIMSK  =  0b00000001;  //tc0  ovf  interrupt  :  enable;

            }


            interrupt  [EXT_INT5]  void  echo_finish()  //하강  엣지  감지  --  인터럽트
            {
                    TIMSK  =  0b00000000;  //tc2  ovf  interrupt  :  disable;


                    //distance(cm)  =  uS  /  58(SPEC)

                    if(dist2!=0  &&  dist/24<=100){      //dist2가  0이  아니고 dist2/24가  120이하일 경우만  출력
                            printf("raw  :  %d,  distance(cm)  :  %d\r  cm",  dist2,  (dist2/24));

                            dist2  =  0;
                    }


            }
            interrupt  [EXT_INT6]  void  echo_start2()

            {
                    TIMSK  =  0b000000001;    //tc2  ovf  interrupt  :  enable;
            }
            interrupt  [EXT_INT7]  void  echo_finish2()
            {

                    TIMSK  =  0b00000000;  //tc2  ovf  interrupt  :  disable;

                    //distance(cm)  =  uS  /  58(SPEC)

                    if(dist2<=210  &&  dist/24>=150){      //dist2가 0이 아니고 dist2/24가 120이하일 경우만 출력

                            printf("raw  :  %d,  distance(cm)  :  %d\r  cm",  dist2,  (dist2/24));
                            dist2  =  0;
                    }
            }
   116   117   118   119   120   121   122   123   124   125   126