各位大虾,这些if判断有没有错?
时间:10-02
整理:3721RD
点击:
Data=0x00fa;//调试用
if(Data<0x000a) PWM=0;
else if(Data>0x01f4) PWM=100;
else
{
if(PWM_code[0]<Data<=PWM_code[1]) PWM=1;
else if(Data<=PWM_code[2]) PWM=2;
else if(Data<=PWM_code[3]) PWM=3;
else if(Data<=PWM_code[4]) PWM=4;
else if(Data<=PWM_code[5]) PWM=5;
else if(Data<=PWM_code[6]) PWM=6;
else if(Data<=PWM_code[7]) PWM=7;
else if(Data<=PWM_code[8]) PWM=8;
else if(Data<=PWM_code[9]) PWM=9;
为什么不管我赋data值不论多少都会被 if(PWM_code[0]<Data<=PWM_code[1]) PWM=1;判断成功,置PWM为1?
if(Data<0x000a) PWM=0;
else if(Data>0x01f4) PWM=100;
else
{
if(PWM_code[0]<Data<=PWM_code[1]) PWM=1;
else if(Data<=PWM_code[2]) PWM=2;
else if(Data<=PWM_code[3]) PWM=3;
else if(Data<=PWM_code[4]) PWM=4;
else if(Data<=PWM_code[5]) PWM=5;
else if(Data<=PWM_code[6]) PWM=6;
else if(Data<=PWM_code[7]) PWM=7;
else if(Data<=PWM_code[8]) PWM=8;
else if(Data<=PWM_code[9]) PWM=9;
为什么不管我赋data值不论多少都会被 if(PWM_code[0]<Data<=PWM_code[1]) PWM=1;判断成功,置PWM为1?
把这 if(PWM_code[0]<Data<=PWM_code[1]) 改成if(PWM_code[0]<Data||Data<=PWM_code[1])试试
谢谢,改了之后好了。
怎么感觉应该是这样 if(PWM_code[0]<Data && Data<=PWM_code[1])。才对呢。这个||表示的是或的意思~
if(PWM_code[0]<Data<=PWM_code[1]) PWM=1;这句就错啦,改为
if(PWM_code[0]&Data<=PWM_code[1]) PWM=1;吧