1、444光立方电路图及程序3.1单片机资源分配情况将4*4*4的LED光立方分层4层,分别由单片机的P1.0,P1.1,P1.2,P1.3,四个口来控制每一层,且给低电平有效,再有P0口和P1的总共16个口来控制16列,给高电平有效,P0和P1口加上位排阻,再给每一列加三极管放大,三极管的基极接单片机的P0和P1口,集电极接5V电源,发射极接每一列。这样就可以通过控制每个口的输出信号来控制每个的亮灭。3.2复位电路 通过某种方式,是单片机内部各类寄存器的值变为出事状态的操作称为复位。单片机的复位是通过外部电路来实现的,复位引脚RET通过一个施密特触发器与复位电路相连接,施密特触发器用作噪声抑制,
2、伟哥机器周期的S5P2时刻,复位电路采样一次施密特输出电平,获得内部复位操作所需要的信号。单片机的时钟电路正常工作后,CPU在RET/VPD引脚上连续采集到两个机器周期的高电平后就可以完成复位操作了,但实际应用时,复位电平的脉冲宽度一般大于1ms。复位电路通常采用上电复位、手动按键复位和看门狗复位三种方式,本次采用的是上电复位方式。 3.3时钟电路 单片机的各个功能部件的运行都是是时钟控制信号为基准,一拍一拍的工作。因此时钟频率直接影响单片机的速度,时钟电路的质量也直接影响单片机系统的可靠性和稳定性。常用的时钟电路设计为内部时钟方式,单片机内部有一个由反向放大器构成的震荡电路,芯片上的XTAL
3、1和XTAL2分别为震荡电路的输入和输出端。只要在这两个引脚上接一个石英晶体振荡器和两个微调电容就构成内部方式的振荡器电路,有振荡器产生自激振荡,便构成一个完整的震荡信号发生器。 一般选用石英晶体振荡器。此电路在加电大约延迟10ms后振荡器起振,在XTAL2引脚产生幅度为3V左右的正弦波时钟信号,其振荡频率主要由石英晶振的频率确定。电路中两个电容C1、C2的作用有两个:一是帮助振荡器起振;二是对振荡器的频率进行微调。本系统的C1、C2的值为33pf。单片机在工作时,有内部振荡器产生或由外直接输入的送至内部控制逻辑单元的时钟信号的周期称为时钟周期。其大小是时钟信号频率的倒数,f表示。图2中的时钟
4、频率为12MHz,即f=12MHz,则时钟周期为1/12us。附注: 三极管可以不接,只是会影响光源亮度。3.4系统的工作原理图 光立方一、二层:光立方三、四层:单片机口点连接: 三极管放大电路:总原理图:3.5 焊接实物图元器件清单:名称数量大LED灯70个AT89S521片按键1901316个102排阻2个1K电阻16个20pF瓷片电容2个12MHz晶振1个10uF电容1个330电阻1个4.7K电阻1个3.3 C语言程序#include #define uchar unsigned char void delay100ms(uchar data1ms) uchar i,j,m; for(i
5、=0;idata1ms;i+) for(j=0;j110;j+) for(m=0;m100;m+) ; void disp(uchar ceng,uchar lie1,uchar lie2 ) delay100ms(7); P1=ceng; P2=lie1; P0=lie2; void main(void) unsigned char hang,shu1; unsigned char code C116= 0x07,0x0B,0x0D,0x0E,0x0E,0x0C,0x08,0x00,0x00,0x08,0x0C,0x0E,0x0C,0x08,0x00,0x00, 0x08,0x0C,0x0E
6、,0x0C,0x08,0x00,0x00,0x08,0x0C,0x0E,0x0C,0x08,0x00,0x00,0x08,0x0C, 0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E, 0x0C,0x08,0x00,0x00,0x08,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0C,0x0E,0x0F,0x0E,0x0C,0
7、x08,0x00, 0x00,0x00,0x00,0x00,0x00,0x0D,0x0D,0x0D,0x05,0x09,0x09,0x09,0x0D,0x0D,0x0D,0x05, 0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09 ; unsigned char code L116= 0xFF,0xFF,0xFF,0xFF,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x96,0
8、x96,0x96,0x96,0x96, 0x96,0x96,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC, 0x01,0x03,0x07,0x0F,0x8E,0x8C,0x88,0x80,0x00,0x00,0x00,0x10,0x30,0x70,0x70,0x60, 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0xCC,0x0F,0x33,0x66,0xCC,0xF0,0x33,0x66,0xCC, 0x66,0x33,0xF0,0xCC,0x66,0x33,0xF0,0x
9、CC,0xCC,0xCC,0xCC,0xCC,0x60,0x60,0x60,0x60, 0xE8,0x74,0x32,0x11,0x00,0x06,0x66,0x60,0x60,0x60,0x00,0x00,0x06,0x66,0x60,0x60, 0x60,0x00,0x00,0x00,0x80,0x40,0x20,0x20,0x20,0x60,0x62,0x60,0x30,0x10,0x80,0xC0, 0x60,0x60,0x60,0x60,0x64,0x60,0x30,0x10/ 0x01,0x02,0x04,0x08,0x80,0x40,0x20,0x10,0x00,0x00,0x0
10、0,0x00,0x00,0x00,0x00,0x00,/列扫描 ; unsigned char code L216= 0xFF,0xFF,0xFF,0xFF,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x69,0x69,0x69,0x69,0x69, 0x69,0x69,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0x33,0x33,0x33,0x33,0x33,0x33,0x33, 0x00,0x00,0x00,0x00,0x00,0x08,0x88,0xC8,0xE8,0xF0,0x71,0x31,0x11,0x10,0x04,0x06
11、, 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x33,0xF0,0xCC,0x66,0x33,0x0F,0xCC,0x66,0x33, 0x66,0xCC,0x0F,0x33,0x66,0xCC,0x0F,0x33,0x33,0x33,0x33,0x33,0x06,0x06,0x06,0x06, 0x8E,0x47,0x23,0x11,0x00,0x00,0x00,0x06,0x06,0x06,0x66,0x60,0x00,0x00,0x06,0x06, 0x06,0x66,0x60,0x00,0x08,0x0C,0x06,0x66,0x06,0x06,0x06,
12、0x06,0x03,0x01,0x00,0x08, 0x04,0x64,0x06,0x06,0x06,0x06,0x03,0x01/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x80,0x40,0x20,0x10 ; while(1) for(hang=0;hang8;hang+) for(shu1=0;shu116;shu1+) disp(C1hangshu1,L1hangshu1,L2hangshu1); / for(hang=0;hang1;hang+)/ / for(shu1=0;shu116;shu1+)/ shu2=0;/ disp(C1shu2shu2,L1hangshu1,L2hangshu1);/ /
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1