《学位论文—--基于单片机的光立方设计.doc》由会员分享,可在线阅读,更多相关《学位论文—--基于单片机的光立方设计.doc(29页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、XXXX大学本科课程设计 题 目 : 基于单片机的光立方设计 姓 名 : 学 号: 院(系): 专业、年级: 指导教师: 二XX年X月基于单片机的4*4*4光立方设计一、 设计任务在当今信息化社会的高速发展过程中,大屏幕显示已经从公共信息展示等商业应用向 消费类多媒体应用渗透。新型的大屏幕要求显示画面色彩鲜艳,立体感强,静如油画,动如电影,这些设计广泛应用于交通运输、车站、商场、医院、宾馆、证券市场、工业企业管理等公共场所。本设计旨在利用人眼视觉暂留的特点,通过AT89C52单片机控制一个由64盏LED灯组成的四层光立方模拟3D显示效果,实现三维显示。该光立方具有以下功能:1)能单独点亮每一个
2、LED灯;2)能点亮任意一条线上的LED灯;3)能同时点亮任意一个面上的LED灯;4)能同时点亮所有的LED灯;5)能让LED灯自由亮灭,产生不同的显示效果。二、 设计方案1、单片机资源分配情况将LED光立方分成4层,分别由单片机的P2.0,P2.1,P2.2,P2.3,四个IO口来控制每一层,由于采用的是共阳极所以当层电位为高电平有效,由P0口和P1的总共16个IO口来控制每层的16盏灯,低电平有效,P0口加上拉排阻。这样就可以通过控制IO口的输出电平来控制每盏灯的亮灭。2、系统框图本系统主要由时钟电路、复位电路、LED光立方电路组成;时钟电路和复位电路作为单片机输入,LED光立方电路作为单
3、片机输出,显示出控制结果如图2- 1所示。时钟电路:单片机的各个功能部件的运行都是以时钟控制信号为基准,一拍一拍的工作。因此时钟频率直接影响单片机的速度,时钟电路的质量也直接影响单片机系统的可靠性和稳定性。常用的时钟电路设计为内部时钟方式,单片机内部有一个由反向放大器构成的振荡电路,芯片上的XTAL1和XTAL2分别为振荡电路的输入和输出端。只要在这两个引脚上接一个石英晶体振荡器和两个微调电容就构成内部方式的振荡器电路,由振荡器产生自激振荡,便构成一个完整的振荡信号发生器。复位电路:通过某种方式,使单片机内部各类寄存器的值变为初始状态的操作称为复位,复位主要通过外部电路实现。常见的复位电路包括
4、上电复位、手动按键复位和看门狗复位三种方式,本次设计综合采用上电复位方式和按键复位方式。图2- 2系统框图3、程序流程本项目的程序设计主要包括延时程序、显示程序两个子程序。显示程序:主要是在得到当前控制灯的位置后,通过控制与它相连的阴阳两端的引脚电平,从而实现对灯的亮灭进行控制。延时程序:由于显示程序不能控制灯持续点亮,达不到显示效果,我们需要增加延时程序来延长显示时间从而达到显示效果。如图2-2所示单片机复位以后,程序开始运行,获取到要显示的LED所在的层和列然后调用显示子程序点亮LED灯,通过延时程序进行短暂延时后继续获取下一个要显示的LED灯的所在的层和列。图2- 3程序流程图28三、
5、工作原理利用单片控制LED点阵显示的原理和控制技术,来控制光立方显示。即通过编写程序控制不同LED的亮灭,来显示不同的内容。由于人眼的具有视觉暂留的特性,设置每幅画面的延迟时间可以使连续的一系列画面呈现动态。最终达到所要显示的内容。每个灯都是由层控制端(共阳极)和列控制端决定亮或灭。如图3-1 a所示,将光立方分成四层,每一层有一个单片机引脚作为层控制端与之相连,设计成共阳极。如图3-1 b所示每层光立方有16盏灯,而这16盏灯又分别与单片机的P0、P1两个IO口组共16个IO口相连,这样就能很好地控制每一盏灯的亮灭。图3-1 光立方结构示意图:a 四层光立方分布结构,b 光立方每层的LED分
6、布在三维光立方中采用动态扫描显示,这种显示方式巧妙地利用了人眼的视觉暂留特性。将连续的几帧画面高速的循环显示,只要帧速率高于24帧/秒,人眼看起来就是一个完整的,相对静止的画面。最典型的例子就是电影放映机。在电子领域中,因为这种动态扫描显示方式极大的缩减了发光单元的信号线数量,因此在LED显示技术中被广泛使用。图3-2描述了将光立方某个侧面对角线点亮的过程图3-2光立方某个侧面对角线点亮的过程四、 结果分析本次设计完成了对光立方的系统框架和基本电路的设计,最终通过编写代码使光立方产生了不错的显示效果,基本完成了设计任务中的不同要求,但是仍然存在单独点亮一盏灯亮度不够等等问题。经过与老师和同学针
7、对这些问题的探讨我们得出了与这些问题相关的一些分析:1)实际做成的光立方单独一盏灯点亮时,亮度很高,而点亮一个面时亮度明显不够分析:这主要是因为这次设计对于LED灯采取的是共阳极的方式,所以用单片机一个引脚的电压带动一个面进行显示肯定是远远不够的,经过思考,我觉得将设计改为共阴极的可能会显示效果更好。2)光立方有一盏灯总是与设计程序不符合(该亮的时候是灭的,而该灭的时候又是亮的)分析:这可能是由于在焊接过程中,将这个LED灯的阴极和阳极刚好接反了,于是显示结果刚好相反。3)点亮侧面的灯时,出现的是该面的灯按层轮换分析:这可能是由于延时程序设计的不合理,导致画面显示不流畅,修改延时程序,再进行调
8、试后正常显示。五、 实物照片如图5-1所示是光立方设计底座,其中蓝色方框中为单片机的最小系统,包括单片机和晶振电路以及复位电路,红色方框中为LED列控制端,灯座的引脚分别与单片机的P0、P1的16个IO口相连。图5-2展示的是最终的显示效果。图5- 1光立方底座图5- 2最终显示效果六、 附:1、元件清单表 1元件清单名称数量LED灯70个AT89C521片按键1个102排阻1个100欧电阻16个20pF瓷片电容2个12MHz晶振1个10uF电容1个10K电阻1个1K电阻1个2、电路图图7.2- 1光立方整体电路图7.2- 2单片机图7.2- 3时钟电路图7.2- 4复位电路3、软件清单#in
9、clude#define uchar unsigned char#define uint unsigned intuchar num,DELAY=100;sbit H1=P34;sbit H2=P35;sbit H3=P36;sbit H4=P37;sbit L1=P20;sbit L2=P21;sbit L3=P22;sbit L4=P23;sbit L5=P24;sbit L6=P25;sbit L7=P26;sbit L8=P27;sbit L9=P10;sbit L10=P11;sbit L11=P12;sbit L12=P13;sbit L13=P14;sbit L14=P15;sb
10、it L15=P16;sbit L16=P17;uchar code tab=0xfF,0xfF,0xfF,0xfF,0xfF,0xfF,0xfF,0xfF,/*未命名文件,0*/* (4 X 4 ) */;uchar code tab1=0x0f,0x00,0x0f,0x00,0x0f,0x00,0x0f,0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,0x0f,0x00,0x0f,0x00,0x0f,0x00,0x0f,0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0xf0,;/* 延时函数/*/void dela
11、y (uint a) / 用于点扫描的延时unsigned int i;while( -a != 0)for(i = 0; i 1; i+); /* 面1/*/void mian1(uchar d,uchar e)uchar i;H2=0;H3=0;H4=0;i = d & 0x01; if(i = 0x01)H1 = 1;L1 = 0;delay(DELAY);H1 = 0;L1 =1;i = d & 0x02;if(i = 0x02)H1 = 1;L2 = 0;delay(DELAY);H1 = 0;L2 =1;i = d & 0x04;if(i = 0x04)H1 = 1;L3 = 0;
12、delay(DELAY);H1 = 0;L3 =1;i = d & 0x08;if(i = 0x08)H1 = 1;L4 = 0;delay(DELAY);H1 = 0;L4 =1;i = d & 0x10;if(i = 0x10)H1 = 1;L5 = 0;delay(DELAY);H1 = 0;L5 =1;i = d & 0x20;if(i = 0x20)H1 = 1;L6 = 0;delay(DELAY);H1 = 0;L6 =1;i = d & 0x40;if(i = 0x40)H1 = 1;L7 = 0;delay(DELAY);H1 = 0;L7 =1;i = d & 0x80;i
13、f(i = 0x80)H1 = 1;L8 = 0;delay(DELAY);H1 = 0;L8 =1;i = e & 0x01;if(i = 0x01)H1 = 1;L9 = 0;delay(DELAY);H1 = 0;L9 =1;i = e & 0x02;if(i = 0x02)H1 = 1;L10 = 0;delay(DELAY);H1 = 0;L10 =1;i = e & 0x04;if(i = 0x04)H1 = 1;L11 = 0;delay(DELAY);H1 = 0;L11 =1;i = e & 0x08;if(i = 0x08)H1 = 1;L12 = 0;delay(DELA
14、Y);H1 = 0;L12 =1;i = e & 0x10;if(i = 0x10)H1 = 1;L13 = 0;delay(DELAY);H1 = 0;L13 =1;i = e & 0x20;if(i = 0x20)H1 = 1;L14 = 0;delay(DELAY);H1 = 0;L14 =1;i = e & 0x40;if(i = 0x40)H1 = 1;L15 = 0;delay(DELAY);H1 = 0;L15 =1;i = e & 0x80;if(i = 0x80)H1 = 1;L16 = 0;delay(DELAY);H1 = 0;L16 =1;/* 面2/*/void mi
15、an2(uchar d,uchar e)uchar i;H1=0;H3=0;H4=0;i = d & 0x01; if(i = 0x01)H2 = 1;L1 = 0;delay(DELAY);H2 = 0;L1 = 1;i = d & 0x02;if(i = 0x02)H2 = 1;L2 = 0;delay(DELAY);H2 = 0;L2 = 1;i = d & 0x04;if(i = 0x04)H2 = 1;L3 = 0;delay(DELAY);H2 = 0;L3 = 1;i = d & 0x08;if(i = 0x08)H2 = 1;L4 = 0;delay(DELAY);H2 = 0
16、;L4 = 1;i = d & 0x10;if(i = 0x10)H2 = 1;L5 = 0;delay(DELAY);H2 = 0;L5 = 1;i = d & 0x20;if(i = 0x20)H2 = 1;L6 = 0;delay(DELAY);H2 = 0;L6 = 1;i = d & 0x40;if(i = 0x40)H2 = 1;L7 = 0;delay(DELAY);H2 = 0;L7 = 1;i = d & 0x80;if(i = 0x80)H2 = 1;L8 = 0;delay(DELAY);H2 = 0;L8 = 1;i = e & 0x01;if(i = 0x01)H2
17、= 1;L9 = 0;delay(DELAY);H2 = 0;L9 = 1;i = e & 0x02;if(i = 0x02)H2 = 1;L10 = 0;delay(DELAY);H2 = 0;L10 = 1;i = e & 0x04;if(i = 0x04)H2 = 1;L11 = 0;delay(DELAY);H2 = 0;L11 = 1;i = e & 0x08;if(i = 0x08)H2 = 1;L12 = 0;delay(DELAY);H2 = 0;L12 = 1;i = e & 0x10;if(i = 0x10)H2 = 1;L13 = 0;delay(DELAY);H2 =
18、0;L13 = 1;i = e & 0x20;if(i = 0x20)H2 = 1;L14 = 0;delay(DELAY);H2 = 0;L14 = 1;i = e & 0x40;if(i = 0x40)H2 = 1;L15 = 0;delay(DELAY);H2 = 0;L15 = 1;i = e & 0x80;if(i = 0x80)H2 = 1;L16 = 0;delay(DELAY);H2 = 0;L16 = 1;/* 面3/*/void mian3(uchar d,uchar e)uchar i;H2=0;H1=0;H4=0;i = d & 0x01; if(i = 0x01)H3
19、 = 1;L1 = 0;delay(DELAY);H3 = 0;L1 = 1;i = d & 0x02;if(i = 0x02)H3 = 1;L2 = 0;delay(DELAY);H3 = 0;L2 = 1;i = d & 0x04;if(i = 0x04)H3 = 1;L3 = 0;delay(DELAY);H3 = 0;L3 = 1;i = d & 0x08;if(i = 0x08)H3 = 1;L4 = 0;delay(DELAY);H3 = 0;L4 = 1;i = d & 0x10;if(i = 0x10)H3 = 1;L5 = 0;delay(DELAY);H3 = 0;L5 =
20、 1;i = d & 0x20;if(i = 0x20)H3 = 1;L6 = 0;delay(DELAY);H3 = 0;L6 = 1;i = d & 0x40;if(i = 0x40)H3 = 1;L7 = 0;delay(DELAY);H3 = 0;L7 = 1;i = d & 0x80;if(i = 0x80)H3 = 1;L8 = 0;delay(DELAY);H3 = 0;L8 = 1;i = e & 0x01;if(i = 0x01)H3 = 1;L9 = 0;delay(DELAY);H3 = 0;L9 = 1;i = e & 0x02;if(i = 0x02)H3 = 1;L
21、10 = 0;delay(DELAY);H3 = 0;L10 = 1;i = e & 0x04;if(i = 0x04)H3 = 1;L11 = 0;delay(DELAY);H3 = 0;L11 = 1;i = e & 0x08;if(i = 0x08)H3 = 1;L12 = 0;delay(DELAY);H3 = 0;L12 = 1;i = e & 0x10;if(i = 0x10)H3 = 1;L13 = 0;delay(DELAY);H3 = 0;L13 = 1;i = e & 0x20;if(i = 0x20)H3 = 1;L14 = 0;delay(DELAY);H3 = 0;L
22、14 = 1;i = e & 0x40;if(i = 0x40)H3 = 1;L15 = 0;delay(DELAY);H3 = 0;L15 = 1;i = e & 0x80;if(i = 0x80)H3 = 1;L16 = 0;delay(DELAY);H3 = 0;L16 = 1;/* 面4/*/void mian4(uchar d,uchar e)uchar i;H2=0;H3=0;H1=0;i = d & 0x01; if(i = 0x01)H4 = 1;L1 = 0;delay(DELAY);H4 = 0;L1 = 1;i = d & 0x02;if(i = 0x02)H4 = 1;
23、L2 = 0;delay(DELAY);H4 = 0;L2 = 1;i = d & 0x04;if(i = 0x04)H4 = 1;L3 = 0;delay(DELAY);H4 = 0;L3 = 1;i = d & 0x08;if(i = 0x08)H4 = 1;L4 = 0;delay(DELAY);H4 = 0;L4 = 1;i = d & 0x10;if(i = 0x10)H4 = 1;L5 = 0;delay(DELAY);H4 = 0;L5 = 1;i = d & 0x20;if(i = 0x20)H4 = 1;L6 = 0;delay(DELAY);H4 = 0;L6 = 1;i
24、= d & 0x40;if(i = 0x40)H4 = 1;L7 = 0;delay(DELAY);H4 = 0;L7 = 1;i = d & 0x80;if(i = 0x80)H4 = 1;L8 = 0;delay(DELAY);H4 = 0;L8 = 1;i = e & 0x01;if(i = 0x01)H4 = 1;L9 = 0;delay(DELAY);H4 = 0;L9 = 1;i = e & 0x02;if(i = 0x02)H4 = 1;L10 = 0;delay(DELAY);H4 = 0;L10 = 1;i = e & 0x04;if(i = 0x04)H4 = 1;L11
25、= 0;delay(DELAY);H4 = 0;L11 = 1;i = e & 0x08;if(i = 0x08)H4 = 1;L12 = 0;delay(DELAY);H4 = 0;L12 = 1;i = e & 0x10;if(i = 0x10)H4 = 1;L13 = 0;delay(DELAY);H4 = 0;L13 = 1;i = e & 0x20;if(i = 0x20)H4 = 1;L14 = 0;delay(DELAY);H4 = 0;L14 = 1;i = e & 0x40;if(i = 0x40)H4 = 1;L15 = 0;delay(DELAY);H4 = 0;L15
26、= 1;i = e & 0x80;if(i = 0x80)H4 = 1;L16 = 0;delay(DELAY);H4 = 0;L16 = 1;void cube4(uchar j,uchar k,uchar f)switch(j)case 0:mian1(k,f);break;case 1:mian2(k,f);break;case 2:mian3(k,f);break;case 3:mian4(k,f);break;void all()uint p,m;/从上往下for(num=0;num4;num+)for(p=0;p50;p+)cube4(num,tab2*num,tab2*num+1
27、);/*for(num=0;num16;num+)/面选择for(m=0;m30;m+) /一个面的停留时间for(p=0;p10;p+) /扫描一行的次数cube4(num%4,tab12*num,tab12*num+1);/对4求余,取0-3面*/从后向前for(p=0;p50;p+)cube4(0,0x0f,0x00);cube4(1,0x0f,0x00);cube4(2,0x0f,0x00);cube4(3,0x0f,0x00);for(p=0;p50;p+)cube4(0,0xf0,0x00);cube4(1,0xf0,0x00);cube4(2,0xf0,0x00);cube4(3
28、,0xf0,0x00);for(p=0;p50;p+)cube4(0,0x00,0x0f);cube4(1,0x00,0x0f);cube4(2,0x00,0x0f);cube4(3,0x00,0x0f);for(p=0;p50;p+)cube4(0,0x00,0xf0);cube4(1,0x00,0xf0);cube4(2,0x00,0xf0);cube4(3,0x00,0xf0);/从左往右for(p=0;p50;p+)cube4(0,0x11,0x11);cube4(1,0x11,0x11);cube4(2,0x11,0x11);cube4(3,0x11,0x11);for(p=0;p5
29、0;p+)cube4(0,0x22,0x22);cube4(1,0x22,0x22);cube4(2,0x22,0x22);cube4(3,0x22,0x22);for(p=0;p50;p+)cube4(0,0x44,0x44);cube4(1,0x44,0x44);cube4(2,0x44,0x44);cube4(3,0x44,0x44);for(p=0;p50;p+)cube4(0,0x88,0x88);cube4(1,0x88,0x88);cube4(2,0x88,0x88);cube4(3,0x88,0x88);/竖向移动for(num=0;num4;num+)for(p=0;p50;
30、p+)cube4(num,0x11,0x11);for(num=0;num4;num+)for(p=0;p50;p+)cube4(3-num,0x22,0x22);for(num=0;num4;num+)for(p=0;p50;p+)cube4(num,0x44,0x44);for(num=0;num4;num+)for(p=0;p50;p+)cube4(3-num,0x88,0x88);/从上往下 从下往上for(m=0;m3;m+)for(num=0;num4;num+)for(p=0;p20;p+)cube4(num,tab2*num,tab2*num+1);for(num=0;num4
31、;num+)for(p=0;p20;p+)cube4(3-num,tab2*num,tab2*num+1);/竖条移动for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x01,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x02,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x04,0x00);for(m=0;m100;m+)for(num=0;nu
32、m4;num+)for(p=0;p1;p+)cube4(num,0x08,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x80,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x40,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x20,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;
33、p1;p+)cube4(num,0x10,0x00);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x01);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x02);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x04);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,
34、0x00,0x08);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x80);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x40);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x20);for(m=0;m100;m+)for(num=0;num4;num+)for(p=0;p1;p+)cube4(num,0x00,0x10);/烟火类似
35、for(m=0;m15;m+)for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x45,0x38);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x82,0x04);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x47,0x86);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x84,0x42);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x21,0x04);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x54,0x83);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x02,0x48);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x64,0x85);for(num=0;num4;num+)for(p=0;p20;p+)cube4(3-num,0x23,0x47);void main()P3M0=0XF0;/高四位强推while(1) all();
限制150内