原创 while中利用break跳出循环

2010-5-12 10:18 7901 7 7 分类: MCU/ 嵌入式

void Check_MACID()
 {
           unsigned char data CheckCount = 0;       //MAC ID检查次数
           unsigned char ReciveFlag = 0;                               //在等待定时期间,有接收到报文标志
           unsigned int *p;
           p = (unsigned int*)malloc(sizeof(unsigned int)*7);         //开辟MAC ID发送报文动态空间,此为调用的函数,在调用结束后自动释放,
                                                                      //在此完全可直接定义发送报文,此处试试动态操作
         while(SlaveState ==0)
         {
        


           SJASendData(p,TR_CMD);
           TR0 = 1;                                                   // 启动T0                                               
           while(TimeOver ==0)                                        //定时器未溢出,一直在此判断是否有收到报文
            {
             if(ReciveMassege == 1)
             {
              SlaveState  = 0;                                        // 如果收到报文,则从站进入通讯故障状态 


                                                                    //应在此跳出第二重循环whil(SlaveState        ==  0),若用break语句,只能跳出第一重循环while(TimeOver == 0)
              ReciveFlag = 1;       //所以在此用一个标志位,来表示收到数据                     
             }
         
            }
           
            if( ReciveFlag ==1)
              {
               TimeOver = 0;
               break;                       //以上等待过程结束后,若有收到数据则执行break语句,跳出第二重循环whil(SlaveState  ==  0),若未收到数据,则执行定时器溢出后相应的操作。
              }
          TimeOver = 0;                                               //清定时器标志位,此时定时器已经溢出 
          CheckCount++;
          if(CheckCount >=2)
            {
              SlaveState = 1;
            }
          
         }
 
 }

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条