STC89C51單片機(jī)流水燈程序
由于程序花樣顯示比較復(fù)雜,所以完全可以通過(guò)查表得方式編寫(xiě)程序,簡(jiǎn)單。如果想顯示不同的花樣,只需要改寫(xiě)表中的數(shù)據(jù)即可。流水燈程序:#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
const table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(uint z) //delay 1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}void main(void)
{
uchar x;
while(1)
{
for(x=0;x<8;x++)
{
P0=table[x];
delay(1000);
}
}
}花樣燈程序:#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
const table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //正向流水燈
0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff, //反向流水燈
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xff, //隔燈閃爍
0xf0,0x0f,0xf0,0x0f,0xff, //高四盞閃爍,低四盞閃爍
0x33,0xcc,0x33,0xcc,0x33,0xcc,0xff}; //隔兩盞閃爍
void delay(uint z) //delay 1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}void main(void)
{
uchar x;
while(1)
{
for(x=0;x<35;x++)
{
P0=table[x];
delay(1000);
}
}
}