快捷搜索:

AT89C51单片机的流水灯控制设计

因为法度榜样花样显示对照繁杂,以是完全可以经由过程查表得要领编写法度榜样,简单。假如想显示不合的花样,只必要改写表中的数据即可。流水灯法度榜样:#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);

}

}

}

滥觞;21ic

您可能还会对下面的文章感兴趣: