欢迎光临散文网 会员登陆 & 注册

51单片机100例实例之04例

2021-01-19 18:50 作者:技术流阿宅  | 我要投稿


proteus仿真图

//项目4:花样流水灯

//项目再创作者:科技小宅神

//说明:16只LED分两组按预设的多种花样变换显示   


#include <reg51.h>

#define uchar unsigned char

#define uint unsigned int


//各式花样,可自行安排(采用字模提取软件较为方便,可自行百度或进群领取软件)

uchar code Pattern_P0[]={

0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,//(第1个图形)

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//熄灭(长)

0xef,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,//(第2个图形)

0xff,//熄灭

0xf8,//(第3个图形)

0xe7,0xc3,0x81,0x00,0xc3,0xe7,//(第4个图形)

0xff,//熄灭

0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,

0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,0x7f,0x3f,0x1f,0x8f,

0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff, 

0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,  

0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,  

0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff 

}; 

uchar code Pattern_P2[]= {

  0xff,0xff,0xff,0xff,0xff,0xff,0xff,

  0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,  

  0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,

  0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,  

  0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,

  0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,  

  0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,

 0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff,

  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

  0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,  

  0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  

  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

  0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,  

  0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,

  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  

  0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff 

};

//1毫秒延时子程序

void DelayMS(uint x)

{

  uchar t;

 while(x--)

 {

   for(t=120;t>0;t--);

 }

}

//主程序

void main()

{

  uchar i;//定义一个局部变量i

 while(1)//死循环

 {    

  //从数组中读取数据送到P0和P2显示

   for(i=136;i>0;i--)//自减执行136次

  {

    P0=Pattern_P0[i];

   P2=Pattern_P2[i];

   DelayMS(100);//此处可调整灯点亮的时间即速度

  } 

 }

}

51单片机100例实例之04例的评论 (共 条)

分享到微博请遵守国家法律