[求助]关于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);
}
发表时间:2014年12月3日9:56:49