|
#include "STC12C5A.H"
#include <INTRINS.H> //包含延时头文件
#define uint unsigned int
#define uchar unsigned char
#define nop() _nop_();_nop_();
sbit AD=P1^0; //定义音频输入接口
sbit K1=P1^2; //定义功能按键接口
sbit K2=P1^4; //定义功能按键接口
sbit K3=P3^5; //定义功能按键接口
sbit K4=P3^6; //定义功能按键接口
sbit VCC1=P1^5; //定义电源功能接口必须为高电平
sbit VCC2=P1^7; //定义电源功能接口必须为高电平
sbit VCC3=P3^2; //定义电源功能接口必须为高电平
sbit VCC4=P3^4; //定义电源功能接口必须为高电平
sbit L1=P0^3; sbit L2=P4^5; sbit L3=P2^4; sbit L4=P2^2; sbit H1=P0^5;
sbit L5=P0^1; sbit L6=P4^6; sbit L7=P2^7; sbit L8=P2^0; sbit H2=P0^6;
sbit L9=P0^0; sbit L10=P0^7; sbit L11=P2^6; sbit L12=P1^6; sbit H3=P4^4;
sbit L13=P1^3; sbit L14=P0^4; sbit L15=P2^5; sbit L16=P3^3; sbit H4=P2^3;
sbit H5=P4^7;
//定义光立方的接口全部高电平有效
sbit LED1=P0^2; sbit LED2=P2^1;
sbit LED3=P3^7; sbit LED4=P1^1;
//定义脚底下4个受控制的LED灯-右下角高电平有效其余低电平有效
unsigned char bdata dzzc0;
sbit dzzc07=dzzc0^7;
sbit dzzc06=dzzc0^6;
sbit dzzc05=dzzc0^5;
sbit dzzc04=dzzc0^4;
sbit dzzc03=dzzc0^3;
sbit dzzc02=dzzc0^2;
sbit dzzc01=dzzc0^1;
sbit dzzc00=dzzc0^0;
unsigned char bdata dzzc1;
sbit dzzc17=dzzc1^7;
sbit dzzc16=dzzc1^6;
sbit dzzc15=dzzc1^5;
sbit dzzc14=dzzc1^4;
sbit dzzc13=dzzc1^3;
sbit dzzc12=dzzc1^2;
sbit dzzc11=dzzc1^1;
sbit dzzc10=dzzc1^0;
unsigned char bdata dzzc2;
sbit dzzc27=dzzc2^7;
sbit dzzc26=dzzc2^6;
sbit dzzc25=dzzc2^5;
sbit dzzc24=dzzc2^4;
sbit dzzc23=dzzc2^3;
sbit dzzc22=dzzc2^2;
sbit dzzc21=dzzc2^1;
sbit dzzc20=dzzc2^0;
unsigned char bdata dzzc3;
sbit dzzc37=dzzc3^7;
sbit dzzc36=dzzc3^6;
sbit dzzc35=dzzc3^5;
sbit dzzc34=dzzc3^4;
sbit dzzc33=dzzc3^3;
sbit dzzc32=dzzc3^2;
sbit dzzc31=dzzc3^1;
sbit dzzc30=dzzc3^0;
//调整数字显示的数据用分别为变的1234
// 4 dzzc6
//3 2 dzzc7 dzzc5
// 1 dzzc4
unsigned char bdata dzzc4;
sbit dzzc47=dzzc4^7;
sbit dzzc46=dzzc4^6;
sbit dzzc45=dzzc4^5;
sbit dzzc44=dzzc4^4;
sbit dzzc43=dzzc4^3;
sbit dzzc42=dzzc4^2;
sbit dzzc41=dzzc4^1;
sbit dzzc40=dzzc4^0;
unsigned char bdata dzzc5;
sbit dzzc57=dzzc5^7;
sbit dzzc56=dzzc5^6;
sbit dzzc55=dzzc5^5;
sbit dzzc54=dzzc5^4;
sbit dzzc53=dzzc5^3;
sbit dzzc52=dzzc5^2;
sbit dzzc51=dzzc5^1;
sbit dzzc50=dzzc5^0;
unsigned char bdata dzzc6;
sbit dzzc67=dzzc6^7;
sbit dzzc66=dzzc6^6;
sbit dzzc65=dzzc6^5;
sbit dzzc64=dzzc6^4;
sbit dzzc63=dzzc6^3;
sbit dzzc62=dzzc6^2;
sbit dzzc61=dzzc6^1;
sbit dzzc60=dzzc6^0;
unsigned char bdata dzzc7;
sbit dzzc77=dzzc7^7;
sbit dzzc76=dzzc7^6;
sbit dzzc75=dzzc7^5;
sbit dzzc74=dzzc7^4;
sbit dzzc73=dzzc7^3;
sbit dzzc72=dzzc7^2;
sbit dzzc71=dzzc7^1;
sbit dzzc70=dzzc7^0;
unsigned int CYCLE=100,PWM_LOW=1110,shan=0,saom=0,shuzi1=0,shuzi2=0,shuzi3=0,shuzi4=0;//定义周期并赋值
unsigned char YL1=0,YL2=0,YL3=0,YL4=0,YL5=0,YL6=0,YL7=0,YL8=0,YL9=0,YL10=0,YL11=0,YL12=0,YL13=0,YL14=0,YL15=0,YL16=0;//高度值
unsigned char lie=0,hang=0,ceng=0;
unsigned char yinyue4X4[]= //定义4X4X4整个屏幕的显示数据,高电平有效,没有音乐的时候默认不亮
{
0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,
};
unsigned char code shuzu4X4[]= //定义4X4X4整个屏幕的显示数据,根据取字模软件进行提取高电平有效
{
//////////////正方形 由 大变小////////////////
0X00,0XCF,0XCF,0X00,0X00,0X00,0XCF,0XCF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,//0帧
0X00,0XEF,0XAF,0XEF,0X00,0X00,0XAF,0X0F,0XAF,0X00,0X00,0XEF,0XAF,0XEF,0X00,0X00,0X00,0X00,0X00,0X00,//1帧
0X00,0XFF,0X9F,0X9F,0XFF,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0XFF,0X9F,0X9F,0XFF,//2帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0XEF,0XAF,0XEF,0X0F,0X00,0XAF,0X0F,0XAF,0X0F,0X00,0XEF,0XAF,0XEF,0X0F,//4帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X0F,0X0F,0X0F,0X0F,0X00,0XCF,0XCF,0X0F,0X0F,0X00,0XCF,0XCF,0X0F,0X0F,//5帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0XEF,0XAF,0XEF,0X0F,0X00,0XAF,0X0F,0XAF,0X0F,0X00,0XEF,0XAF,0XEF,0X0F,//7帧
0X00,0XFF,0X9F,0X9F,0XFF,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0XFF,0X9F,0X9F,0XFF,//8帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X7F,0X5F,0X7F,0X0F,0X00,0X5F,0X0F,0X5F,0X0F,0X00,0X7F,0X5F,0X7F,0X0F,//10帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X3F,0X3F,0X0F,0X0F,0X00,0X3F,0X3F,0X0F,0X0F,//11帧
0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X5F,0X4F,0X7F,0X0F,0X00,0X5F,0X0F,0X5F,0X0F,0X00,0X7F,0X5F,0X7F,0X0F,//13帧
0X00,0XFF,0X9F,0X9F,0XFF,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0X9F,0X0F,0X0F,0X9F,0X00,0XFF,0X9F,0X9F,0XFF,//14帧
0X00,0X7F,0X5F,0X7F,0X0F,0X00,0X5F,0X0F,0X5F,0X0F,0X00,0X7F,0X5F,0X7F,0X0F,0X00,0X0F,0X0F,0X0F,0X0F,//18帧
0X00,0X3F,0X3F,0X0F,0X0F,0X00,0X3F,0X3F,0X0F,0X0F,0X00,0X0F,0X0F,0X0F,0X0F,0X00,0X0F,0X0F,0X0F,0X0F,//19帧
};
void Delay(unsigned int t)
{
while(--t);
}
void init()
{
P4SW=0xff; //定义P4口为I/O口
P0M1=0x00; //I/O口0模式控制器0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
P0M0=0xff; //定义P0为强上拉输出.
P1M1=0x01;
P1M0=0xfe; //定义P1为强上拉输出. P.14作为AD此时不能作为强上蜡
P2M1=0x00;
P2M0=0xff; //定义P2为强上拉输出.
P3M1=0x00;
P3M0=0xff; //定义P3为强上拉输出.
P4M1=0x00;
P4M0=0xff; //定义P4为强上拉输出.
}
void hansao(unsigned char hs,unsigned char shangxia)
{
if(shangxia==0)
{
if(hs<5) //判断hs的值是否在行扫描的值范围内,不在范围内不执行任何操作
{
if(hs==0) //选通第1行 //作为控制显示高度的时候调用
{
H1=1;H2=1;H3=1;H4=1;H5=0; return;
}
if(hs==1) //选通第2行
{
H1=1;H2=1;H3=1;H4=0;H5=1; return;
}
if(hs==2) //选通第3行
{
H1=1;H2=1;H3=0;H4=1;H5=1; return;
}
if(hs==3) //选通第4行
{
H1=1;H2=0;H3=1;H4=1;H5=1; return;
}
if(hs==4) //选通第5行
{
H1=0;H2=1;H3=1;H4=1;H5=1; return;
}
}
}
else if(shangxia==1)
{
if(hs<5) //判断hs的值是否在行扫描的值范围内,不在范围内不执行任何操作
{
if(hs==0) //选通第1行 //平时的时候调用这个显示其他图形和变化
{
H1=0;H2=1;H3=1;H4=1;H5=1; return;
}
if(hs==1) //选通第2行
{
H1=1;H2=0;H3=1;H4=1;H5=1; return;
}
if(hs==2) //选通第3行
{
H1=1;H2=1;H3=0;H4=1;H5=1; return;
}
if(hs==3) //选通第4行
{
H1=1;H2=1;H3=1;H4=0;H5=1; return;
}
if(hs==4) //选通第5行
{
H1=1;H2=1;H3=1;H4=1;H5=0; return;
}
}
}
}
void main()
{
unsigned int donghua=0;
init(); //初始化IO口为强上蜡输出状态
VCC1=1;VCC2=1;VCC3=1;VCC4=1;LED4=1; //关闭开机时候的状态 使单片机没有任何反应 LED4通电不初始化会亮可以作为电源指示灯
while (1)
{
//26//////////////////////////////////上位机生成动画数据控制光立方LED灯显示////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//数据直接利用上位机去摸取好之后赋值到定义的数组里面shuzu4X4
//8421的数据分别为L1L2L3L4,然后第一行的数据分别为数组的第一个数据从上面到下面数0-5
//H1-H2-H2-H4-H5
//H6-H7-H8-H9-H10
//H11-H12-H13-H14-H15
//H16-H17-H18-H19-H20
for(CYCLE=0;CYCLE<3000;CYCLE++)
{
for(saom=0;saom<5;saom++)
{
dzzc0=shuzu4X4[saom+donghua*20]; //将第一个需要分配的数据赋值个为变量进行分配给L1-L4
L1=dzzc07;L2=dzzc06;L3=dzzc05;L4=dzzc04;
dzzc1=shuzu4X4[saom+donghua*20+5]; //将第一个需要分配的数据赋值个为变量进行分配给L5-L8
L5=dzzc17;L6=dzzc16;L7=dzzc15;L8=dzzc14;
dzzc2=shuzu4X4[saom+donghua*20+10]; //将第一个需要分配的数据赋值个为变量进行分配给L9-L12
L9=dzzc27;L10=dzzc26;L11=dzzc25;L12=dzzc24;
dzzc3=shuzu4X4[saom+donghua*20+15]; //将第一个需要分配的数据赋值个为变量进行分配给L13-L16
L13=dzzc37;L14=dzzc36;L15=dzzc35;L16=dzzc34;
hansao(saom,0);
Delay(10);
H1=1;H2=1;H3=1;H4=1;H5=1;
}
}
donghua++;
Delay(10);
if(donghua==65000)
{
donghua=0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
|
|