导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→[求助]关于AVR单片机的问题4[wangxd5429]

 *第60965篇: [求助]关于AVR单片机的问题4

  
楼 主:wangxd5429 2014年12月3日09:56
 [求助]关于AVR单片机的问题4
各位高手,小弟正在基于AVR开发一款智能小车,遇到“串口接收字符串错误”,调试了一下,发现当屏蔽了端口B后,可以正常显示,对端口B赋值后,无法正常显示。请教其中的原因。谢谢。部分代码如下:
void main(void)
{
        int counter = 0;
 int i;
 int stop_count = 0;
  
 MCUCSR |= BIT(7);
 MCUCSR |= BIT(7);
 
 vInitEeprom();
 uart0_init();
        init_devices();
        EECR |= BIT(EERIE);
 DUTY1=50;
        DUTY2=50;
        LCD_write_string(0,0,dis1);
        LCD_write_string(0,1,"SPACE:");
 memcpy (ControlMsg , "stop" , 4);
 addr = 1;
   
 while(1)
    {
    //str_send (Xunji);
    if (Xunji == 1)
    {
        //rcv_new = 0;
        //str_send ('x');
        stop_count = 0;
        forward();
     //delay_nms(10);
        if(L_XJ == 0 || R_XJ == 0)
           {
            break;
        }
    }    
    else if (Xunji == 0)
    {
        //rcv_new = 0;
     //str_send ('c');
        if (stop_count == 0)
     {
         //str_send ('c');
         stop();
         stop_count++;
     }
    }          
   }
 
 while(1)
    {     
     if (Xunji == 1)
  {   
      //rcv_new = 0;
      stop_count = 0;
      switch (PINB&0x03)
         {
             case 0x03:       
           DUTY1 = 35;
           DUTY2 = 35;
           //str_send ('a');
           forward();
           break;
          case 0x00:          
           DUTY1 = 35;
           DUTY2 = 35;
           //str_send ('b');
           forward();
           break;
          case 0x02:
      
           for (i = 0 ; i   < 5 ; i++)
           {
            if ((PINB&0x03) == 0x02)
            {
             counter++;
            }
            else if ((counter >  = 0)&&(counter   < 5)&&((PINB&0x03) == 0x03))
            {
                break;
            }

           }
      
           if (counter == 5)
           {  
            counter = 0;
                   DUTY1 = 40;
            //str_send ('c');
            left_slow();
           }  
           else if (counter != 5)
           {
               counter = 0;
       
            DUTY1 = 40;
            DUTY2 = 40;
            //str_send ('d');
            left();
           }
      
           break;
          case 0x01:
          
           for (i = 0 ; i   < 5 ; i++)
           {
               if ((PINB&0x03) == 0x01)
            {
                counter++;
            }
            else if ((counter >  = 0)&&(counter   < 5)&&((PINB&0x03) == 0x03))
            {
                break;
            }
           }
      
           if (counter == 5)
           {
            counter = 0;
       
                   DUTY2 = 40;
            //str_send ('e');
            right_slow();
           }  
           else if (counter != 5)
           {
            counter = 0;
       
          DUTY2 = 40;
            DUTY1 = 40;
            //str_send ('f');
            right();
           }
        break;
         default:
           break;
         }
  }
  else if (Xunji == 0)
  {
      //rcv_new = 0;
      if (stop_count == 0)
      {
         stop();
         stop_count++;
      }
  }   
  
  start_SB();
 }
}

#pragma interrupt_handler usart0_isr:12
void usart0_isr(void)
{
      static unsigned char i;
    
       UCSRB &= ~BIT(7);
 ControlMsg[i] = UDR;
 i++;
 if (i == 4)
 {
     i = 0;
     LCD_write_char(7,1,ControlMsg[0]);
     LCD_write_char(8,1,ControlMsg[1]);
     LCD_write_char(9,1,ControlMsg[2]);
     LCD_write_char(10,1,ControlMsg[3]);

  if (memcmp (ControlMsg , "star" , 4) == 0)
     {
         Xunji = 1;
     }
     else if (memcmp (ControlMsg , "stop" , 4) == 0)
     {
         Xunji = 0;
     }
     else
     {
         ;
     }  
 }
 UCSRB |= BIT(7);
}


>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:新手如何走进STM32(一)

[下一篇主题]:示波器探头上的10X是什么意思?