51單片機中P2=0xfe時,P2^0管腳輸出讓led燈亮,延時后,P2=0xff時,燈不滅;
#include<reg52.h>
char tmp;
void delay(int time)
{
int x,j;
for(x=time;x>0;x--);
for(j=30000;j>0;j--);
}
void main()
{
tmp=0xfe;
P2=tmp;
delay(100);
tmp=0xff;
}
請問,這個應該要怎么調;這段代碼,是我寫流水燈的前部分,流水燈循環2次后,P2^0和P2^7的燈不會滅,循環流水燈代碼如下:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
char tmp;
void delay(int time)
{
int i,j;
for(i=time;i>0;i--);
for(j=30000;j>0;j--);
}
void main()
{
uchar t;
uchar p=2;
if(p>0)
{
while(p--)
{
t=tmp;
tmp=0x7f;
P2=tmp;
delay(500);
for(t=0;t<7;t++)
{
tmp=_cror_(tmp,1);
P2=tmp;
delay(500);
}
for(t=0;t<7;t++)
{
tmp=_crol_(tmp,1);
P2=tmp;
delay(500);
}
}
}
else
{
tmp=0xfe;
P2=tmp;
}
}
|