程序如下,我希望把这个流水灯程序改成在P1 P2 P3三个IO口同步同时带三组LED,但是我怎么改都不行,不是P1亮完再P2再P3,要不就是根本不亮……
两年多没玩单片机了,基本上忘得差不多了,最近准备重操旧业,望高手指教,谢谢!
#include<reg52.h> //52系列单片机头文件
void delay_1s() //子函数
{
unsigned int i,j; //定义无字符型自变量i,j
for(i=1000;i>0;i--) //晶振12M
for(j=8;j>0;j--); //延时函数
}
#define unchar unsigned char //宏定义
unchar num; //定义无字符型自变量num
unchar code table[]={ //声明数组
0x7F,0x3F,0x1F,0xF,
0x7,0x3,0x1,0x0,0x80,
0xC0,0xE0,0xF0,0xF8,
0xFC,0xFE,0xFF,0xFE,
0xFC,0xF8,0xF0,0xE0,
0xC0,0x80,0x0,0x1,
0x3,0x7,0xF,0x1F,
0x3F,0x7F,0xFF,0x7E,
0x3C,0x18,0x0,0x81,
0xC3,0xE7,0xFF,0xE7,
0xC3,0x81,0x81,0x0,
0x18,0x3C,0x7E,0xFE,
0xFD,0xFB,0xF7,0xEF,
0xDF,0xBF,0x7F,0x7E,
0x7D,0x77,0x6F,0x5F,
0x3F,0x3E,0x3D,0x3B,
0x37,0x2F,0x1F,0x1E,
0x1D,0x1B,0x17,0xF,
0xE,0xD,0xB,0x7,0x6,
0x5,0x3,0x2,0x1,0x0,
0x0,0x0,0x0,0xFF,0xFF,
0xAA,0xAA,0xAA,0xAA,
0x55,0x55,0x55,0x55,
0xAA,0xAA,0xAA,0xAA,
0x55,0x55,0x55,0x55,};
void main() //主函数
{
while(1) //大循环
{
for(num=0;num<105;num++) //数组循环
{
P3=table[num]; //调用数组
delay_1s(); //调用子函数
}
}
}
更多回帖