《最新MCS-51单片机课程设计报告.doc》由会员分享,可在线阅读,更多相关《最新MCS-51单片机课程设计报告.doc(78页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateMCS-51单片机课程设计报告01电本模拟电路课程设计教学要求和选题 单片机课程设计报告专业班级: 学生学号: 学生姓名: 指导教师: 设计时间: 自动化与电气工程学院设计课题题目: 最小系统实现音乐播放及秒计时器一、设计任务与要求1 学会运用STC12C5404单片机为核心,以动态扫描的形式点亮数码管2. 学会利用利用STC12C54040单片机为核心,驱动蜂鸣器3
2、. 利用最小系统板做音乐播放和秒级计时双模式系统二、硬件原理及单元电路分析74LS1648 位串入,并出移位寄存器。用于数码管输出的串入并出。时钟 (CP) 每次由低变高时,数据右移一位,输入到 Q0, Q0 是两个数据输入端(DSA和 DSB)的逻辑与,它将上升时钟沿之前保持一个建立时间的长度74LS1383 线8 线译码器。用于控制数码管的共阴极引脚。MAX232MAX232芯片是美信公司专门为电脑的RS-232标准串口设计的单电源电平转换芯片,使用+5v单电源供电。 三位共阴数码管 三位共阴数码管结构0123456789不带小数点3FH06H5BH4FH66H6DH7DH07H7FH6F
3、H带小数点0BFH86HFBH0CFH0E6H0EDH0FDH87H0FFH0EFH 三、软件原理及框图阐述音乐播放原理:单片机产生不同频率脉冲信号的原理: 要产生音频脉冲,只要算出某一音频的脉冲(1/频率),然后将此周期除以2,即为半周期的时间,利用定时器计时这个半周期的时间,每当计时到后就将输出脉冲的I/O反相,然后重复计时此半周期的时间再对I/O反相,就可以在I/O脚上得到此频率的脉冲。(可根据下图理解) 例如,中音1频率为523Hz,其周期为1/523 S=1912uS,因此只要每1912us就将I/O反接,就可到中音DO(532Hz)。在程序中则为1912/4=47830H。高音频率
4、为中音频率的2倍则高音1为18H。对应音符表音符名频率(Hz)对应数值低音1261.625660H低音2293.664856H低音3329.62764CH低音4349.228248H低音5391.995440H低音644039H低音7493.883334H中音1523.251130H中音2587.32952BH中音3659.255126H中音4698.456524H中音5783.990920H中音68801CH中音7987.76661AH高音11046.50218H高音21174.65915H高音31318.5113H高音41396.91312H高音51567.98210H高音617600EH
5、高音71975.5330DH休止符0FFH计时器T0控制播放时长,且规定:一拍 40H 半拍 20H 1/4拍 10H。数码管动态扫描原理:视觉停留:当一个画面1秒内连续闪烁24次以上则人眼认为该画面为静止。 打开相应数码管负极引脚, 输出信号存到A寄存器, A寄存器带进位右移,则最后一位存到C, 把C中的信号传给P1.1口, P3.4口给74LS164一个上升沿触发信号,74LS164内数值右移,P1.1口信号存到Q0, 循环 7次,使Q0Q7为对应数值 延时使每一个数字显示一段时间,并保证能使数字1秒内连续闪烁24次以上 循环重复数码管动态扫描PROTEUS仿真:程序框图:程序: ORG
6、0000H LJMP STRAT ;主程序 ORG 000BH ;音乐用中断入口 LJMP TEE0 ORG 001BH ;计时用中断入口 LJMP TEE1 ORG 0100HSTRAT: MOV SP,#0DFH ;*模式选择模块* MOV DPTR,#SMG0 ;数码管显示无小数点数字 MOV P1,#01011111B ;初始化P1口并打数码管2 显示1 MOV A,#1 MOVC A,A+DPTR; LCALL PRINT MOV P1,#11011111B ;初始化P1口并打数码管3 显示0 MOV A,#0 MOVC A,A+DPTR; LCALL PRINT MOV P1,#0
7、0111111B ;初始化P1口并打数码管4 显示R MOV A,#77H LCALL PRINT MOV P1,#10111111B ;初始化P1口并打数码管5 显示2 MOV A,#2 MOVC A,A+DPTR; LCALL PRINT JNB P1.4,MUSIC ;按下S1进入音乐模式 JNB P1.3,CHANGE0 ;按下S2进入计时模式 SJMP STRAT ;保持显示1OR2;*音乐模块*MUSIC: ;音乐播放 LCALL DELKEY ;延时 避免开关多次读取 PP EQU P3.7 ;定义 音乐输出口 MOV P1,#0FFH ;清除读数 MOV TH0,#0D8H ;
8、定义计时器0初值 定时10ms MOV TL0,#0EFH MOV TMOD,#01H ;计时器0为1模式 MOV IE,#82H ;打开中断总开关与计时器1中断开关MUSIC0: JNB P1.4,SONG1 ;第一次扫描到按下S1跳转到SONG1 JNB P1.3,SONG3 ;第一次扫描到按下S2跳转到SONG3 JNB P1.2,END1 ;第一次扫描到按下S3跳转到END1 LJMP MUSIC0 ;未按下开关则不断循环等待END1: LCALL DELKEY ;延时 避免开关多次读取 JNB P1.2,STRAT ;第二次扫描到按下S3(即长按S3)跳转到初始程序 LJMP MUS
9、IC0 ;未按下S3(即短按S3) 跳转到音乐初始模式SONG1: LCALL DELKEY ;延时 避免开关多次读取 JNB P1.4,SONG2 ;第二次扫描到按下S1(即长按S1)跳转到SONG2 MOV DPTR,#MOUSE ;播放老鼠爱大米 MOV P1,#10111111B ;初始化P1口并打数码管5 显示1 MOV A,#6 LCALL PRINT ;调用输出语句 LJMP MUSIC1SONG2: MOV DPTR,#LIKE ;播放甩葱歌 MOV P1,#10111111B ;初始化P1口并打数码管5 显示2 MOV A,#5BH LCALL PRINT ;调用输出语句 L
10、JMP MUSIC1SONG3: LCALL DELKEY ;延时 避免开关多次读取 JNB P1.3,SONG4 ;第二次扫描到按下S2(即长按S2)跳转到SONG4 MOV DPTR,#SKY ;播放天空之城 MOV P1,#10111111B ;初始化P1口并打数码管5 显现3 MOV A,#4FH LCALL PRINT ;调用输出语句 LJMP MUSIC1SONG4: MOV DPTR,#ANGEL ;播放残酷天使纲领 MOV P1,#10111111B ;初始化P1口并打数码管5 显示4 MOV A,#66H LCALL PRINT ;调用输出语句 LJMP MUSIC1CHAN
11、GE0:LJMP JISHU ;连接计时返回跳转CHANGE3:LJMP STRAT ;连接初始程序返回跳转MUSIC1: JNB P1.2,MUSIC ;按下S3返回音乐模式 MOV 20H,#00H ;中断计数器清0 NOP CLR A ;A清零 MOVC A,A+DPTR ;查表取代码 JZ END0 ;是00H,则结束 CJNE A,#0FFH,MUSIC4 ;如果是休止符,往下执行 LJMP MUSIC3END0: LJMP MUSIC ;是结束符则跳转到音乐初始程序MUSIC4: NOP MOV R6,A ;读取音符的频率 INC DPTR ;DPTR加一 MOV A,#0 ;清除
12、A MOVC A,A+DPTR ;取节拍代码送R7 MOV R7,A ;读取音符发音的时间 SETB TR0 ;启动计数MUSIC2: NOP CPL PP ;音乐输出口控制 MOV A,R6 MOV R3,A ;频率转存R3 LCALL DEL ;调用音乐延时 MOV A,R7 CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否? (即控制时长) ;不等,则继续循环 MOV 20H,#00H ;等于,则清零 INC DPTR ;取下一代码 LJMP MUSIC1MUSIC3: MOV R2,20H CJNE R2,#10,MUSIC3 INC DPTR ;读取下一个音符 LJ
13、MP MUSIC1DEL: ;延时2*频率(根据具体效果调整) NOPDEL1: MOV R4,#0cHDEL2: NOP DJNZ R4,DEL2 NOP DJNZ R3,DEL1 RET;*计时模块*;JISHU: MOV TH1,#03CH ;定义计时器1初值 定时50ms MOV TL1,#0B0H MOV TMOD,#10H ;计时器1模式1 MOV IE,#88H MOV R0,#0 ;清零计时 MOV R1,#0 MOV R2,#0 MOV R3,#0 MOV R4,#0 MOV R5,#0 MOV R6,#20 ;重装中断计数器1 LCALL DELKEY ; 开关延迟STRA
14、T0: LCALL SMGPRINT ; 调用数码管动态显示 JNB P1.2,CHANGE3 ;按下S3返回初始模式选择 JNB P1.4,STRAT1 ;按下S1开始计时 SJMP STRAT0 ;未按下则循环扫描按键STRAT1:SETB TR1 ;开始计时STRAT2: LCALL SMGPRINT ;调用数码管动态显示 JNB P1.3,STOP ;按下S2则停止计时 SJMP STRAT2 ;未按下S2则一直计时STOP: CLR TR1 ;停止计时 LCALL SMGPRINT ;保持显示 JNB P1.4,STRAT1 ;按下S1则继续计时 JNB P1.2,JISHU ;按下
15、S3则返回计时初始程序 SJMP STOP ;未按下S3则循环等待TEE1: MOV TH1,#03CH ;重装计时初值 MOV TL1,#0B0H DJNZ R6,CHANGE2 ;直到延迟20次(即1秒) MOV R6,#20 ;重装中断计数器1 INC R5 ;计时加1 CJNE R5,#10,CHANGE2 ;第6数码管满10进1 MOV R5,#0 INC R4 CJNE R4,#6,CHANGE2 ;第5数码管满6进1 MOV R4,#0 INC R3 CJNE R3,#10,CHANGE2 ;第4数码管满10进1 MOV R3,#0 INC R2 CJNE R2,#6,CHANG
16、E2 ;第3数码管满6进1 MOV R2,#0 INC R1 CJNE R1,#10,CHANGE2 ;第2数码管满10进1 MOV R1,#0 INC R0 CJNE R0,#10,CHANGE2 ;记满100小时清零 MOV R0,#0 MOV R1,#0 MOV R2,#0 MOV R3,#0 MOV R4,#0 MOV R5,#0CHANGE2: RETITEE0: ;音乐模式用中断 INC 20H ;中断服务,中断计数器0加1 MOV TH0,#0D8H MOV TL0,#0EFH ;12M晶振,形成10毫秒中断 RETI;*调用库*SMGPRINT: MOV DPTR,#SMG0
17、MOV P1,#00011111B ;初始化P1口并打数码管0 MOV A,R0 MOVC A,A+DPTR LCALL PRINT MOV P1,#01011111B ;初始化P1口并打数码管2 MOV A,R2 MOVC A,A+DPTR LCALL PRINT MOV P1,#00111111B ;初始化P1口并打数码管4 MOV A,R4 MOVC A,A+DPTR LCALL PRINT MOV P1,#10111111B ;初始化P1口并打数码管5 MOV A,R5 MOVC A,A+DPTR LCALL PRINT MOV DPTR,#SMG1 MOV P1,#10011111B
18、 ;初始化P1口并打数码管1 MOV A,R1 MOVC A,A+DPTR LCALL PRINT MOV P1,#11011111B ;初始化P1口并打数码管3 MOV A,R3 MOVC A,A+DPTR LCALL PRINT RETPRINT: ; 数码管显示 MOV 24H,#08HLOOP: RRC A ;A带进位位右移 MOV P1.1,C ;将进位位输出到74LS164 CPL P3.4 ;给予74LS164上升沿触发信号 CPL P3.4 DJNZ 24H,LOOP ;A右移并输出7次DELSMG: MOV 25H,02H ;延时( 显示一段时间 )LOOP1: MOV 26
19、H,80HLOOP2: DJNZ 26H,LOOP2 DJNZ 25H,LOOP1 RETSMG0: ;不带小数点0-9代码DB 3fH,06H,5bH,4fH,66H,6dH,7dH,07H,7fH,6fH ;不带小数点0-9SMG1: ;带小数点0-9代码DB 0BfH,86H,0dbH,0cfH,0e6H,0edH,0fdH,87H,0ffH,0efH ;带小数点0-9DELKEY: ;按键延迟 避免多次读取 MOV 21H,#10HDEL3: MOV 22H,#00HDEL4: MOV 23H,#00HDEL5: DJNZ 23H,DEL5 DJNZ 22H,DEL4 DJNZ 21H
20、,DEL3 RET;*音乐代码*MOUSE: ; 老鼠爱大米DB 30H,20H,2BH,10H,26H,10HDB 26H,20H,26H,20H,2BH,20H,30H,10H,2BH,10H,2BH,60H,30H,10H,2BH,10HDB 26H,20H,26H,20H,2BH,20H,30H,20H,30H,60H,40H,10H,39H,10HDB 40H,40H,40H,10H,40H,10H,39H,10H,30H,10H,30H,60H,30H,20HDB 30H,20H,30H,20H,30H,10H,2BH,10H,2BH,40H,30H,20H,2BH,10H,26H
21、,10HDB 26H,20H,26H,20H,20H,20H,1CH,10H,2BH,10H,2BH,40H,26H,20H,2BH,10H,30H,10HDB 30H,20H,30H,20H,2BH,20H,26H,10H,20H,10H,20H,60H,40H,10H,40H,10HDB 39H,20H,30H,10H,30H,10H,30H,10H,26H,30H,2BH,20H,30H,20H,30H,20H,2BH,10H,30H,10HDB 30H,0C0H,26H,20H,26H,10H,20H,10HDB 20H,20H,20H,10H,20H,10H,20H,20H,20H,
22、10H,1CH,10H,1CH,40H,26H,20H,2BH,20HDB 30H,20H,30H,20H,30H,20H,2BH,10H,26H,10H,26H,60H,26H,10H,20H,10HDB 20H,20H,20H,20H,20H,20H,1CH,10H,18H,10H,18H,20H,1CH,20H,20H,20H,26H,20HDB 2BH,20H,30H,20H,30H,20H,39H,10H,2BH,10H,2BH,60H,26H,10H,20H,10HDB 20H,20H,20H,20H,20H,10H,1CH,20H,20H,10H,1CH,40H,26H,20H,
23、2BH,20HDB 30H,20H,30H,20H,30H,20H,2BH,10H,26H,10H,26H,60H,26H,10H,20H,10HDB 20H,20H,20H,20H,20H,20H,1CH,10H,18H,10H,18H,20H,1CH,20H,20H,20H,26H,10H,2BH,10HDB 2BH,20H,2BH,20H,2BH,80H,30H,10H,26H,20H,24H,10HDB 26H,20H,2BH,20H,2BH,80H,26H,20H,2BH,10H,30H,10HDB 30H,40H,26H,20H,2BH,10H,30H,10H,30H,40H,26
24、H,20H,2BH,20HDB 26H,20H,30H,20H,26H,20H,1CH,10H,20H,10H,20H,60H,26H,10H,20H,10HDB 1CH,20H,1CH,10H,20H,10H,20H,20H,1CH,10H,20H,10H,20H,40H,26H,10H,2BH,10H,30H,20HDB 2BH,20H,2BH,10H,26H,10H,2BH,20H,30H,10H,2BH,10H,2BH,40H,26H,20H,2BH,10H,30H,10HDB 30H,40H,26H,20H,2BH,10H,30H,10H,30H,40H,26H,20H,2BH,20
25、HDB 26H,20H,30H,20H,26H,10H,1CH,20H,20H,10H,20H,60H,26H,10H,20H,10HDB 1CH,20H,1CH,20H,18H,20H,20H,10H,1CH,10H,20H,30H,20H,10H,26H,10H,2BH,10H,30H,20HDB 2BH,40H,2BH,10H,30H,10H,2BH,10H,26H,10H,2BH,40H,26H,20H,26H,20H,2BH,60H,30H,20H,30H,0C0HDB 00HSKY: ;天空之城DB 39H,20H,34H,20HDB 18H,60H,1AH,20H,18H,40H
26、,13H,40HDB 1AH,0C0H,26H,10H,26H,10HDB 1CH,60H,20H,20H,1CH,40H,18H,40HDB 20H,80H,0FFH,26H,10H,26H,10HDB 24H,60H,26H,20H,26H,20H,18H,60HDB 26H,80,0FFH,18H,20H,18H,20H,18H,20HDB 1AH,60H,24H,20H,24H,40H,1AH,40HDB 1AH,80H,0FFH,1CH,20H,1AH,20HDB 18H,60H,1AH,20H,18H,40H,13H,40H,DB 1AH,80H,26H,10H,26H,10HDB
27、 1CH,60H,20H,20H,1CH,40H,18HDB 20H,80H,20H,40H,0FFH,26H,20H,DB 24H,40H,18H,20H,1AH,20H,1AH,40H,18H,40H,DB 15H,20H,15H,20H,13H,20H,18H,40H,0FFHDB 18H,40H,1AH,20H,1CH,20H,1CH,20H,1AH,40H,20H,40HDB 1CH,80H,0FFH,18H,20H,15H,20HDB 13H,60H,15H,20H,13H,40H,10H,40HDB 15H,80H,0FFH,26H,20H,26H,20HDB 18H,20H,1
28、AH,20H,18H,40H,13H,40HDB 13H,80H,0FFH,0FFH,0FFH,0FFHDB 1CH,20H,1AH,20H,18H,40H,1AH,40H,15H,20H,15H,20HDB 18H,60H,20H,20H,20H,40H,0FFHDB 12H,40H,13H,40H,15H,40H,18H,40HDB 13H,80H,13H,80H,DB 13H,80H,0FFH,13H,40HDB 0EH,80H,10H,40H,10H,40H,DB 13H,20H,15H,20H,18H,40H,0FFH,18H,20H,DB 15H,40H,18H,20H,15H,2
29、0H,15H,20H,10H,40HDB 13H,80H,0FFH,13H,40HDB 0EH,80H,10H,80HDB 13H,20H,15H,20H,18H,80H,0FFH,18H,20HDB 15H,40H,18H,20H,15H,20H,15H,20H,1AH,40HDB 1CH,80H,0FFH,1CH,20H,1AH,20DB 1CH,80H,1CH,80HDB 00HANGEL: ;残酷天使纲领DB 39H,40H,30H,40H,2BH,30H,30H,10H,30H,20H,2BH,20HDB 2BH,20H,2BH,20H,20H,20H,24H,20H,26H,10H
30、,2BH,20H,26H,10H,26H,40HDB 26H,40H,20H,40H,1CH,30H,2BH,10H,2BH,20H,30H,20HDB 20H,20H,20H,20H,26H,20H,20H,20HDB 20H,30H,1CH,10H,1CH,0C0HDB 0FFH,30H,20H,40H,10H,40H,10H,40H,40H,0FFH,30H,20HDB 30H,30H,2BH,10H,2BH,20H,20H,20H,20H,40H,0FFH,20H,20HDB 26H,30H,24H,10H,24H,20H,26H,20H,2BH,30H,30H,10H,30H,20H
31、,2BH,20HDB 26H,30H,24H,10H,24H,20H,26H,20H,39H,40H,0FFH,39H,10H,34H,10HDB 30H,30H,30H,10H,30H,20H,34H,20H,34H,40H,0FFH,30H,10H,2BH,10HDB 24H,30H,26H,10H,26H,20H,2BH,20H,30H,40H,0FFH,26H,20HDB 26H,30H,2BH,10H,2BH,20H,30H,20H,2BH,40H,39H,40HDB 39H,60H,34H,20H,34H,80HDB 0FFH,30H,20H,40H,10H,40H,10H,40H
32、,40H,0FFH,30H,20HDB 30H,20H,2BH,10H,2BH,20H,20H,20H,20H,40H,0FFH,20H,20HDB 26H,30H,24H,10H,24H,20H,26H,20H,2BH,30H,30H,10H,30H,20H,2BH,20HDB 26H,30H,24H,10H,24H,20H,26H,20H,39H,40H,0FFH,39H,10H,34H,10HDB 30H,30H,30H,10H,30H,20H,34H,20H,34H,40H,0FFH,30H,10H,2BH,10HDB 24H,30H,26H,10H,26H,20H,2BH,20H,3
33、0H,40H,0FFH,26H,20HDB 26H,30H,2BH,10H,2BH,20H,30H,20H,2BH,30H,26H,10H,26H,20H,24H,20HDB 26H,80H,26H,80HDB 30H,30H,30H,10H,30H,20H,34H,20H,30H,30H,30H,10H,30H,20H,34H,20HDB 2BH,30H,2BH,10H,2BH,20H,30H,20H,34H,30H,39H,10H,39H,20H,34H,20HDB 30H,30H,30H,10H,30H,20H,34H,20H,2BH,30H,34H,10H,34H,10H,39H,30
34、HDB 30H,30H,30H,10H,30H,20H,34H,20H,30H,30H,30H,10H,30H,20H,34H,20HDB 2BH,30H,2BH,10H,2BH,20H,30H,20H,34H,30H,30H,10H,30H,20H,2BH,20HDB 26H,30H,24H,10H,24H,20H,26H,20H,2BH,30H,30H,10H,30H,20H,2BH,20HDB 26H,80H,26H,80HDB 39H,40H,30H,40H,2BH,30H,30H,10H,30H,20H,2BH,20HDB 2BH,20H,2BH,20H,20H,20H,24H,20
35、H,26H,10H,2BH,20H,26H,10H,26H,40HDB 26H,40H,20H,40H,1CH,30H,2BH,10H,2BH,20H,30H,20HDB 34H,20H,34H,20H,39H,20H,34H,20H,2BH,10H,30H,20H,30H,10H,30H,40HDB 39H,40H,30H,40H,2BH,30H,30H,10H,30H,20H,2BH,20HDB 2BH,20H,2BH,20H,20H,20H,24H,20H,26H,10H,2BH,20H,26H,10H,26H,40HDB 26H,40H,20H,40H,1CH,30H,2BH,10H,
36、2BH,20H,30H,20HDB 20H,20H,20H,20H,26H,20H,20H,20HDB 20H,30H,1CH,10H,1CH,0C0HDB 00HLIKE: ;甩葱歌DB 30H,20H,24H,20H,24H,30H,20H,10H,1CH,10H,1CH,10H,24H,20H,24H,20H,24H,10H,1CH,10HDB 20H,20H,26H,20H,26H,20H,26H,20H,20H,10H,20H,10H,24H,20H,24H,30H,24H,10HDB 30H,20H,24H,20H,24H,30H,20H,10H,1CH,10H,1CH,10H,24H,20H,24H,20H,24H,10H,1CH,10HDB 18H,10H,18H,10H,18H,10H,1AH,10H,1CH,10H,1CH,10H,20H,10H,20H,10H,1CH,20H,24H,10H,24H,10H,24H,20H,24H,10H,1CH,10HDB 18H,20H,18H,20H,1AH,20H,1CH,20H,20H,20H,26H,20H,26H,20H,26H,10H,26H,10DB 1AH,10H,1AH,10H,1AH,10H,1AH,10H,1CH,20H,20H,20H,1CH,20H,24H,10