4X4X4光立方C程序(含制作方法和电路图)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{0x40,0xA0,0x24,0x10,0x00,0x02,0x10,0x00},
{0x40,0xA0,0x24,0x10,0x20,0x02,0x10,0x00},
{0x40,0xA0,0x24,0x10,0x20,0x22,0x10,0x00},
{0x40,0xA0,0x24,0x10,0x20,0x22,0x14,0x42},
126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150};
void delay(uint z)
{
uint x,y;
for(x=80;x>0;x--)
for(y=z;y>0;y--);
P2=tabP2[i];
P0=tabP0[j][i];
ys(10);
}
}
}
}
void randomlight() //随机亮完
{
unsigned char code tabP0[38][8]={
{0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x00,0x00,0x00,0x00,0x10,0x00},
19,20,21,22,23,24,25,26,27,
28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43,44,45,
46,47,48,49,50,51,52,53,54,
55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,
ET0=1; //允许定时器0中断
EA=1; //允许总中断
}
void alllighttooff()//闪动4下最后关闭
{
unsigned char code tabP0[8][8]={
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x40,0xA0,0x24,0x10,0x20,0x26,0x14,0x42},
{0x40,0xA0,0x25,0x10,0x20,0x26,0x14,0x42},
{0x44,0xA0,0x25,0x10,0x20,0x26,0x14,0x42},
{0x44,0xA0,0x25,0x50,0x20,0x26,0x14,0x42},
{0xBD,0x85,0x54,0x29,0xDD,0x53,0x48,0x8D},
{0x9D,0x85,0x54,0x29,0xDD,0x53,0x08,0x8D},
{0x9D,0x81,0x54,0x09,0xDD,0x13,0x08,0x8D},
{0x95,0x81,0x54,0x09,0xDD,0x12,0x08,0x85},
/********************************************************************
*名称: Delay_1ms()
*功能:延时子程序,延时时间为1ms * x
*输入: x (延时一毫秒的个数)
*输出:无
***********************************************************************/
unsigned char code tabP2[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; //扫描
unsigned char code PWMsz[8]={0x00,0x60,0x60,0x00,0x00,0x60,0x60,0x00};//中间四个
73,74,75,76,77,78,79,80,81,82,
83,84,85,86,87,88,89,90,91,
92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,
110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
{0x56,0xB1,0x67,0x5A,0xA8,0xE7,0x56,0x5B},
{0x56,0xB1,0x67,0x5A,0xAA,0xE7,0x56,0x5F},
{0x56,0xB1,0x67,0x5A,0xAA,0xE7,0x56,0x7F},
{0x56,0xF9,0x67,0x7A,0xAA,0xE7,0x56,0x7F},
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
void init() //初始化函数
{
TMOD=0x02; //定时器0,工作模式2(0000,0010),8位定时模式
TH0=0x06; //写入预置初值6到定时器0,使250微秒溢出一次(12MHz)
TL0=0x06; //写入预置值
{0x94,0x00,0x00,0x00,0x88,0x00,0x08,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
inLeabharlann Baidu j,k,i;
for(j=0;j<23;j++)
{
for(k=0;k<10;k++)
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x00,0x00,0x00,0x02,0x10,0x00},
{0x00,0x20,0x04,0x00,0x00,0x02,0x10,0x00},
{0x00,0xA0,0x04,0x00,0x00,0x02,0x10,0x00},
{0x00,0xA0,0x24,0x10,0x00,0x02,0x10,0x00},
{0x44,0xA0,0x65,0x50,0xA0,0xA7,0x54,0x53},
{0x44,0xA0,0x65,0x50,0xA8,0xA7,0x54,0x53},
{0x44,0xA0,0x65,0x50,0xA8,0xA7,0x56,0x5B},
{0x46,0xA0,0x67,0x52,0xA8,0xA7,0x56,0x5B},
{0x44,0xA0,0x25,0x50,0xA0,0x26,0x14,0x42},
{0x44,0xA0,0x25,0x50,0xA0,0x27,0x14,0x43},
{0x44,0xA0,0x25,0x50,0xA0,0x27,0x14,0x53},
{0x44,0xA0,0x65,0x50,0xA0,0x27,0x54,0x53},
{0xDE,0xFD,0xF7,0xFB,0xFF,0xF7,0xFF,0xFF},
{0xDE,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}
};
int j,k,i;
for(j=0;j<38;j++)
j = table[num2];
delay(j);
P0=0x00;
P2=0x00;
delay(150-j);
}
/*******************************************************************/
void ys(uchar i)//1ms延时
{
uchar x,j;
{0xFF,0xFF,0xDF,0xFF,0xFF,0xFF,0xFF,0xDF},
{0xFF,0xFF,0xDF,0xFF,0xFF,0xFF,0xED,0xDF},
{0xFF,0xF7,0xDD,0xFF,0xFF,0xFF,0xED,0xDF},
{0xFF,0xF7,0xDD,0xEF,0xFF,0xDF,0xED,0xDF},
{0x95,0x01,0x54,0x09,0xC9,0x12,0x08,0x85},
{0x95,0x01,0x54,0x01,0x89,0x12,0x08,0x84},
{0x95,0x01,0x40,0x01,0x89,0x02,0x08,0x80},
{0x95,0x00,0x40,0x01,0x88,0x02,0x08,0x00},
{0x56,0xF9,0x67,0x7A,0xAE,0xE7,0x5E,0x7F},
{0x5E,0xFD,0x67,0x7B,0xAE,0xE7,0x5E,0x7F},
{0x5E,0xFD,0x67,0x7B,0xEE,0xE7,0xDE,0xFF},
{0xDE,0xFD,0xE7,0xFB,0xEF,0xE7,0xFF,0xFF},
{
for(k=0;k<10;k++)
{
for(i=0;i<8;i++)
{
P0=0;
P2=tabP2[i];
P0=tabP0[j][i];
ys(10);
}
}
}
}
void randomoff() //随机灭完
{
unsigned char code tabP0[23][8]={
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
}
void light1(uchar num1)
{
uchar j;
P0=0x00;
P2=0x00;
j = table[num1];
delay(j);
P0=0xff;
P2=0x00;
delay(150-j);
}
void light2(uchar num2)
{
uchar j;
P0=0xff;
P2=0x00;
一、
#include <STC12C5A60S2.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
unsigned int scale; //占空比控制变量
unsigned char code tabP0[38][8]={0x00,0x60,0x60,0x00,0x00,0x60,0x60,0x00};
/************************************************************************/
//结束呼吸灯专用
uchar code table[]={
0,0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,
{0xFF,0xF7,0x5D,0xAF,0xFD,0xDF,0xED,0xDF},
{0xFF,0xF7,0x5C,0xAF,0xDD,0xDF,0xED,0xDF},
{0xFF,0xE7,0x5C,0xAF,0xDD,0xDF,0x6D,0xDD},
{0xFF,0xE7,0x5C,0x2F,0xDD,0xD7,0x6D,0x9D},
{0x46,0xA1,0x67,0x52,0xA8,0xA7,0x56,0x5B},
{0x46,0xB1,0x67,0x52,0xA8,0xA7,0x56,0x5B},
{0x46,0xB1,0x67,0x5A,0xA8,0xA7,0x56,0x5B},
{0x56,0xB1,0x67,0x5A,0xA8,0xA7,0x56,0x5B},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
int j,k,i;
for(j=0;j<8;j++)
{
for(k=0;k<25;k++)
{
for(i=0;i<8;i++)
{
P0=0;
{0xFF,0xE5,0x5C,0x2F,0xDD,0xD7,0x69,0x9D},
{0xFF,0xA5,0x5C,0x2B,0xDD,0x57,0x69,0x9D},
{0xFF,0xA5,0x5C,0x29,0xDD,0x57,0x69,0x8D},
{0xBD,0x85,0x5C,0x29,0xDD,0x57,0x69,0x8D},
相关文档
最新文档