为什么说没有定义temp,i

img


#include<reg51.h>
sbit L0=P1^0;
sbit L1=P1^1;
sbit L2=P1^2;
sbit L3=P1^3;
unsigned char s[] = {0x3f,0x06,0x5b,0x4f,
                     0x66,0x6d,0x7d,0x07,
                       0x7f,0x6f,0x77,0x7c,
                       0x39,0x5e,0x79,0x71};
void delay(unsigned char i)
{
while(i--)
{
unsigned int t;
for(t=0;t<120;t++);
}
}
void main()
{      
      P1=0xef;
      unsigned char i=0,temp=0;
      while(1)
      {
           //P1=0xef; //1110 1111
          for(i=0;i<4;i++)
          {
              if(L0==0)
                  P2=s[i*4+0];
              if(L1==0)
                  P2=s[i*4+1];
              if(L2==0)
                  P2=s[i*4+2];
              if(L3==0)
                  P2=s[i*4+3];
              delay(5000);
              temp=P1;
              temp=temp|0x0f;
              temp=temp<<1;
              temp=temp|0x0f;
              P1=temp;
          }
      }
}

unsigned char i=0,temp=0;
P1=0xef;
语序换一下,比如先定义再进行赋值

语序不对。

img


你这样先执行赋值语句,再进行变量定义,在这里是不行的,因此没有识别出来赋值语句之后的定义语句。
语序换一下就可以了。

如有帮助,还请帮忙点下采纳!感谢!


void main()
{
      unsigned char i=0,temp=0;      //C51中变量定义必须在可执行语句前面
      P1=0xef;

放到数组下面,试试