52单片机 4*4*4光立方程序竖共阳层共阴 uln2803 573锁存,跪求程序 50
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏50(财富值+成长值)
1个回答
展开全部
/*******4*4*4的光立方,层共阴(P0^0~P0^3),列共阳(P1和P2口)*******/
#include<stdio.h>
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
/*****************************延时函数******************************/
void Delay(uint del)
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<4000; j++);
}
void Delay1(unsigned int t)
{
while(--t);
}
/***************群体闪烁********************/
void flash_1() //全部
{
uchar i;
for(i=0;i<3;i++)
{
P0=0X00;
P1=0Xff;
P2=0Xff;
Delay(20);
P1=0X00;
P2=0X00;
Delay(20);
}
}
void flash_2() //粒闪
{
uchar i,m,n;
for(i=0;i<12;i++)
{
for(m=0;m<3;m++)
{
P0=0x05;
P1=0xaa;
P2=0xaa;
Delay(1);
P0=0x0a;
P1=0x55;
P2=0x55;
Delay(1);
}
for(n=0;n<3;n++)
{
P0=0x05;
P1=0x55;
P2=0x55;
Delay(1);
P0=0x0a;
P1=0xaa;
P2=0xaa;
Delay(1);
}
}
}
void flash_3() //框+立体米
{
uchar i,m,n;
for(i=0;i<7;i++)
{
for(m=0;m<3;m++)
{
P0=0x00;
P1=0x09;
P2=0x90;
Delay(1);
P0=0x06;
P1=0x9f;
P2=0xf9;
Delay(1);
}
for(n=0;n<3;n++)
{
P0=0x06;
P1=0x60;
P2=0x06;
Delay(1);
P0=0x09;
P1=0xf6;
P2=0x6f;
Delay(1);
}
}
}
void flash_4(uchar i,uchar j,uchar k) //柱体‘回’闪
{
P0=0x00;
P1=0x60;
P2=0x06;
Delay(i);
P1=0x9f;
P2=0xf9;
Delay(i);
P1=0x60;
P2=0x06;
Delay(j);
P1=0x9f;
P2=0xf9;
Delay(j);
P1=0x60;
P2=0x06;
Delay(k);
P1=0x9f;
P2=0xf9;
Delay(k);
}
void flash_5() //十字闪
{
uchar m,n;
P0=0x00;
for(m=0;m<3;m++)
{
P1=0x60;
P2=0x06;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
}
for(n=0;n<3;n++)
{
P1=0x66;
P2=0x66;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
P1=0xf0;
P2=0x0f;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
}
}
/*********************************列断续扫描**************************/
void line_1(uchar i,uchar j,uchar k) //单列亮
{
P0=0X00;
P1=0X1;
P2=0X00;
Delay(i);/*1*/
P1=0X2;
P2=0X00;
Delay(i);/*2*/
P1=0X4;
P2=0X00;
Delay(i);/*3*/
P1=0X8;
P2=0X00;
Delay(i);/*4*/
P1=0X10;
P2=0X00;
Delay(j);/*5*/
P1=0X00;
P2=0X8;
Delay(j);/*12*/
P1=0X00;
P2=0X10;
Delay(j);/*13*/
P1=0X00;
P2=0X20;
Delay(j);/*14*/
P1=0X00;
P2=0X40;
Delay(k);/*15*/
P1=0X00;
P2=0X80;
Delay(k);/*16*/
P1=0X00;
P2=0X1;
Delay(k);/*9*/
P1=0X80;
P2=0X00;
Delay(k);/*8*/
}
void line_2(uchar i,uchar j,uchar k) //逐渐列全亮
{
// P0=0X00;
P1=0X1;
P2=0X00;
Delay(i);/*1*/
P1=0X3;
P2=0X00;
Delay(i);/*2*/
P1=0X7;
P2=0X00;
Delay(i);/*3*/
P1=0X0f;
P2=0X00;
Delay(i);/*4*/
P1=0X1f;
P2=0X00;
Delay(j);/*5*/
P1=0X1f;
P2=0X8;
Delay(j);/*12*/
P1=0X1f;
P2=0X18;
Delay(j);/*13*/
P1=0X1f;
P2=0X38;
Delay(j);/*14*/
P1=0X1f;
P2=0X78;
Delay(k);/*15*/
P1=0X1f;
P2=0Xf8;
Delay(k);/*16*/
P1=0X1f;
P2=0Xf9;
Delay(k);/*9*/
P1=0X9f;
P2=0Xf9;
Delay(k);/*8*/
}
void line_3(uchar n,uchar j,uchar k) //双列绕心转
{
uchar i;
for(i=0;i<3;i++)
{
P0=0x00;
P1=0x41;
P2=0x14;
Delay(n);
P1=0x42;
P2=0x24;
Delay(n);
P1=0x24;
P2=0x42;
Delay(j);
P1=0x28;
P2=0x82;
Delay(j);
P1=0x30;
P2=0x03;
Delay(k);
P1=0xc0;
P2=0x0c;
Delay(k);
}
}
/****************************************平面扫描*************************************/
void plan_1(uchar i) //列面扫描
{
P0=0x00;
P1=0XF;
P2=0X00;
Delay(i);/*1*/
P1=0XF0;
P2=0X00;
Delay(i);/*2*/
P1=0X00;
P2=0XF;
Delay(i);/*3*/
P1=0X00;
P2=0XF0;
Delay(i);/*4*/
P1=0X00;
P2=0XF;
Delay(i);/*3*/
P1=0XF0;
P2=0X00;
Delay(i);/*2*/
P1=0XF;
P2=0X00;
Delay(i);/*1*/
}
void plan_2(uchar i) // 层面扫描
{
P0=0XFE;
P1=0XFF;
P2=0XFF;
Delay(i);/*第1层(从下到上)*/
P0=0XFD;
P1=0XFF;
P2=0XFF;
Delay(i);/*第2层(从下到上)*/
P0=0XFB;
P1=0XFF;
P2=0XFF;
Delay(i);/*第3层(从下到上)*/
P0=0XF7;
P1=0XFF;
P2=0XFF;
Delay(i);/*第4层(从下到上)*/
P0=0XFB;
P1=0XFF;
P2=0XFF;
Delay(i);/*第3层(从下到上)*/
P0=0XFD;
P1=0XFF;
P2=0XFF;
Delay(i);/*第2层(从下到上)*/
P0=0XFE;
P1=0XFF;
P2=0XFF;
Delay(i);/*第1层(从下到上)*/
}
/*****************逐点走*****************/
void point()
{
P0=0x0e;
line_2(8,8,8);
P0=0x0c;
line_2(7,7,7);
P0=0x08;
line_2(6,6,6);
P0=0x00;
line_2(5,5,5);
P0=0x08;
line_2(4,4,4);
P0=0x0c;
line_2(2,2,2);
P0=0x0e;
line_2(1,1,1);
}
/*****************正方形放大缩小*********************/
void cube_1() //中心到全部
{
uchar i;
for(i=0;i<3;i++)
{
P0=0x09;
P1=0x60;
P2=0x06;
Delay(20);
P0=0x0f;
Delay(3);
P0=0x00;
P1=0xff;
P2=0xff;
Delay(10);
}
}
void cube_2(uchar i) //单旋
{
P0=0x00;
P1=0xc3;
P2=0x00;
Delay(i);
P1=0x66;
P2=0x00;
Delay(i);
P1=0x3c;
P2=0x00;
Delay(i);
P1=0x30;
P2=0x0c;
Delay(i);
P1=0x00;
P2=0x3c;
Delay(i);
P1=0x00;
P2=0x66;
Delay(i);
P1=0x00;
P2=0xc3;
Delay(i);
P1=0xc0;
P2=0x03;
Delay(i);
}
void cube_3(uchar i) //四旋
{
P0=0x00;
P1=0x60;
P2=0x06;
Delay(i);
P1=0xe7;
P2=0x07;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0xe0;
P2=0xe7;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0x70;
P2=0x7e;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0x7e;
P2=0x0e;
Delay(i);
}
/****************面变成体******************/
void plan_cube()
{
P0=0x00;
P1=0x41;
P2=0x14;
Delay(20);
P1=0x28;
P2=0x82;
Delay(20);
P1=0x0f;
P2=0x00;
Delay(20);
P1=0x18;
P2=0x18;
Delay(20);
P1=0x00;
P2=0xf0;
Delay(20);
P1=0x81;
P2=0x81;
Delay(20);
P1=0x00;
P2=0x00;
Delay(20);
P1=0x41;
P2=0x14;
Delay(20);
P1=0x69;
P2=0x96;
Delay(20);
P1=0x6f;
P2=0x96;
Delay(20);
P1=0x7f;
P2=0x9e;
Delay(20);
P1=0x7f;
P2=0xfe;
Delay(20);
P1=0xff;
P2=0xff;
Delay(20);
}
/*******************************主函数*****************************/
main()
{
uint CYCLE=600,PWM_LOW=0;//定义周期并赋值
flash_1();
flash_2();
line_1(10,9,8);
line_1(6,5,4);
line_1(3,2,1);
line_1(1,1,1);
line_2(8,6,4);
line_1(1,1,1);
line_2(8,6,4);
flash_2();
line_3(10,8,6);
line_3(5,4,3);
line_3(3,2,1);
cube_1();
plan_1(10);
plan_2(10);
plan_1(8);
plan_2(8);
flash_4(8,8,8);
line_3(5,5,5);
line_3(4,4,4);
flash_2();
flash_3();
flash_3();
cube_2(8);
cube_2(7);
cube_2(6);
cube_2(5);
cube_2(4);
cube_2(4);
cube_2(3);
cube_2(3);
cube_2(2);
cube_2(2);
cube_2(2);
cube_2(1);
cube_2(1);
cube_2(1);
cube_1();
flash_5();
plan_2(7);
plan_1(7);
line_3(10,8,6);
line_3(5,4,3);
line_3(3,2,1);
flash_4(15,14,13);
flash_4(12,11,10);
flash_4(9,8,7);
flash_4(6,5,4);
cube_1();
cube_2(15);
cube_2(12);
cube_2(10);
cube_2(8);
cube_2(8);
cube_2(8);
flash_4(8,8,8);
line_2(8,8,8);
line_1(5,5,5);
line_2(2,2,2);
point();
plan_cube();
cube_3(15);
cube_3(12);
cube_3(10);
cube_3(8);
cube_3(8);
cube_3(8);
flash_3();
flash_3();
point();
flash_4(10,10,10);
point();
flash_2();
plan_cube();
P0=0x00;
while (1) //主循环
{
P1=0x00;
P2=0x00;
Delay1(10000); //特意加延时,可以看到熄灭的过程
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++){//PWM_LOW表示低
//电平时间,这个循环中低电平时长从1累加到CYCLE(周期)的值,即600次
P1=0xff;
P2=0xff; //点亮LED
Delay1(PWM_LOW);//延时长度,600次循环中从1加至599
P1=0x00;
P2=0x00; //熄灭LED
Delay1(CYCLE-PWM_LOW);//延时长度,600次循环中从599减至1
}
P1=0xff;
P2=0xff;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--){//与逐渐变亮相反的过程
P1=0xff;
P2=0xff;
Delay1(PWM_LOW);
P1=0x00;
P2=0x00;
Delay1(CYCLE-PWM_LOW);
}
}
}
#include<stdio.h>
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
/*****************************延时函数******************************/
void Delay(uint del)
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<4000; j++);
}
void Delay1(unsigned int t)
{
while(--t);
}
/***************群体闪烁********************/
void flash_1() //全部
{
uchar i;
for(i=0;i<3;i++)
{
P0=0X00;
P1=0Xff;
P2=0Xff;
Delay(20);
P1=0X00;
P2=0X00;
Delay(20);
}
}
void flash_2() //粒闪
{
uchar i,m,n;
for(i=0;i<12;i++)
{
for(m=0;m<3;m++)
{
P0=0x05;
P1=0xaa;
P2=0xaa;
Delay(1);
P0=0x0a;
P1=0x55;
P2=0x55;
Delay(1);
}
for(n=0;n<3;n++)
{
P0=0x05;
P1=0x55;
P2=0x55;
Delay(1);
P0=0x0a;
P1=0xaa;
P2=0xaa;
Delay(1);
}
}
}
void flash_3() //框+立体米
{
uchar i,m,n;
for(i=0;i<7;i++)
{
for(m=0;m<3;m++)
{
P0=0x00;
P1=0x09;
P2=0x90;
Delay(1);
P0=0x06;
P1=0x9f;
P2=0xf9;
Delay(1);
}
for(n=0;n<3;n++)
{
P0=0x06;
P1=0x60;
P2=0x06;
Delay(1);
P0=0x09;
P1=0xf6;
P2=0x6f;
Delay(1);
}
}
}
void flash_4(uchar i,uchar j,uchar k) //柱体‘回’闪
{
P0=0x00;
P1=0x60;
P2=0x06;
Delay(i);
P1=0x9f;
P2=0xf9;
Delay(i);
P1=0x60;
P2=0x06;
Delay(j);
P1=0x9f;
P2=0xf9;
Delay(j);
P1=0x60;
P2=0x06;
Delay(k);
P1=0x9f;
P2=0xf9;
Delay(k);
}
void flash_5() //十字闪
{
uchar m,n;
P0=0x00;
for(m=0;m<3;m++)
{
P1=0x60;
P2=0x06;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
}
for(n=0;n<3;n++)
{
P1=0x66;
P2=0x66;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
P1=0xf0;
P2=0x0f;
Delay(10);
P1=0x00;
P2=0x00;
Delay(10);
}
}
/*********************************列断续扫描**************************/
void line_1(uchar i,uchar j,uchar k) //单列亮
{
P0=0X00;
P1=0X1;
P2=0X00;
Delay(i);/*1*/
P1=0X2;
P2=0X00;
Delay(i);/*2*/
P1=0X4;
P2=0X00;
Delay(i);/*3*/
P1=0X8;
P2=0X00;
Delay(i);/*4*/
P1=0X10;
P2=0X00;
Delay(j);/*5*/
P1=0X00;
P2=0X8;
Delay(j);/*12*/
P1=0X00;
P2=0X10;
Delay(j);/*13*/
P1=0X00;
P2=0X20;
Delay(j);/*14*/
P1=0X00;
P2=0X40;
Delay(k);/*15*/
P1=0X00;
P2=0X80;
Delay(k);/*16*/
P1=0X00;
P2=0X1;
Delay(k);/*9*/
P1=0X80;
P2=0X00;
Delay(k);/*8*/
}
void line_2(uchar i,uchar j,uchar k) //逐渐列全亮
{
// P0=0X00;
P1=0X1;
P2=0X00;
Delay(i);/*1*/
P1=0X3;
P2=0X00;
Delay(i);/*2*/
P1=0X7;
P2=0X00;
Delay(i);/*3*/
P1=0X0f;
P2=0X00;
Delay(i);/*4*/
P1=0X1f;
P2=0X00;
Delay(j);/*5*/
P1=0X1f;
P2=0X8;
Delay(j);/*12*/
P1=0X1f;
P2=0X18;
Delay(j);/*13*/
P1=0X1f;
P2=0X38;
Delay(j);/*14*/
P1=0X1f;
P2=0X78;
Delay(k);/*15*/
P1=0X1f;
P2=0Xf8;
Delay(k);/*16*/
P1=0X1f;
P2=0Xf9;
Delay(k);/*9*/
P1=0X9f;
P2=0Xf9;
Delay(k);/*8*/
}
void line_3(uchar n,uchar j,uchar k) //双列绕心转
{
uchar i;
for(i=0;i<3;i++)
{
P0=0x00;
P1=0x41;
P2=0x14;
Delay(n);
P1=0x42;
P2=0x24;
Delay(n);
P1=0x24;
P2=0x42;
Delay(j);
P1=0x28;
P2=0x82;
Delay(j);
P1=0x30;
P2=0x03;
Delay(k);
P1=0xc0;
P2=0x0c;
Delay(k);
}
}
/****************************************平面扫描*************************************/
void plan_1(uchar i) //列面扫描
{
P0=0x00;
P1=0XF;
P2=0X00;
Delay(i);/*1*/
P1=0XF0;
P2=0X00;
Delay(i);/*2*/
P1=0X00;
P2=0XF;
Delay(i);/*3*/
P1=0X00;
P2=0XF0;
Delay(i);/*4*/
P1=0X00;
P2=0XF;
Delay(i);/*3*/
P1=0XF0;
P2=0X00;
Delay(i);/*2*/
P1=0XF;
P2=0X00;
Delay(i);/*1*/
}
void plan_2(uchar i) // 层面扫描
{
P0=0XFE;
P1=0XFF;
P2=0XFF;
Delay(i);/*第1层(从下到上)*/
P0=0XFD;
P1=0XFF;
P2=0XFF;
Delay(i);/*第2层(从下到上)*/
P0=0XFB;
P1=0XFF;
P2=0XFF;
Delay(i);/*第3层(从下到上)*/
P0=0XF7;
P1=0XFF;
P2=0XFF;
Delay(i);/*第4层(从下到上)*/
P0=0XFB;
P1=0XFF;
P2=0XFF;
Delay(i);/*第3层(从下到上)*/
P0=0XFD;
P1=0XFF;
P2=0XFF;
Delay(i);/*第2层(从下到上)*/
P0=0XFE;
P1=0XFF;
P2=0XFF;
Delay(i);/*第1层(从下到上)*/
}
/*****************逐点走*****************/
void point()
{
P0=0x0e;
line_2(8,8,8);
P0=0x0c;
line_2(7,7,7);
P0=0x08;
line_2(6,6,6);
P0=0x00;
line_2(5,5,5);
P0=0x08;
line_2(4,4,4);
P0=0x0c;
line_2(2,2,2);
P0=0x0e;
line_2(1,1,1);
}
/*****************正方形放大缩小*********************/
void cube_1() //中心到全部
{
uchar i;
for(i=0;i<3;i++)
{
P0=0x09;
P1=0x60;
P2=0x06;
Delay(20);
P0=0x0f;
Delay(3);
P0=0x00;
P1=0xff;
P2=0xff;
Delay(10);
}
}
void cube_2(uchar i) //单旋
{
P0=0x00;
P1=0xc3;
P2=0x00;
Delay(i);
P1=0x66;
P2=0x00;
Delay(i);
P1=0x3c;
P2=0x00;
Delay(i);
P1=0x30;
P2=0x0c;
Delay(i);
P1=0x00;
P2=0x3c;
Delay(i);
P1=0x00;
P2=0x66;
Delay(i);
P1=0x00;
P2=0xc3;
Delay(i);
P1=0xc0;
P2=0x03;
Delay(i);
}
void cube_3(uchar i) //四旋
{
P0=0x00;
P1=0x60;
P2=0x06;
Delay(i);
P1=0xe7;
P2=0x07;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0xe0;
P2=0xe7;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0x70;
P2=0x7e;
Delay(i);
P1=0x60;
P2=0x06;
Delay(i);
P1=0x7e;
P2=0x0e;
Delay(i);
}
/****************面变成体******************/
void plan_cube()
{
P0=0x00;
P1=0x41;
P2=0x14;
Delay(20);
P1=0x28;
P2=0x82;
Delay(20);
P1=0x0f;
P2=0x00;
Delay(20);
P1=0x18;
P2=0x18;
Delay(20);
P1=0x00;
P2=0xf0;
Delay(20);
P1=0x81;
P2=0x81;
Delay(20);
P1=0x00;
P2=0x00;
Delay(20);
P1=0x41;
P2=0x14;
Delay(20);
P1=0x69;
P2=0x96;
Delay(20);
P1=0x6f;
P2=0x96;
Delay(20);
P1=0x7f;
P2=0x9e;
Delay(20);
P1=0x7f;
P2=0xfe;
Delay(20);
P1=0xff;
P2=0xff;
Delay(20);
}
/*******************************主函数*****************************/
main()
{
uint CYCLE=600,PWM_LOW=0;//定义周期并赋值
flash_1();
flash_2();
line_1(10,9,8);
line_1(6,5,4);
line_1(3,2,1);
line_1(1,1,1);
line_2(8,6,4);
line_1(1,1,1);
line_2(8,6,4);
flash_2();
line_3(10,8,6);
line_3(5,4,3);
line_3(3,2,1);
cube_1();
plan_1(10);
plan_2(10);
plan_1(8);
plan_2(8);
flash_4(8,8,8);
line_3(5,5,5);
line_3(4,4,4);
flash_2();
flash_3();
flash_3();
cube_2(8);
cube_2(7);
cube_2(6);
cube_2(5);
cube_2(4);
cube_2(4);
cube_2(3);
cube_2(3);
cube_2(2);
cube_2(2);
cube_2(2);
cube_2(1);
cube_2(1);
cube_2(1);
cube_1();
flash_5();
plan_2(7);
plan_1(7);
line_3(10,8,6);
line_3(5,4,3);
line_3(3,2,1);
flash_4(15,14,13);
flash_4(12,11,10);
flash_4(9,8,7);
flash_4(6,5,4);
cube_1();
cube_2(15);
cube_2(12);
cube_2(10);
cube_2(8);
cube_2(8);
cube_2(8);
flash_4(8,8,8);
line_2(8,8,8);
line_1(5,5,5);
line_2(2,2,2);
point();
plan_cube();
cube_3(15);
cube_3(12);
cube_3(10);
cube_3(8);
cube_3(8);
cube_3(8);
flash_3();
flash_3();
point();
flash_4(10,10,10);
point();
flash_2();
plan_cube();
P0=0x00;
while (1) //主循环
{
P1=0x00;
P2=0x00;
Delay1(10000); //特意加延时,可以看到熄灭的过程
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++){//PWM_LOW表示低
//电平时间,这个循环中低电平时长从1累加到CYCLE(周期)的值,即600次
P1=0xff;
P2=0xff; //点亮LED
Delay1(PWM_LOW);//延时长度,600次循环中从1加至599
P1=0x00;
P2=0x00; //熄灭LED
Delay1(CYCLE-PWM_LOW);//延时长度,600次循环中从599减至1
}
P1=0xff;
P2=0xff;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--){//与逐渐变亮相反的过程
P1=0xff;
P2=0xff;
Delay1(PWM_LOW);
P1=0x00;
P2=0x00;
Delay1(CYCLE-PWM_LOW);
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询