单片机音乐盒程序设计源代码.doc

上传人:仙人指路1688 文档编号:2385856 上传时间:2023-02-17 格式:DOC 页数:10 大小:29.50KB
返回 下载 相关 举报
单片机音乐盒程序设计源代码.doc_第1页
第1页 / 共10页
单片机音乐盒程序设计源代码.doc_第2页
第2页 / 共10页
单片机音乐盒程序设计源代码.doc_第3页
第3页 / 共10页
单片机音乐盒程序设计源代码.doc_第4页
第4页 / 共10页
单片机音乐盒程序设计源代码.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《单片机音乐盒程序设计源代码.doc》由会员分享,可在线阅读,更多相关《单片机音乐盒程序设计源代码.doc(10页珍藏版)》请在三一办公上搜索。

1、RS BIT P2.0;定义液晶显示端口标号RW BIT P2.1E BIT P2.2ORG 0000HLJMP MAINORG 000BHLJMP TT0ORG 001BHLJMP TIINTORG 1000HMAIN:;-液晶初始化MOV SP,#70HMOV P0,#01H;清屏CALL ENABLEMOV P0,#38H;8位,2行显示LCALL ENABLEMOV P0,#0FH;屏显ON,光标ON,闪烁ONLCALL ENABLEMOV P0,#06H;计数地址加1,显示幕ONLCALL ENABLE;-内在初始化LCALL INITIL;-KEY1:LCALL KEYLCALL

2、MODDLJMP KEY1;-键盘扫描KEY:NOPNOP LCALL KSJNZ K1;有按键转到K1LCALL KAIJILCALL SOPXN:LJMP KEYK1:LCALL MODDLCALL MODDLCALL KSJNZ K2LJMP KEYK2:MOV R2,#0FEH;读键盘MOV R4,#00HK3:MOV A,R2MOV P1,AMOV A,P1JB ACC.4,L1;为1跳转,第一行无按键MOV A,#00HLJMP LKL1:JB ACC.5,L2MOV A,#04HLJMP LKL2:JB ACC.6,L3MOV A,#08HLJMP LKL3:JB ACC.7,N

3、EXT1MOV A,#0CH;-LK:ADD A,R4PUSH ACCK4:LCALL DELAY1;若同时有其他键,则等待LCALL KSJNZ K4;-MOV R3,#07HCLR AMOV R0,#30HMOV R1,#31HMM1:MOV A,R1MOV R0,AINC R0INC R1DJNZ R3,MM1POP ACCMOV R0,ARET;-NEXT1;INC R4;-列扫描MOV A,R2JNB ACC.3,N2LJMP N1N2:LJMP KEYN1:RL AMOV R2,ALJMP K3;-KS:MOV A,#0F0H;判断P1口MOV P1,ANOPNOP MOV A,P

4、1CPL AANL A,#0F0HRET;-DELAY1:SETB RS0DL:MOV R5,#0AHDL2:MOV R6,#63DL3:NOPNOP DJNZ R6,DL3DJNZ R5,DL2CLR RS0RET;30H-37H初值为零;-INITIL:MOV R3,#08HMOV R0,#30HM1:MOV R0,#00HM1:MOV R0,#00HM1:MOV R0,#00HINC R0DJNZ R3,M1RET;-;显示;-MODD:MOV P0,#8EHLCALL ENABLEMOV A,37HMOV DPTR,#TABLE3MOVC A,A+DPTRLCALL WRITE2RET

5、;-;开机提示字;-KAIJI:MOV A,37HCJNE A,#0FH,DFFMOV P0,#80H;设光标地址LCALL ENABLEMOV DPTR,#TABLE1;写数据LCALL WRITE1DFF:RET;-;按键值播放歌曲;-SOP:MOV A,37HCJNE A,#01H,A11LCALL MODDMOV 52H,#HIGH TABLE10MOV 53H,#LOW TABLE10LCALL INITILE2LCALL MAIN0A11:CJNE A,#02H,A22LCALL MODDMOV 52H,#HIGH TABLE20MOV 3H,#LOW TABLE20LCALL I

6、NITILE2LCALL MAIN0AAA:RET;-INITILE2:MOV L50MS,#20MOV L1MS,#00HMOV L250MS,#00HMOV SEC,#00HMOV MIN,#00HMOV HOU,#00HMOV A,HOUMOV B,#10HDIV ABADD A,#30H;将BCD码转化为ASIIC码MOV P0,#0C8H;显示小时十位CALL ENABLECALL WRITE2MOV A,BADD A,#30HMOV P0,#0C9H;显示小时个位CALL ENABLECALL WRITE2MOV A,#3AHMOV P0,#0DH;显示冒号CALL ENABLEC

7、ALL WRITE2MOV A,MINMOV B,10DIV ABADD A,#30HMOV P0,#0CBH;显示分十位CALL ENABLECALL WRITE2MOV A,BADD A,#30HMOV P0,#0CDH;显示冒号CALL ENABLECALL WRITE2MOV A,SECMOV B,#10DIV ABADD A,#30HMOV P0,#0CEH;显示秒十位CALL ENABLECALL WRITE2MOV A,BADD A,#30HMOV P0,#0CFH;显示秒个位CALL ENABLECALL WRITE2MOV P0,#0C0H;设光标地址CALL ENABLEC

8、ALL WRITE1RET;-写指令ENABLE:CLR RSCLR RWCLR ELCALL DELAYSETB ERET;-写数据WRITE1:MOV R1,#00HA1:MOV A,R1MOVC A,A+DPTRCALL WRITE2INC R1CJNE A,#OFEH,A1;未到字符串末尾继续RETWRITE2:MOV P0,ASETB RSCLR RWLCR ECALL DELAYSETB ERET;-TABDB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8HDB 80H,90H,88H,83H,0C6H,0A1H,86H,8EHTAB1:DB 89H,86

9、H,0C7H,0C7H,0C0HTAB2:DB 0C6H,88H,0C0HTABLE1:DBWELCOM HERE,0FEHTABLE2:DBDFF WB,0FEHTABLE3:DB 30H,31H,32H,33HDB 34H,35H,36H,37HDB 38H,39H,41H,42HDB 43H,44H,45H,46H;-释放歌曲程序;-MAIN0:MOV TMOD,#11HMOV IE,#8AHMOV TH1,#3CHMOV TL1,#0B0HLCALL KSJNZ TTM12MOV 40H,#00H;-NEXT20:MOV A,40HMOV DPH,52HMOV DPL,53HMOVC

10、A,A+DPTRMOV R2,AJZ STOPANL A,#0FHMOV R1,AMOV A,R2SWAP AANL A,#0FHJNZ SINGCLR TR0JMP W1;-SING:DEC AMOV 22H,ARL AMOV DPTR,#TABLE00MOVC A,A+DPTRMOV TH0,AMOV 21H,AMOV A,22HRL AINC AMOVC A,A+DPTRMOV TL0,AMOV 20H,ASETB TR0SETB TR1W1:LCALL DELAY30INC 40HLCALL KS;有键跳出JNZ STOPLJMP NEXT20;-STOP;CLR TR0CLR TR1

11、LJMP AMIN0;-TTM12:LCALL K2MOV A,37HCJNE A,#0EH,TTM13CLR TR1LCALL DELAY1TTM120:LCALL KSLCALL DELAY1JZ TTM120LCALL K2MOV A,37HCJNE A,#0EH,TTM120SETB TR1LJMP NEXT20TTM13:CJNE A,#0CH,TTM14MOV A,52HINC AMOV 52H,AMOV A,53HINC AMOV 53H,AMOV A,36HINC AMOV 37H,ALJMP TTM2TTM14:CJNE A,#0DH,TTM2MOV A,52HDEC AMO

12、V 52H,AMOV A,53HDEC AMOV 53H,AMOV A,36HDEC AMOV 37H,ATTM2:RETRET;-TABLE00;DW 64580 ,64684 ,64777 ,64820DW 64898,64968,65030,64260DW 64400,64524,65058,63835,64021;-;第二首月亮代表我的心;-TABLE20:DB 02H,82HDB 16H,32H,54H,02H,52HDB 0A6H,32H,54H,02H,52HDB 64H,74H,0B6H,64HDB 52H,5CH,32H,22HDB 16H,12H,14H,32H,22HDB

13、 16H,12H,14H,22H,32HDB 26H,12H,94H,22H,32HDB 2CHDB 32H,52HDB 36H,22H,14H,54HDB 0ACH,92H,0A2HDB 96H,0A2H,96H,82HDB 3CH,54HDB 36H,22H,14H,54HDB 0ACH,92H,0A2HDB 96H,0A2H,96H,82HDB 3CH,54HDB 36H,22H,14H,54HDB 0ACH,92H,0A2HDB 16H,12H,14H,54HDB 0ACH,92H,0A2HDB 16H,12H,14H,22H,32H2CH,02H,82HDB 16H,32H,56H,12HDB 0A6H,32H,56H,52HDB 66H,72H,0B6H,62HDB 66H,72H,0B6H,62HDB 1CHDB 00END

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号