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

控制/MCU

1816人已加入

描述

  由于程序花样显示比较复杂,所以完全可以通过查表得方式编写程序,简单。如果想显示不同的花样,只需要改写表中的数据即可。流水灯程序:#include “reg51.h”

AT89C51单片机

  #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

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分