本文为您讲解基于51单片机的4*4*4光立方程序实现原理及程序代码。LED光立方的复位电路、时钟电路、每层LED灯电路控制逻辑,系统总原理图,工作流程及相关C语言源码实现。希望能够对你学习了解LED光立方程序编写及LED立方实体制作起到一定的帮助指导作用。
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通过一个施密特触发器与复位电路相连接,施密特触发器用作噪声抑制,伟哥机器周期的S5P2时刻,复位电路采样一次施密特输出电平,获得内部复位操作所需要的信号。单片机的时钟电路正常工作后,CPU在RET/VPD引脚上连续采集到两个机器周期的高电平后就可以完成复位操作了,但实际应用时,复位电平的脉冲宽度一般大于1ms。复位电路通常采用上电复位、手动按键复位和看门狗复位三种方式,本次采用的是上电复位方式。
3.3时钟电路
单片机的各个功能部件的运行都是是时钟控制信号为基准,一拍一拍的工作。因此时钟频率直接影响单片机的速度,时钟电路的质量也直接影响单片机
系统的可靠性和稳定性。常用的时钟电路设计为内部时钟方式,单片机内部有一个由反向放大器构成的震荡电路,芯片上的XTAL1和XTAL2分别为震荡电路的输入和输出端。只要在这两个引脚上接一个石英晶体振荡器和两个微调电容就构成内部方式的振荡器电路,有振荡器产生自激振荡,便构成一个完整的震荡信号发生器。
一般选用石英晶体振荡器。此电路在加电大约延迟10ms后振荡器起振,在XTAL2引脚产生幅度为3V左右的正弦波时钟信号,其振荡频率主要由石英晶振的频率确定。电路中两个电容C1、C2的作用有两个:一是帮助振荡器起振;二是对振荡器的频率进行微调。本系统的C1、C2的值为33pf。
单片机在工作时,有内部振荡器产生或由外直接输入的送至内部控制逻辑单元的时钟信号的周期称为时钟周期。其大小是时钟信号频率的倒数,f表示。图2中的时钟频率为12MHz,即f=12MHz,则时钟周期为1/12us。
附注: 三极管可以不接,只是会影响光源亮度。
3.4系统的工作原理图
光立方一、二层:
光立方三、四层:
单片机口点连接:
三极管放大电路:
总原理图:
3.5 焊接实物图
元器件清单:
3.3 C语言程序
#include
#define uchar unsigned char
void delay100ms(uchar data1ms)
{uchar i,j,m;
for(i=0;i
for(j=0;j<110;j++)
for(m=0;m<100;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 C1[][16]={
{0x07,0x0B,0x0D,0x0E,0x0E,0x0C,0x08,0x00,0x00,0x08,0x0C,0x0E,0x0C,0x08,0x00,0x00},
{0x08,0x0C,0x0E,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,0x08,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 L1[][16]={
{0xFF,0xFF,0xFF,0xFF,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x96,0x96,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,0xCC,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,0x00,0x00,0x00,0x00,0x00,0x00},//列扫描
};
unsigned char code L2[][16]={
{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},
{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,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;hang<8;hang++)
{for(shu1=0;shu1<16;shu1++)
disp(C1[hang][shu1],L1[hang][shu1],L2[hang][shu1]);
}
// for(hang=0;hang<1;hang++)
// {
// for(shu1=0;shu1<16;shu1++)
// {shu2=0;
// disp(C1[shu2][shu2],L1[hang][shu1],L2[hang][shu1]);
// }
// }
}
}
今天的文章光立方体c语言程序,444光立方程序怎么写 光立方原理图、源代码及制作教程 – 全文…分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/23726.html