1
控制/MCU
1、首先先在proteus画出仿真图,方便仿真程序
2、下面来编写程序,先来写入头函数
3、根据自己在proteus画的图,定义一下管脚根据你的原理图进行编写
sbit p0=P1^0;
sbit p1=P1^1;
sbit p2=P1^2;
sbit p3=P1^3;
sbit p4=P1^4;
sbit p5=P1^5;
sbit p6=P1^6;
sbit p7=P1^7;
4、然后写一个延时函数,来调节流水灯的时间间隔延时时间自己定义
void mdelay(unsigned int t)
{
unsigned char n;
for(;t》0;t--)
for(n=0;n《125;n++)
{;}
}
5、下面就是主函数,包括流水灯的反复循环和j流水灯的方向
6、检查没有错误,编译一下。就可以进行仿真了
原理图
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;
}
全部0条评论
快来发表一下你的评论吧 !