视频:
希望喜欢工作室作品的朋友将我们的作品和精神分享,我们坚持创新,坚持开源!转载和引用请注明出处,禁止用于商业目的。
光立方原理图:
14年注定是繁忙的一年,年初到现在,除了本职工作比较繁忙,再就是辅导学生参加单片机设计竞赛。加上最近比较泛滥,都没时间整理汇编教程。好像是在某一天,突然觉得这么浑浑噩噩下去实在是不行,于是鞭策自己跑到实验室,开始枯燥的码字。进过一段时间的努力,总算是小有收货。
这次给大家的带来的作品是4x4x4的立方光,可能大家觉得,之前我做的是8x8x8的,现在怎么越做越小了,其实不是这样的。现在我带领学生也在做16x16X16的立方光,但大的立方光就必须要用C语言写了,我的C语言学的时间不长,基本上都是用到什么才去学,为了能更好的实现16x16x16立方光的控制,所以我先做了一个4x4x4的立方光,用C语言编程,感悟一下C语言的控制方式。视频中的动画平不多,因为我实在是没时间来设计动画了,有想做的朋友可以自己再加动画。
制作步骤
一 材料请根据原理图自行购买
二制作工具
焊接灯珠一向是比较麻烦的,但借助自己制作的工具来焊接,可以节约大量的人力和时间,所以这里简要说明一向焊接模板的制作。
图1
图1是我用万能版加排针搭建的,排针直接横向的间距是7个洞,纵向的间距是8个洞,没2个排针为一组,一次焊接好16组就可以了。
接下来是灯珠管脚的弯折,最好是用平口镊子。灯珠的短管脚面向你,用镊子把所有管脚向右90度弯折,如图2
再把灯珠的长管脚(正极)向下90度弯折,如图
图3
灯珠的弯折只需要这两步,然后就可以摆放到焊接模板上了,这里我以两个灯珠的摆放为例如图4
摆放好后,就可以焊接了,焊接好后,检查是否有开焊虚焊等问题。焊好的点阵如图4-1

三 驱动板的焊接,这次驱动电路我没使用任何IC,而是三极管直接驱动,之所以选用8550,是因为三极管开关电路中,8550是低电平导通,避免了单片机上电就导通的问题。8550可承受的电流较于其他90系列三极管较大,最适合做led驱动。
每组三极管的焊接如图所示
图5
共阳极驱动三极管共需要16只,再加上4只回路控制,共20只,这里需要注意的是,共阳极三极管和回路三极管的焊接是不同的,详细请参照原理图。三极管的B极是通过单片机控制的,三极管的数量比较多,所以在板子背面就只能跳线了。
四 实物组装
焊接好最小系统,驱动电路后,就可以组装了。组装之前检查4个点阵高度是否一致,然后就直接插在母座上面。插好后,会发现灯珠的负极管脚还是悬空的。此时将每一层的负极管脚短接。注意!!!请参考下图6:

这里要强调是,不是每个点阵的负极短接,而是两两点阵之间的负极管脚短接。这里所说的每一层是竖直高度的,而不是之前焊接好的点阵。
这样焊接好后,电路是不会点亮的,因为led灯珠此时的负极没有构成回路,换句话说,负极还是悬空的。此时就需要用废弃的管脚或跳线来把每一层的负极连接到万能板的回路三极管上。我是用元件管脚连接的,由于颜色问题,图片里看不清楚,所以我给大家做出了图示图7
实物焊接图
图8

负极短接好后,就是连接到回路三极管了,我采用了跳线短接,即每一层的负极短接到万能板,再通过跳线连接到回路三极管的C极,这样立方光就有了电路回路(请根据原理图理解)
图9

主程序:
- #include"stc12c5a.h"
- #include"INTRINS.h"
- #include"basic.h"
- #define sNum 0
- #define eNum 1600
- void Delay100us();
- void Timer0Init(void);
- Word temp=sNum,count=0;
- Byte code table[]={0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,
- 0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xfe,0xff,0xff,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xf3,0xf3,0xf3,0xf3,0xf3,
- 0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
- 0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7, //71
- 0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
- 0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,
- 0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
- 0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe, //75 上到下
-
- 0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0, //79 前到后
- 0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,
- 0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,
- 0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,
- 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,//83 右到左
- 0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
- 0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
- 0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,
- 0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7, //87 下到上
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, //91
- 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,
- 0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,
- 0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,
- 0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xf0,0xff,0xff,0xff, //95
- 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xfc,0xfc,0xff,0xff,0xfc,0xfc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xf8,0xf8,0xf8,0xff,0xf8,0xf8,0xf8,0xff,0xf8,0xf8,0xf8,0xff,0xff,0xff,0xff,0xff,
- 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,//99
-
- };
- void main()
- {
- Byte m=0xfe,i;
- Timer0Init();
- while(1)
- {
-
- if(temp<eNum)
- {
- for(i=0;i<8;i++)
- {
- P0=m;
- P1=table[temp+i];
- m=_crol_(m,1);
- Delay100us();
- P1=0xff;
- }
- m=0xfe;
- P0=0xff;
- for(i=0;i<8;i++)
- {
- P2=m;
- P1=table[temp+i+8];
- m=_crol_(m,1);
- Delay100us();
- P1=0xff;
- }
- m=0xfe;
- P2=0xff;
- }
- else
- temp=sNum;
- }
- }
- void Timer0Init(void) //5毫秒@11.0592MHz
- {
- IE=0x82;
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x01; //设置定时器模式
- TL0 = 0x00; //设置定时初值
- TH0 = 0x28; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void T0_time() interrupt 1
- {
-
- TL0 = 0xA0; //设置定时初值
- TH0 = 0x15; //设置定时初值
- count++;
- if(count==30)
- {
- count=0;
- temp=temp+16;
- }
- }
- void Delay100us() //@11.0592MHz
- {
- unsigned char i, j;
- i = 2;
- j = 15;
- do
- {
- while (--j);
- } while (--i);
- }
复制代码
更多资料请移步工作室百度网盘下载
工作室百度网盘: http://pan点baidu点com/share/home?uk=3691829170 包含工作室教学视频、教学资料和网络作品资料下载
|