大神帮我看看这个彩灯的程序为什么不行啊
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={
0xff,0xe7,0xc3,0x81,0x00, //从中间向两侧点亮
0xff,0xe7,0xc3,0x81,0x00,
0xff,0x7e,0x3c,0x18,0x00, //从两侧向中间点亮
0xff,0x7e,0x3c,0x18,0x00,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //循环左移
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, //循环右移
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
0x01
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void main()
{
uint i;
while(1)
{
if(table!=0x01)
{
P1=table[1];
i++;
delay(1000);
}
else
{
i=0;
}
}
}
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={
0xff,0xe7,0xc3,0x81,0x00, //从中间向两侧点亮
0xff,0xe7,0xc3,0x81,0x00,
0xff,0x7e,0x3c,0x18,0x00, //从两侧向中间点亮
0xff,0x7e,0x3c,0x18,0x00,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //循环左移
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, //循环右移
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
0x01
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void main()
{
uint i;
while(1)
{
if(table!=0x01)
{
P1=table[1];
i++;
delay(1000);
}
else
{
i=0;
}
}
}
把 i 设置为全局变量或者静态变量。
P1=table[1];
这个地方应该是要写P1=table【i】;的吧
楼上正解,程序有笔误
正解啊。谢谢哥们哈。是我自己没检查到这个错误。
3Q。
注意细节
3Q
彩灯 相关文章: