
可编程LED摇棒,短小精悍,好玩有趣……
现将源程序公开,可以实现不对称符号显示的程序,不过还有修改空间,如果有达人不妨提出意见呵~
#include <reg51.h>
#define SEG 17 //每帧图片分成17列来显示
#define INTERVAL 20 //每幅图片在左右摇摆20次后换下一幅
typedef unsigned char uchar;
typedef unsigned int uint;
code char pattern[17][8]={ //4幅图片的字模(双模)
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xf9,0xf9,0xff,0xff},
{0x3f,0xff,0xff,0xff,0xf6,0xf6,0x9f,0x9f},
{0x7f,0xff,0xff,0xff,0xee,0xee,0xa6,0xa6},
{0x7f,0xff,0x7f,0x7f,0xdd,0xdd,0x78,0x78},
{0x7f,0xff,0x7e,0x7e,0xbb,0xbb,0x7f,0x7f},
{0x00,0x00,0x00,0x00,0x77,0x77,0x7f,0x7f},
{0x7f,0x7f,0x7e,0x7e,0xbb,0xbb,0x7f,0x7f},
{0xff,0x7f,0x7f,0x7f,0xdd,0xdd,0x78,0x78},
{0xff,0x7f,0xff,0xff,0xee,0xee,0xa6,0xa6},
{0xff,0x3f,0xff,0xff,0xf6,0xf6,0x9f,0x9f},
{0xff,0xff,0xff,0xff,0xf9,0xf9,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
};
uchar phase,th1,tl1,index,count,acount;
main()
{
EA=0;
EX0=1;
ET1=1;
PX0=1;
IT0=1;
TMOD=0x11;
index=0;
EA=1;
acount=0;
while(1)
{
}
}
void Int0_Handle(void) interrupt 0 using 2
{
uint t0_time;
TR0=0;
TR1=0;
TF1=0;
t0_time=TH0<<8|TL0;
TL0=0;
TH0=0;
TR0=1;
t0_time=65535-t0_time/SEG;
th1=t0_time/256;
TH1=th1;
tl1=t0_time % 256;
TL1=tl1;
acount++; //切换因子
acount%=2;
if (count<8*INTERVAL){ //4幅图片循环
count++;
}
else{
count=0;
}
index=(count/40)*2+acount; //左右字模切换
if (th1!=0xff || tl1!=0xff){ //如果摆动特别慢,定时器溢出就不显示
phase=0;
TR1=1;
}
else{
TR1=0;
}
}
void Timer1(void) interrupt 3 using 3
{
if (phase<SEG) //17段依次显示
{
P1=pattern[phase][index];
phase++;
TH1=th1;
TL1=tl1;
}
}