Proteus仿真问题
时间:10-02
整理:3721RD
点击:
想实现:LED自上而下依次点亮熄灭,然后自下而上依次点亮熄灭,而后齐亮齐灭,
现在问题是:
程序如下:依次点亮熄灭可以,但是不能齐亮齐灭
#include<reg52.h>
#include<intrins.h>
unsigned char LED;
sbit spk=P2^0;
void yanshi(unsigned int);
void main()
{
LED=0xfe;
P0=LED;
while(1)
{
unsigned int a;
for(a=0;a<7;a++)
{
LED=_crol_(LED,1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=7;a>0;a--)
{
LED=_crol_(LED,-1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=0;a<4;a++)
{
LED=0x00;
spk=0;
yanshi(50);
LED=0xff;
spk=1;
yanshi(50);
}
}
}
void yanshi(unsigned int z)
{
unsigned int x,y;
for(x=0;x<z;x++)
for(y=1000;y>0;--y);
}
仿真电路如下
现在问题是:
程序如下:依次点亮熄灭可以,但是不能齐亮齐灭
#include<reg52.h>
#include<intrins.h>
unsigned char LED;
sbit spk=P2^0;
void yanshi(unsigned int);
void main()
{
LED=0xfe;
P0=LED;
while(1)
{
unsigned int a;
for(a=0;a<7;a++)
{
LED=_crol_(LED,1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=7;a>0;a--)
{
LED=_crol_(LED,-1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=0;a<4;a++)
{
LED=0x00;
spk=0;
yanshi(50);
LED=0xff;
spk=1;
yanshi(50);
}
}
}
void yanshi(unsigned int z)
{
unsigned int x,y;
for(x=0;x<z;x++)
for(y=1000;y>0;--y);
}
仿真电路如下
新手,刚学习单片机,没有老师,求各位大神指导
后面的那个P0没有赋值。而是用了LED代替、
谢谢,终于找到原因了,已经成功,谢谢