本文主要是介绍基于51单片机的花样心形型流水灯proteus仿真,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
硬件设计
(末尾附文件)
仿真图如下:
基于51单片机,多个LED组成的硬件电路
程序设计
#include<reg52.h>
#define uchar unsigned char
uchar flag=200;
///
uchar code Tab1[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xFF};//暗中左移 向下
uchar code Tab2[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};//暗中右移 向上
uchar code Tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00};//亮中左移 向下
uchar code Tab4[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};//亮中右移 向上
uchar code Tab11[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0xff};//暗中左移 向下
uchar code Tab22[]={0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0xff};uchar code Tab33[]={0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};
uchar code Tab44[]={0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
uchar code Tab55[]={0x08,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff};
uchar code Tab5[]={0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xff};
uchar code Tab6[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xff};
uchar code Tab7[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar code Tab8[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};void shansuo();
void xl();
///
void delay(void)
{unsigned char m,n;for(m=0;m<flag;m++)for(n=0;n<250;n++) ;}
///void hy1(void) //点亮状态逆时针旋转90度(一个一个灭)
{unsigned char i;for(i=0;i<8;i++) {P0=Tab11[i];P1=Tab22[i];P2=Tab11[i];P3=Tab22[i];delay();}for(i=0;i<8;i++) {P0=Tab44[i];P1=Tab55[i];P2=Tab44[i];P3=Tab55[i];delay();}
}
///void hy2(void) //暗中逆时针转360。(一个一个点亮)
{unsigned char i;for(flag=250;flag>0;flag=flag-50){P0=0xff;P1=0xff;P2=0xff;P3=0xff;for(i=0;i<8;i++) {P0=Tab11[i];delay();}for(i=0;i<8;i++) {P2=Tab11[i];delay();}for(i=0;i<8;i++) {P3=Tab22[i];delay();}for(i=0;i<8;i++) {P1=Tab22[i];delay();}}
flag=250;
}void hy3(void) //点亮中逆时针转360°(一个一个灭)
{unsigned char i;flag=50;P0=0x00;P1=0x00;P2=0x00;P3=0x00;for(i=0;i<8;i++) {P0=Tab44[i];delay();}for(i=0;i<8;i++) {P2=Tab44[i];delay();}for(i=0;i<8;i++) {P3=Tab33[i];delay();}for(i=0;i<8;i++) {P1=Tab33[i];delay();}flag=150;
}
///void hy4(void) //点亮状态顺时针旋转90度(一个一个灭)
{unsigned char i;for(i=0;i<8;i++) {P1=Tab11[i];P0=Tab22[i];P3=Tab11[i];P2=Tab22[i];delay();}for(i=0;i<9;i++) {P1=Tab6[i];P0=Tab5[i];P3=Tab6[i];P2=Tab5[i];delay();}
}
/void hy2_1(void) //暗中逆时针转90度。(一个一个点亮)
{unsigned char i;flag=200;P0=0xff;P1=0xff;P2=0xff;P3=0xff;for(i=0;i<9;i++) {P0=Tab11[i];delay();}flag=110;for(i=0;i<9;i++) {P2=Tab11[i];delay();}flag=80;for(i=0;i<9;i++) {P3=Tab22[i];delay();}flag=80;for(i=0;i<9;i++) {P1=Tab22[i];delay();}
}void hy2_2(void) //暗中逆时针转180度。(一个一个点亮)
{unsigned char i;P0=0xff;P1=0xff;P2=0xff;P3=0xff;for(i=0;i<8;i++) {P0=Tab11[i];delay();}for(i=0;i<8;i++) {P2=Tab11[i];delay();}P0=0xff;P2=0xff;for(i=0;i<8;i++) {P3=Tab22[i];delay();}for(i=0;i<8;i++) {P1=Tab22[i];delay();}P1=0xff;P3=0xff;
}
///void hy2_3(void) //暗中向下180。(一个一个点亮)
{unsigned char i;P0=0xff;P1=0xff;P2=0xff;P3=0xff;for(i=0;i<8;i++) {P0=Tab11[i];P1=Tab11[i];delay();}for(i=0;i<8;i++) {P2=Tab11[i];P3=Tab11[i];delay();}
///flag=100;for(i=0;i<8;i++) {P2=Tab33[i];P3=Tab33[i];delay();}for(i=0;i<8;i++) {P0=Tab33[i];P1=Tab33[i];delay();flag=200;}
}
///void hy2_4(void) //暗中逆时针转360。(一个一个点亮)
{unsigned char i;P0=0xff;P1=0xff;P2=0xff;P3=0xff;for(i=0;i<8;i++) {P0=Tab11[i];P3=Tab22[i];delay();}for(i=0;i<8;i++) {P2=Tab11[i];P1=Tab22[i];delay();}
///flag=100;
for(i=0;i<8;i++) {P0=Tab44[i];P3=Tab5[i];delay();}for(i=0;i<8;i++) {P2=Tab44[i];P1=Tab5[i];delay();}flag=200;
}
.
文件仅供参考:
链接:https://pan.baidu.com/s/14rN-I12wxD0tKT9pHYeoNQ
提取码:2l80
.
这篇关于基于51单片机的花样心形型流水灯proteus仿真的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!