int main(void)
{
u16 x,y,z;
u8 button;
u8 Buffer[9];
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init_all(115200);
LED_Init();
stepperMotor_Init();
Encoder_Init();
while(1)
{
for(u8 i=0;i<USART_REC_LEN;i++)
{
if(USART_RX_BUF[i]==0xff)
{
//memcpy(&Buffer[0],&USART_RX_BUF[i],9);
Buffer[0]=USART_RX_BUF[i];
Buffer[1]=USART_RX_BUF[1+i];
Buffer[2]=USART_RX_BUF[2+i];
Buffer[3]=USART_RX_BUF[3+i];
Buffer[4]=USART_RX_BUF[4+i];
Buffer[5]=USART_RX_BUF[5+i];
Buffer[6]=USART_RX_BUF[6+i];
Buffer[7]=USART_RX_BUF[7+i];
Buffer[8]=USART_RX_BUF[8+i];
u8 m;
u8 sum_check=0;
for(m=1;m<8;m++)
{
sum_check=sum_check+Buffer[m];
}
if(sum_check==Buffer[8])
{
x=(Buffer[1]<<8)|(Buffer[2]);
y=(Buffer[3]<<8)|(Buffer[4]);
z=(Buffer[5]<<8)|(Buffer[6]);
button=Buffer[7];
if(x<0x0200)printf("Left
");
else if((x>0x0200)&(x<=0x3ff))printf("Right
");
else if(x==0x0200)printf("No LR
");
if(y<0x0200)printf("Up
");
else if((y>0x0200)&(y<=0x3ff))printf("Down
");
else if(y==0x0200)printf("No UD
");
if(z<0x0200)printf("Wide
");
else if((z>0x0200)&(z<=0x3ff))printf("Tele
");
else if(z==0x0200)printf("No WT
");
if(button==0x02)printf("Burron
");
else if(button==0x00)printf("No Button
");
USART_RX_STA=0;
sum_check=0;
}
else
{printf("
");
USART_RX_STA=0;
sum_check=0;
}
printf("
");
USART_RX_STA=0;
sum_check=0; }
}
LED0=!LED0;//DS0·-×a
delay_ms(400);//Ñóê±200ms
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>