生产实习报告材料_第1页
生产实习报告材料_第2页
生产实习报告材料_第3页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1基础部分1.1设计任务按照给定电路原理图,进行单片机最小系统的焊接:包括单片机、开关、插 排、复位电路和晶振电路,正确焊接后,电路可以进行程序的下载。设计并焊接 简单外围电路,包括:LED与独立按键、蜂鸣器、双位数码管。使用汇编或C语言编写程序,使本电路完成以下功能:LED跑马灯、双位数码管对应计数 ,方式一(始终一个方向)、方式(左 右循环),可准确确定周期 T。每次第一个LED亮起的时候蜂鸣器响一声(t 秒)提示 。按键控制:一共三个按键分别实现以下功能暂停:检测该按键有效按下后,LED和数码管暂停,再次检测按键按下后, 继续执行当前循环;复位:检测该按键有效按下后,LED和数码管归零重

2、新开始以当前模式循环;模式转换:正常运行状态,检测该按键有效按下后,数码管显示不变,LED显示从当前方式转换成另一方式继续执行。1.2设计思路先设计好外围电路模块的原理图。根据自己的板子的实际情况安排布线并依 据原理图进行焊接。再设计程序流程图,分别编写简单程序调试各个外围电路是 否可以正常工作。学习使用单片机程序开发环境,编译下载程序等。比如:单独的跑马灯;双位数码管按秒计数;蜂鸣器 1s 一响;按键控制 LED点亮(8个按键对应8个LED)。设计程序运行的状态图以及程序流程图, 编写程序代码并调试。1.3原理图1.4PCB 图1.5器件清单表1-1器件清单(1)器件名称实物图片数量器件名称

3、实物图片数量单片机STCS90C52RC11四角按键开关4单排插针(4针)1六角自锁开关a130pF瓷片电容210KQ电阻1晶振11.0592M1导线若f干10uf电解电容1万能版HB1编程接口板1杜邦线 440脚IC座卜1LED (红色)丿丄8双位数码管1三极管8050331KQ电阻14排阻11.6程序流程图开定时器图数码管子程序图主程序流程图1.7程序代码#in clude<reg52.h>#defi ne uint un sig ned int#defi ne uchar un sig ned charucharcode0xc0,0xf9,0xa4,0xb0,0x99,0x9

4、2,0x82,0xf8,0x80,0x90;uchar code Ieds1=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f; P0口控制uchartable=8 位 LEDcodeIeds2=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd;sbit le 仁 P3A5;/左边数码管位选sbit le2=P3A4;/右边数码管位选sbit fen g=P3A7;/蜂鸣器控制位sbit key1=P2A0;/模式切换sbit key2=P2A1;/暂停和开始sbit key

5、3=P2A2;/功能复位uint ti,co un t,shi1,ge1,k;uint flag=1;void delay()/延时固定时间 int i,j;for(i=500;i>0;i-)for(j=100;j>0;j-);void delayms( uint ms)/延时ms毫秒int i,j;for(i=ms;i>0;i-)for(j=110;j>0;j-);void keysca n()if(key2=1)delayms(IO);if(key2=1)while(key2);TRO=!TRO;P2=0x00;if(key1=1)delayms(IO);if(ke

6、y1=1)while(keyl);flag=!flag;flag=1为默认模式1,为0为模式2P2=0x00;if(key3=1)delayms(10);if(key3=1)while(key3);coun t=0;PO=Oxfe;void init()P0=0xfe;P2=0x00;le 仁0;le2=0;fen g=0;TMOD=0x01;TH0=(65536-45872)/256;TL0=(65536-45872)%256;EA=1;ET0=1;/TR0=0;void display( uint shi,u int ge) uint i,j;i=shi;j=ge;le 仁0;le2=0;

7、P1=tablei;le1=1;delayms(10);le 1=0;/二极管/按键/设置定时器1工作模式/给定时器装入初值/打开中断打开定时器中断/数码管扫描P1=tablej;设置T0/T1Ie2=1;delayms(IO);int mai n()in it();while(1)if(fen g=1 &&TRO=O&&k=O)delay();fen g=O;shi 仁 cou nt/10;ge 仁coun t%10;keysca n();display(shi1,ge1);void timer() in terrupt 1TH0=(65536-45872)/

8、256;/ 定时时间为 1s,公式TL0=(65536-45872)%256;ti+;if(ti=20)/每累加到20的时间为1秒ti=0;/ti 标志置 0coun t+;if(cou nt=100) coun t=0;if(flag=1)k=cou nt%8;P0=leds1k; if(k=0) fen g=1;elsefen g=0;elsek=cou nt%14;P0=leds2k; if(k=0) fen g=1;elsefen g=0;2提高部分2.1设计任务在基础项目的前提下设计电子琴,让电子琴可以播放简单的歌曲,可以用按 键进行简单的弹奏。在弹奏过程中,led灯会根据不同的按键

9、,点亮不同的灯。2.2设计思路先设计好外围电路模块的原理图。根据自己的板子的实际情况安排布线画出 PCB图,并依据PCB图进行焊接。焊接完成之后根据设计任务设计程序流程图, 再根据流程图编写程序,下载到单片机之后根据硬件情况进行调试。直到完成设 计任务为止。2.3原理图2.4PCB 图2.5器件清单表2-1器件清单(2)器件名称实物图片数量器件名称实物图片数量四角按键开关4?18LED8蜂鸣器亠1杜邦线92.6程序流程图2.7程序代码头文件#ifndef _SOUNDPLAY_H_REVISION_FIRST.#defi ne _SOUNDPLAY_H_REVISION_FIRST.*#def

10、ine SYSTEM_OSC11059200 / 定义晶振频率 12000000HZ#define SOUND_SPACE4/5/定义普通音符演奏的长度分率,/每4分音符间隔#defi ne play 1#defi ne stop 0sbit BeepIO =P3A7;/定义输出管脚un sig nedintcodeFreTab12= 262,277,294,311,330,349,369,392,415,440,466,494 ; /原始频率表un sig ned char code Sig nTab7 = 0,2,4,5,7,9,11 ;/17 在频率表中的位置un sig ned cha

11、r code Len gthTab7= 1,2,4,8,16,32,64 ;unsigned char Sound_Temp_TH0,Sound_Temp_TL0; / 音符定时器初值暂存 unsigned char Sound_Temp_TH1,Sound_Temp_TL1; / 音长定时器初值暂存 char state_s ong;/*void In itialSo un d(void)BeepIO = 0;Sou nd_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256;/ 计算TL1应装入的初值(10ms的初装值)Sou nd_Temp_TL1 = (

12、65535-(1/1200)*SYSTEM_OSC)%256;/ 计算TH1应装入的初值TH1 = Sou nd_Temp_TH1;TL1 = Sou nd_Temp_TL1;TMOD |= 0x11;ET0 = 1;ET1 = 0;EXO = 1;EX1 = 1;TRO = 0;TR1 = 0;EA = 1;ITO = 1;IT1 = 1;void in t0() in terrupt 0state_s ong =stop;/音符发生中断void BeepTimer0(void) in terrupt 1 BeepIO = !BeeplO;TH0 = Soun d_Temp_TH0;TL0

13、= Sou nd_Temp_TL0;void in t1() in terrupt 2 state_s ong =play;void Play(unsignedchar *Sound,unsignedchar Signature,unsignedOctachord, un sig ned int Speed)unsigned int NewFreTab12;/ 新的频率表un sig ned char i,j;un sig nedintPoi nt, LDiv,LDivO 丄 Div1 丄 Div2, LDiv4,Curre ntFre,Temp_T,Sou ndLe ngth;un sig

14、ned char To ne,Le ngth,SL,SH,SM,SLe n,XG,FD;for(i=0;i<12;i+)/根据调号及升降八度来生成新的频率表j = i + Sig nature;if(j > 11)j = j-12;NewFreTabi = FreTabj*2;elseNewFreTabi = FreTabj;if(Octachord = 1)NewFreTabi>>=2;else if(Octachord = 3)NewFreTabi<<=2;Soun dLe ngth = 0;while(SoundSoundLength != 0x00)

15、/ 计算歌曲长度Soun dLe ngth+=2;Poi nt = 0;/读出第一个音符和它时时值Tone = Soun dPo in t;Len gth = Sou ndPoi nt+1;LDivO = 12000/Speed;/算出1分音符的长度(几个10ms)LDiv4 = LDivO/4;/算出4分音符的长度LDiv4 = LDiv4-LDiv4*SOUND_SPACE; / 普通音最长间隔标准TR0 = 0;TR1 = 1;while(Po int < Soun dLe ngth&&state_s ong)SL=Tone%10;/计算出音符SM=Tone/10%

16、10;/计算出高低音SH=Tone/100;/计算出是否升半CurrentFre = NewFreTabSignTabSL-1+SH;/ 查出对应音符的频率if(SL!=0)if (SM=1) CurrentFre >>= 2;/ 低音if (SM=3) CurrentFre <<= 2;/ 高音Temp_T65536-(50000/Curre ntFre)*10心2OOOOOO/SYSTEM_OSC); 计算计数器初值Sou nd_Temp_TH0 = Temp_T/256;Sou nd_Temp_TL0 = Temp_T%256;THO = Soun d_Temp_

17、TH0;TLO = Sound_Temp_TLO + 12; /力卩12是对中断延时的补偿SLe n=Le ngthTabLe ngth%10; / 算出是几分音符XG=Le ngth/10%10;FD=Le ngth/100;LDiv=LDiv0/SLe n;/算出音符类型(0普通1连音算出连音音符演奏的长度2顿音)(多少个10ms)if (FD=1)LDiv=LDiv+LDiv/2;if(XG!=1)if(XG=0)if (SLe *=4)/算出普通音符的演奏长度LDiv仁LDiv-LDiv4; elseLDiv仁LDiv*SOUND_SPACE;elseLDiv仁LDiv/2;elseL

18、Div1=LDiv; if(SL=0) LDiv1=0;LDiv2=LDiv-LDiv1;if (SL!=0)TR0=1;for(i=LDiv1;i>0;i-)/算出顿音的演奏长度/算出不发音的长度/发规定长度的音while(TF1=0);TH1 = Sou nd_Temp_TH1;TL1 = Sou nd_Temp_TL1;TF1=0;if(LDiv2!=0)TR0=0; BeeplO=0;for(i=LDiv2;i>0;i-)/ 音符间的间隔while(TF1=0);TH1 = Soun d_Temp_TH1;TL1 = Sou nd_Temp_TL1;TF1=0;Poi nt

19、+=2;Ton e=So un dPo in t;Le ngth=Sou ndPoi nt+1;BeepIO = 0;#en dif程序#in clude <reg52.H>#in clude "so un dplay.h"#defi ne uchar un sig ned char#defi ne uint un sig ned intuchar code table =0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71;uchar temp;uint

20、i,j;void delay( uint x)uint i;for(i=0;i<x;i+);void dou()uint x=150;while(x-)BeeplO=0;delay(120);BeepIO=1;delay(120);void re()uint x=150;while(x-)BeepIO=0;delay(115);BeepIO=1;delay(115);void mi()uint x=150;while(x-)BeeplO=0; delay(110);BeepIO=1; delay(110);void fa()uint x=150;while(x-)BeepIO=0; de

21、lay(105);BeepIO=1; delay(105); void so()uint x=150;while(x-)BeepIO=0; delay(100);BeepIO=1; delay(100);void la()uint x=150; while(x-) BeepIO=0;delay(95);BeeplO=1; delay(95); void si()uint x=150;while(x-)BeepIO=0;delay(90);BeepIO=1;delay(90); void doo()uint x=150;while(x-)BeepIO=0;delay(85);BeepIO=1;d

22、elay(85); void dou2()uint x=150;while(x-)BeepIO=0; delay(80);BeepIO=1;delay(80);void re2()uint x=150; while(x-)BeeplO=0;delay(75);BeepIO=1;delay(75); void mi2()uint x=150;while(x-)BeepIO=0;delay(70);BeepIO=1;delay(70); void fa2()uint x=150;while(x-)BeepIO=0;delay(65);BeepIO=1;delay(65); void so2()ui

23、nt x=150;while(x-)BeeplO=0;delay(60);BeepIO=1;delay(60); void la2()uint x=150;while(x-)BeepIO=0;delay(55);BeepIO=1;delay(55); void si2()uint x=150;while(x-)BeepIO=0;delay(50);BeepIO=1;delay(50); void doo2()uint x=150;while(x-)BeeplO=0;delay(45);BeepIO=1;delay(45);void Delay1ms( un sig ned int count)

24、un sig ned int i,j;for(i=0;i<co un t;i+)for(j=0;j<120;j+);IMusic*/生日快乐un sig ned char code Music_Girl= 0x19,0x67, 0x19,0x04, 0x1A,0x02,0x19,0x02, 0x15,0x02,0x1B,0x01,0x19,0x67,0x19,0x04,0x1A,0x02, 0x19,0x02,0x20,0x02,0x1F,0x01,0x19,0x67,0x19,0x04, 0x23,0x02,0x21,0x02,0x1F,0x02,0x1B,0x0C,0x1A,0

25、x02, 0x18,0x67,0x18,0x04,0x21,0x02,0x1F,0x02,0x20,0x02, 0x1F,0x01,0x00,0x00;/ 一只哈巴狗un sig ned char code Music_Same= 0x15,0x02, 0x15,0x02, 0x15,0x02,0x16,0x02, 0x17,0x16,0x17,0x02,0x17,0x02,0x17,0x02,0x18,0x02, 0x19,0x16,0x1A,0x02,0x1A,0x02,0x19,0x02,0x18,0x02, 0x17,0x16,0x19,0x02,0x19,0x02,0x16,0x03

26、,0x17,0x03, 0x15,0x16,0x15,0x02,0x15,0x02,0x15,0x02,0x16,0x02, 0x19,0x16,0x17,0x02,0x17,0x02,0x17,0x02,0x18,0x02, 0x19,0x16,0x1A,0x02,0x1A,0x02,0x19,0x02,0x18,0x02, 0x17,0x16,0x19,0x02,0x19,0x02,0x16,0x02,0x17,0x02, 0x15,0x16,0x00,0x00 ;/两只蝴蝶un sig ned char code Music_Two = 0x17,0x03, 0x16,0x03, 0x1

27、7,0x01,0x16,0x03, 0x17,0x03,0x16,0x03,0x15,0x01,0x10,0x03,0x15,0x03, 0x16,0x02,0x16,0x0D,0x17,0x03,0x16,0x03,0x15,0x03, 0x10,0x03,0x10,0x0E,0x15,0x04,0x0F,0x01,0x17,0x03, 0x16,0x03,0x17,0x01,0x16,0x03,0x17,0x03,0x16,0x03, 0x15,0x01,0x10,0x03,0x15,0x03,0x16,0x02,0x16,0x0D, 0x17,0x03,0x16,0x03,0x15,0x

28、03,0x10,0x03,0x15,0x03, 0x16,0x01,0x17,0x03,0x16,0x03,0x17,0x01,0x16,0x03, 0x17,0x03,0x16,0x03,0x15,0x01,0x10,0x03,0x15,0x03, 0x16,0x02,0x16,0x0D,0x17,0x03,0x16,0x03,0x15,0x03, 0x10,0x03,0x10,0x0E,0x15,0x04,0x0F,0x01,0x17,0x03, 0x19,0x03,0x19,0x01,0x19,0x03,0x1A,0x03,0x19,0x03, 0x17,0x01,0x16,0x03,0

29、x16,0x03,0x16,0x02,0x16,0x0D, 0x17,0x03,0x16,0x03,0x15,0x03,0x10,0x03,0x10,0x0D, 0x15,0x00,0x19,0x03,0x19,0x03,0x1A,0x03,0x1F,0x03, 0x1B,0x03,0x1B,0x03,0x1A,0x03,0x17,0x0D,0x16,0x03, 0x16,0x03,0x16,0x0D,0x17,0x01,0x17,0x03,0x17,0x03, 0x19,0x03,0x1A,0x02,0x1A,0x02,0x10,0x03,0x17,0x0D, 0x16,0x03,0x16,

30、0x01,0x17,0x03,0x19,0x03,0x19,0x03, 0x17,0x03,0x19,0x02,0x1F,0x02,0x1B,0x03,0x1A,0x03, 0x1A,0x0E,0x1B,0x04,0x17,0x02,0x1A,0x03,0x1A,0x03, 0x1A,0x0E,0x1B,0x04,0x1A,0x03,0x19,0x03,0x17,0x03, 0x16,0x03,0x17,0x0D,0x16,0x03,0x17,0x03,0x19,0x01,0x19,0x03,0x19,0x03,0x1A,0x03,0x1F,0x03,0x1B,0x03, 0x1B,0x03,

31、0x1A,0x03,0x17,0x0D,0x16,0x03,0x16,0x03, 0x16,0x03,0x17,0x01,0x17,0x03,0x17,0x03,0x19,0x03, 0x1A,0x02,0x1A,0x02,0x10,0x03,0x17,0x0D,0x16,0x03, 0x16,0x01,0x17,0x03,0x19,0x03,0x19,0x03,0x17,0x03, 0x19,0x03,0x1F,0x02,0x1B,0x03,0x1A,0x03,0x1A,0x0E, 0x1B,0x04,0x17,0x02,0x1A,0x03,0x1A,0x03,0x1A,0x0E, 0x1B

32、,0x04,0x17,0x16,0x1A,0x03,0x1A,0x03,0x1A,0x0E, 0x1B,0x04,0x1A,0x03,0x19,0x03,0x17,0x03,0x16,0x03, 0x0F,0x02,0x10,0x03,0x15,0x00,0x00,0x00 ;mai n()In itialSou nd();while(1)if(state_s ong)Play(Music_Girl,0,3,360);Delay1ms(500);Play(Music_Same,0,3,360);Delay1ms(500);Play(Music_Two,0,3,360);Delay1ms(500);elseP2=0xfe;temp=P2;temp=temp&0 xf0;while(temp!=0xf0)switch(temp)case 0xe0:dou();break;case 0xd0:re();break;case 0xb0:mi();break;case 0x70:fa();break;P

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论