《毕业论文基于51单片机的爱心彩灯设计与制作.doc》由会员分享,可在线阅读,更多相关《毕业论文基于51单片机的爱心彩灯设计与制作.doc(22页珍藏版)》请在三一办公上搜索。
1、湖南机电职业技术学院毕业设计任务书课题名称: 基于51单片机的爱心彩灯设计与制作 专 业: 机电一体化技术 学生班级: 机电1309 学生姓名: 同组学生: 指导教师: 目 录1引 言 2 设计原理2.1MCS512.2 LED2.3中断指令2.4硬件接原理图3程序流程图3.1 主流程图3.2流水灯子流程图3.3 中断程序流程图4汇编程序4.1主程序4.2一秒钟定时程序5小结参考文献1.1引言随着人们生活环境的不断改善和美化,在许多场合可以看到彩色霓虹灯。 LED 彩灯由于其丰富的灯光色彩,低廉的造价以及控制简单等特点而得到了广泛的应用,用彩灯来装饰已经成为一种时尚。但目前市场上各式样的 LE
2、D 彩灯控制器大多数用全硬件电路实现,电路结构复杂、功能单一,这样一旦制作成品只能按照固定的模式闪亮,不能根据不同场合、不同时间段的需要来调节亮灯时间、模式、闪烁频率等动态参数。这种彩灯控制器结构往往有芯片过多、电路复杂、功率损耗大等缺点。此外从功能效果上看,亮灯模式少而且样式单调,缺乏用户可操作性,影响亮灯效果。因此有必要对现有的彩灯控制器进行改进。 课程设计是学完一门课后应用本课知识及以前的知识积累而进行的综合性、开放性的训练,是培养学生工程意识和创新能力的重要环节。进一步巩固和加深“单片机”课程的基本知识,了解单片机设计知识在实际中的应用。综合运用“单片机”课程和先修课程的理论及生产实际
3、知识去分析和解决电路设计问题,进行单片机电路设计的训练。学习单片机设计电路的一般方法,了解和掌握单片机电路的设计过程和进行方式,培养正确的设计思想和分析问题、解决问题的能力,特别是总体电路设计能力。通过计算和绘图,学会运用标准、规范和查阅有关技术资料等,培养单片机电路设计的基本技能。该程序示例了单片机键盘控制p1口流水灯花样的方法;具体表现为:p3.2 3.2 3.4 3.5四个小本文提出了一种基于AT89S51单片机的彩灯控制方案,实现对LED彩灯的控制。按键,分别实现了四个控制。通过这次实验,我们也了解了团队合作的重要性,集体的力量是伟大的,一个人如何融入一个团队是是一个重要问题,讲究合作
4、才能取得最后的成功!2设计原理2.1 MCS51单片机引脚说明MCS单片机都采用40引脚的双列直插封装方式。图2-9为引脚排列图, 40条引脚说明如下:1、主电源引脚Vss和Vcc Vss接地 Vcc正常操作时为+5伏电源2、外接晶振引脚XTAL1和XTAL2 XTAL1内部振荡电路反相放大器的输入端,是外接晶体的一个引脚。当采用外部振荡器时,此引脚接地。 XTAL2内部振荡电路反相放大器的输出端。是外接晶体的另一端。当采用外部振荡器时,此引脚接外部振荡源。3、控制或与其它电源复用引脚RST/VPD,ALE/,和/Vpp RST/VPD 当振荡器运行时,在此引脚上出现两个机器周期的高电平(由低
5、到高跳变),将使单片机复位在Vcc掉电期间,此引脚可接 图2-9 8051引脚排列图上备用电源,由VPD向内部提供备用电源,以保持内部RAM中的数据。 ALE/ 正常操作时为ALE功能(允许地址锁存)提供把地址的低字节锁存到外部锁存器,ALE 引脚以不变的频率(振荡器频率的)周期性地发出正脉冲信号。因此,它可用作对外输出的时钟,或用于定时目的。但要注意,每当访问外部数据存储器时,将跳过一个ALE脉冲,ALE 端可以驱动(吸收或输出电流)八个LSTTL电路。 对于EPROM型单片机,在EPROM编程期间,此引脚接收编程脉冲(功能) 外部程序存储器读选通信号输出端,在从外部程序存储取指令(或数据)
6、期间,在每个机器周期内两次有效。同样可以驱动八LSTTL输入。 /Vpp 、 /Vpp为内部程序存储器和外部程序存储器选择端。当/Vpp为高电平时,访问内部程序存储器,当/Vpp 为低电平时,则访问外部程序存储器。对于EPROM型单片机,在EPROM编程期间,此引脚上加21伏EPROM编程电源(Vpp)。4、输入/输出引脚P0.0 - P0.7,P1.0 - P1.7,P2.0 - P2.7,P3.0 - P3.7。 P0口(P0.0 - P0.7)是一个8位漏极开路型双向I/O口,在访问外部存储器时,它是分时传送的低字节地址和数据总线,P0口能以吸收电流的方式驱动八个LSTTL负载。 P1口
7、(P1.0 - P1.7)是一个带有内部提升电阻的8位准双向I/O口。能驱动(吸收或输出电流)四个LSTTL负载。 P2口(P2.0 - P2.7)是一个带有内部提升电阻的8位准双向I/O口,在访问外部存储器时,它输出高8位地址。P2口可以驱动(吸收或输出电流)四个LSTTL负载。 P3口(P3.0 - P3.7)是一个带有内部提升电阻的8位准双向I/O口。能驱动(吸收或输出电流)四个LSTTL负载2.2 LED显示数码管LED有共阴极和共阳极两种。如图所示。二极管的阴极连接在一起,通常此公共阴极接地,而共阳极则将发光二极管的阳极连接在一起,接入+5V的电压。一位显示器由8个发光二极管组成,其
8、中7个发光二极管构成字型“8”的各个笔划(段)ag,另一个小数点为dp发光二极管。当在某段发光二极管施加一定的正向电压时,该段笔划即亮;不加电压则暗。为了保护各段LED不被损坏,需外加限流电阻。LED数码管结构原理图: 高电平驱动 共阴极低电平驱动 共阳极图3 AT89C2051引脚配置AT89C2051芯片的20个引脚功能为:VCC 电源电压。GND 接地。RST 复位输入。当RST变为高电平并保持2个机器周期时,所有I/O引脚复位至“1”。XTAL1 反向振荡放大器的输入及内部时钟工作电路的输入。XTAL2 来自反向振荡放大器的输出。P1口 8位双向I/O口。引脚P1.2P1.7提供内部上
9、拉,当作为输入并被外部下拉为低电平时,它们将输出电流,这是因内部上拉的缘故。P1.0和P1.1需要外部上拉,可用作片内精确模拟比较器的正向输入(AIN0)和反向输入(AIN1),P1口输出缓冲器能接收20mA电流,并能直接驱动LED显示器;P1口引脚写入“1” 后,可用作输入。在闪速编程与编程校验期间,P1口也可接收编码数据。P3口 引脚P3.0P3.5与P3.7为7个带内部上拉的双向I/0引脚。P3.6在内部已与片内比较器输出相连,不能作为通用I/O引脚访问。P3口的输出缓冲器能接收20mA的灌电流;P3口写入“1”后,内部上拉,可用输入。P3口也可用作特殊功能口。2.3中断指令。在CPU和
10、外设交换信息时,存在着快速CPU和慢速外设间的矛盾,机器内部有时也可能出现突发事件,为此,计算机中通常采用中断技术。CPU和外设并行工作,当外设数据准备好( 或有某种突发事件发生)时向CPU提出请求,CPU暂停正在执行的程序转而为该外设服务(或处 理紧急事件),处理完毕再回到原断点继续执行原程序。中断优先级:当有多个中断源同时 向CPU申请中断时,CPU优先响应最需紧急处理的中断请求,处理完毕再响应优先级别较低的 ,这种预先安排的响应次序。 中断的嵌套:在中断系统中,高优先级的 中断请求能中断正在进行的较低级的中断源处理,(1)中断技术是实时控制中的常用技术,51系列单片机有三个内部中断,二个
11、外部中断。所谓 外部中断就是在外部引脚上有产生中断所需要的信号。每个中断源有固定的中断服务程序的入口地址(称矢量地址或向量地址)。当CPU响应中断以 后单片机内部硬件保证它能自动的跳转到该地址。因此,此地址是应该熟记的,在汇编程序 中,中断服务程序应存放在正确的向量地址内。(或存放一条转移指令);而在C语言中是靠Interrupt n的关键字n自动设置的。 (2)单片机的中断是靠内部的寄存器管理的,这就是中断允许寄存器IE,中断优先权寄存器IP ,必须在CPU开中断即开全局中断开关EA,开各中断源的中断开关,CPU才能响应该中断源的 中断请求,其中缺一不可。(3)从程序表面看来,主程序和中断服
12、务程序好象是没有关连的,只有掌握中断响应的过程, 才能理解中断的发生和返回,看得懂中断程序,并能编写高质量中断程序。表2.1 常用中断符号 名 称中 断 引 起 原 因 中断服务程序入口INT0外部中断0P3.2引脚的低电平或下降沿信号 0003HINT1外部中断1P3.3引脚的低电平或下降沿信号 0013HT0定时器0中断 定时计数器0计数回零溢出 000BHT1定时器1中断 定时计数器1计数回零溢出 001BHT2定时器2中断 定时计数器2中断(TF2或T2EX信号)002BHTI/RI 串行口中断 串行通信完成一帧数据发送或接收引起中断 0023H2.4 硬件原理图晶振(12MHz)定时
13、1秒对于12MHz的晶振而言,其时钟周期T=1/f=1/12us,而89C51的一个机器周期包括12个时钟周期,所以一个机器周期为1us,对于T0而言,使之工作于16-bit,最大计时为65536*1=65536us,需要多次定时才能实现一秒定时。3 程序流程图3.1总流程图初始化 有键按下? N YT0按下?T1按下?INT1按下?INT0按下? N Y N Y N Y N Y间隔点亮动点亮逐点熄灭逐点点亮流水灯3.2流水灯子程序流程图INT0键按下? N Y 消除抖动 按键释放? N Yp1.0-1.7流动点亮其他子程序流程图与上图按下其他键的流程图和它相类似。3.3中断程序流程图4 汇编
14、程序4.1主程序:ORG 0000H ;中断入口程序;LJMP STARTORG 0003HRETIORG 000BHRETIORG 0013HRETIORG 001BHRETICLEAR: RET; ; 初始化程序 ;START:ACALL CLEAR ; 主 程 序 STAR1:MOV P3,#0FFHJNB P3.2,FUN2JNB P3.3,FUN3 ;关闭按纽JNB P3.4,FUN0JNB P3.5,FUN1JNB F0,STAR1 ;曾经有键按下F0置1RET;FUN0:LCALL DL10MS ;消除抖动JB P3.4,STAR1WAITL0:JNB P3.4,WAITL0 ;
15、等待键释放SETB F0FUN01:LCALL FUN00LCALL STAR1LJMP FUN01;FUN1:LCALL DL10MS ;消除抖动JB P3.5,STAR1WAITL1:JNB P3.5,WAITL1 ;等待键释放SETB F0FUN10:LCALL FUN11LCALL STAR1LJMP FUN10;FUN2:LCALL DL10MS ;消除抖动JB P3.2,STAR1WAITL2:JNB P3.2,WAITL2 ;等待键释放SETB F0FUN20:LCALL FUN22LCALL STAR1LJMP FUN20;FUN3:LCALL DL10MS ;消除抖动JB P
16、3.3,STAR1WAITL3:JNB P3.3,WAITL3 ;等待键释放CLR F0MOV P1,#0FFH ;关显示LJMP STAR1;FUN00:MOV A,#0FEH ;从P1.0到P1.7移动点亮FUN000:MOV P0,ALCALL DL05SJNB ACC.7,OUTRL AAJMP FUN000OUT: RET;FUN11:MOV A,#0FEH ;从P1.0到P1.7依次点亮FUN111:MOV P1,ALCALL DL05SJZ OUTRL AANL A,P1AJMP FUN111;FUN22:MOV A,#0FEH ;间隔点亮FUN222:MOV P1,ALCALL
17、 DL01SCPL ARL A MOV P1,ALCALL DL01SRET;FUN33: MOV A,#01H ;逐点熄灭FUN333: MOV P1,ALCALL DL01SJNZ OUTRL AORL A,P1AJMP FUN333DL01S:MOV R2,#0FFH ; 延时程序 MOV R7,#02HLOOP1: DJNZ R2,LOOP1LOOP5:DJNZ R7,DL512RETDL10MS:MOV R3,#14HLOOP2: LCALL DL512DJNZ R3,LOOP2RETDL05S:MOV R4,#0AHLOOP3: LCALL DL10MSDJNZ R4,LOOP3R
18、ETDL30S:MOV R5,#03HLOOP4:LCALL DL05SDJNZ R5,LOOP4 RET END4.2一秒钟定时程序MOV B,#0AH ;允许中断MOV TMOD,#01H ;工作方式1MOV TH0,#0B0H MOV TL0,#3CHSETB TR0 ;启动计数SETB EA ;开中断BU:JBC TF0,SHISJMP BUSHI:MOV TH0,#3CHMOV TL0,#0B0HRET小结经过努力,我们组终于完成这次数字彩灯的课程设计任务。我们首先查阅了大量的书本资料,接着又上网搜集了许多有用信息,有时候为了找到一个合适的电路而苦恼,有时候又为取得一点成功而由衷的高
19、兴。当最终的方案设计出来以后,我们请教了信息学院的几位老师,他们的一个小小指点就给我们很大启示和灵感,对我们的程序提出了很多有价值的建议,在此对个位老师特别是辅导老师苏扬表示热烈感谢,对在设计和买元件期间给于我们帮助的同学们同样表示衷心感谢。通过课程设计,我们增强了对单片机的理解,学会查寻资料比较方案,学会单片机的设计计算;进一步提高分析解决实际问题的能力,创造一个动脑动手独立开展电路实验的机会,锻炼分析解决程序编写问题的实际本领,真正实现由课本知识向实际能力的转化;通过典型程序的设计与制作,加深对基本原理的了解,增强了实践能力。由于我们的能力和水平有限,实验过程过于简陋,实验经验尚浅,错误之
20、处在所难免,恳请老师加以纠正,以后不断学习改进!湖南机电职业技术学院机电一体化技术专业毕业设计开题报告姓名:付广志 专业:机电一体化技术 班级:机电1309 课题名称基于51单片机的爱心彩灯设计与制作指导教师张凤娟 本课题要解决的问题及采用的研究方法: 一、背景和研究意义背景: 以微处理器为核心的微型计算机以其小型、价廉、高可靠性等优势,迅速走出机房;基于高速数值解算能力的微型机,表现出的智能化水平引起了控制专业人士的兴趣。他们将微型机嵌入到一个对象体系中,实现了对象体系的智能化控制。这样一来,计算机便失去了原来的形态与通用的计算机功能。为了区别于原有的通用计算机系统,把嵌入到对象体系中、实现
21、对象体系智能化控制的计算机,称作嵌入式计算机系统。由于嵌入式计算机系统要嵌入到对象体系中,实现的是对象的智能化控制,因此。它有着与通用计算机系统完全不同的技术要求与技术发展方向。嵌入式系统虽然起源于微型计算机时代。然而,微型计算机的体积、价位、可靠性都无法满足大量的对象系统的嵌入式应用要求,因此,嵌入式系统必须走独立发展道路,这条道路就是芯片化道路。芯片化道路即是将计算机做在一个芯片上,从而开创了嵌入式系统独立发展的单片机时代。 意义: 单片机是指一个集成在一块芯片上的完整计算机系统。尽管他的大部分功能集成在一块小芯片上,但是它具有一个完整计算机所需要的大部分部件:CPU、内存、内部和外部总线
22、系统,目前大部分还会具有外存。同时集成诸如通讯接口、定时器,实时时钟等外围设备。而现在最强大的单片机系统甚至可以将声音、图像、网络、复杂的输入输出系统集成在一块芯片二、主要内容 1设计并实现具有复位功能的单片机小系统; 2利用单片机进行灯光的场景开关控制; 3利用单片机进行灯光的循环点亮控制及速度变化控制; 4 利用单片机进行灯光的色彩连续变化效果控制。 5利用单片机进行灯光的三色联动定时控。三、研究拟采用的方法 毕业设计进度计划:步骤时间进度第一步04.20-04.21确定设计方案第二步04.21-04.25硬件电路图设计第三步04.25-04.28编写软件第四步04.28-05.01软硬件
23、整体调试第五步05.01-05.10完成论文初稿第六步05.10-05.15论文定稿、总结答辩指导教师意见 年 月 日教研室意 见年 月 日 O(_)O谢谢!A large group of tea merchants on camels and horses from Northwest Chinas Shaanxi province pass through a stop on the ancient Silk Road, Gansus Zhangye city during their journey to Kazakhstan, May 5, 2015. The caravan, co
24、nsisting of more than 100 camels, three horse-drawn carriages and four support vehicles, started the trip from Jingyang county in Shaanxi on Sept 19, 2014. It will pass through Gansu province and Xinjiang Uygur autonomous region, and finally arrive in Almaty, formerly known as Alma-Ata, the largest
25、city in Kazakhstan, and Dungan in Zhambyl province. The trip will cover about 15,000 kilometers and take the caravan more than one year to complete. The caravan is expected to return to Jingyang in March 2016. Then they will come back, carrying specialty products from Kazakhstan A small art troupe f
26、ounded six decades ago has grown into a household name in the Inner Mongolia autonomous region. In the 1950s, Ulan Muqir Art Troupe was created by nine young musicians, who toured remote villages on horses and performed traditional Mongolian music and dances for nomadic families. The 54-year-old was
27、 born in Tongliao, in eastern Inner Mongolia and joined the troupe in 1975.He says there are 74 branch troupes across Inner Mongolia and actors give around 100 shows every year to local nomadic people. I can still recall the days when I toured with the troupe in the early 80s. We sat on the back of
28、pickup trucks for hours. The sky was blue, and we couldnt help but sing the folk songs, Nasun says. The vastness of Inner Mongolia and the lack of entertainment options for people living there, made their lives lonely. The nomadic people were very excited about our visits, Nasun recalls. We didnt ha
29、ve a formal stage. The audience just sat on the grass. Usually, the performances became a big party with local people joining in. For him, the rewarding part about touring isnt just about sharing art with nomadic families but also about gaining inspiration for the music and dance. Ulan Muqir literal
30、ly translates as red burgeon, and todays performers of the troupe still tour the regions villages and entertain nomadic families, but their fame has spread around the world. On May 16 and 17, nearly 100 singers and dancers from the troupe performed at Beijings Poly Theater. Their show, titled Ulan M
31、uqir on the Grassland, depicted the history and development of the art troupe. Being from the region allowed me to embrace the culture of Inner Mongolia and being a member of the troupe showed me where I belonged, Nasun, the art troupes president, who is also a renowned tenor, tells China Daily. Dur
32、ing a tour in 1985, he went to a village and met an elderly local man, who told him a story about his friendship with a solider from Shenyang, capital of Northeast Chinas Liaoning province, decades ago. The solider gave the old man a handmade saddle when they bid farewell. The story inspired Nasun t
33、o write Carved Saddle, a song that later became one of his most popular numbers. Now, every year, Nasun recruits young singers and dancers for the troupe. The troupe has also designed a new repertoire, which is mostly based on the daily lives of Mongolian people, especially the lives of nomadic fami
34、lies, and has combined contemporary musical elements with folk songs of the region. Haimu, a 25-year-old khoomei (a local variant of overtone singing) singer, joined the troupe three years ago. Along with a six-member band, he performs fast songs and soft ones that he writesall while playing the hor
35、se-head fiddle.Although I learned the piano since childhood and grew up listening to various kinds of music, to me, the folk music of Inner Mongolia is the root, he says. Performing in remote villages is pleasant. I feel at home on the boundless grasslands, and the warm people there make me feel ful
36、filled. The first round of spring auction season in Beijing ended last week, but it failed to create much spring in the art market. Although two pieces of Chinese painting fetched more than 100 million yuan, the decline in trading volume and sale rate showed a downturn this year. In the “Grand View:
37、 Chinese Painting Highlight” session at China Guardian 2015 spring auctions, Pan Tianshous representative work Eagle, Rock and Flora hit a record auction price of 279 million yuan, while Li Kerans masterwork Jinggang Mountain fetched 126.5 million yuan, an unexpected high in recent years. However, t
38、he trading volume fells to 1.87 billion yuan from 2.22 billion yuan in the same period the year before. The Huangchen 2015 Spring Auctions, which recorded 42.5 million yuan in total sales, experienced the same. The section number went down to 5 from 12 compared to last year. According to expert Shao
39、 Jianwu, the art market did not attract much excitement this year due to the booming stock market and the persistent problems of forgery and fake deals. The two pieces of Chinese painting notched up high price this spring due to their own value not due to a revival in the market. The successful tran
40、saction of two works with a hammer price of more than 100 million yuan once again confirms that valuable and rare works of high quality always earn the long-lasting high price. Chinese painting and calligraphy is still the pillar of the market. However, the overall sales rate has dropped slightly, w
41、hich reflects the demand for the ordinary auction goods has weakened,” said the president of China Guardians Hu Yanyan. Besides, the entry of new buyers also makes certain changes to the direction of purchasing. In a word, the overall market trend is very unpredictable. Although China Guardian 2015
42、Spring Auctions has achieved remarkable results, it does not mean that the market has walked out of the predicament. We still have to wait for the big economic boom to invigorate the art market.” Even so, the hot pursuit of some special items appeared this spring. A special session of China Guardian
43、 Spring Auctions titled “Fine GiltBronze Buddhist Images” achieved a great deal with total sales volume of 41.89 million yuan and 92 percent sale rate. The 5th Shamar Rinpoche Statue from 16-17th century of Tibet was sold for 5.06 million yuan. The Beijing Chengxuan Auctions featured almost 2,800 items of coins and stamps in three sessions with