我定义了一个指针* Receiver,定义了两个Receivebuf[20],Receivebuf1[20],准备接收两次数据。第一次指针指向p2+1,然后将第一次接收的0xff存在Receivebuf[0]中,接收的0x00存在Receivebuf[1]中,第二次指针指向p2+3:第二次接收的数据是与第一次数据不相同,第二次接收的数据分别存在Receivebuf1[0],Receivebuf1[1]中,结果单片机程序运行后,两次不同的Receivebuf[0],Receivebuf[1]与Receivebuf1[0],Receivebuf1[1]中数据都一样,都是:0xff,0x00。怎么回事?哪位高手对指针应用比较熟练,我第二次接收数据程序哪里出了问题?求教!!!
Receiver=(p2+1);
Receivebuf[0]=Receiver[0];
Receivebuf[1]=Receiver[1];
if(i==0&&Receivebuf[0]==0xff&&Receivebuf[1]==0x00) //第一次接收0xff,0x00
{
sprintf((char*)dtbuf2,"%02X%02X",Receivebuf[0],Receivebuf[1]);
Show_Str(170,415,1000,12,dtbuf2,12,0);
i++;
}
Receiver=(p2+3);
Receivebuf1[0]=Receiver[0];
Receivebuf1[1]=Receiver[1];
if(i==1&&Receivebuf1[0]!=Receivebuf[0]&&Receivebuf1[1]!=Receivebuf[1]) //第二次接收不为0xff,0x00两个数据
{
sprintf((char*)dtbuf2,"%02X%02X",Receivebuf1[0],Receivebuf1[1]);
Show_Str(320,415,1000,12,dtbuf2,12,0);
i++;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>