本帖最后由 芯圣电子官方QQ 于 2023-7-25 10:31 编辑
void sugpriority(unsigned int sug)
{
unsigned char pwm0a = 0;
unsigned char pwm0b = 0;
unsigned char pwm1a = 0;
unsigned char pwm1b = 0;
unsigned char pwm2a = 0;
unsigned char pwm2b = 0;
unsigned int i=0;
angle_addpriority[0]=0;
angle_addpriority[1]=0;
angle_addpriority[2]=0;
angle_addpriority[3]=0;
angle_addpriority[4]=0;
angle_addpriority[5]=0;
angle_addpriority[6]=0;
angle_addpriority[7]=0;
angle_addpriority[8]=0;
angle_addpriority[9]=0;
angle_addpriority[10]=0;
angle_addpriority[11]=0;
angle_addpriority[12]=0;
angle_addpriority[13]=0;
angle_addpriority[14]=0;
angle_addpriority[15]=0;
i=sug;
if (1==(i>>15)&0x01)
{
pwm0a += 1;
angle_addpriority[0] += pwm0a;
}
i=sug;
if (1==(i>>9)&0x01)
{
pwm0a += 1;
angle_addpriority[6] += pwm0a;
}
i=sug;
if (1==(i>>3)&0x01)
{
pwm0a += 1;
angle_addpriority[12] += pwm0a;
}
i=sug;
if (1==(i>>14)&0x01)
{
pwm0b += 1;
angle_addpriority[1] += pwm0b;
}
i=sug;
if (1==(i>>8)&0x01)
{
pwm0b += 1;
angle_addpriority[7] += pwm0b;
}
i=sug;
if (1==(i>>2)&0x01)
{
pwm0b += 1;
angle_addpriority[13] += pwm0b;
}
i=sug;
if (1==(i>>13)&0x01)
{
pwm1a += 1;
angle_addpriority[2] += pwm1a;
}
i=sug;
if (1==(i>>7)&0x01)
{
pwm1a += 1;
angle_addpriority[8] += pwm1a;
}
i=sug;
if (1==(i>>1)&0x01)
{
pwm1a += 1;
angle_addpriority[14] = pwm1a;
}
i=sug;
if (1==(i>>12)&0x01)
{
pwm1b += 1;
angle_addpriority[3] = pwm1b;
}
i=sug;
if (1==(i>>6)&0x01)
{
pwm1b += 1;
angle_addpriority[9] += pwm1b;
}
i=sug;
if (1==(i>>0)&0x01)
{
pwm1b += 1;
angle_addpriority[15] += pwm1b;
}
i=sug;
if (1==(i>>11)&0x01)
{
pwm2a += 1;
angle_addpriority[4] += pwm2a;
}
i=sug;
if (1==(i>>5)&0x01)
{
pwm2a += 1;
angle_addpriority[10] += pwm2a;
}
i=sug;
if (1==(i>>10)&0x01)
{
pwm2b += 1;
angle_addpriority[5] += pwm2b;
}
i=sug;
if (1==(i>>4)&0x01)
{
pwm2b += 1;
angle_addpriority[11] += pwm2b;
}
}
我在使用这块mcu时发现我写的位运算全都不能正确运行,就比如上面的函数,如果传入的sug=0xffff;按照执行逻辑顺序,应该每一个if判断语句都会进入执行其中的内容,然而现实情况是,在处理了第一个if判断后就将sug的值变成了0x0001,这里显然出了很大的错误,我是将sug赋值给i后对i处理,每一次if判断后都对i重新赋值,按理说sug应该一直不变才对,每次对i赋值后i都应该是0xffff,!!然而不对啊,后面的if全都判断为非跳过了。
@
|