《单片机实验(江苏理工学院).doc》由会员分享,可在线阅读,更多相关《单片机实验(江苏理工学院).doc(8页珍藏版)》请在金锄头文库上搜索。
1、三、数据传送子程序(把(R2,R3)源RAM区首地址内的(R6,R7)个字节数据,传送到(R4,R5)目的RAM区。)数据传输ORG 0MOV R2,#60HMOV R3,#00HMOV R4,#70HMOV R5,#00HMOV R6,#0FHMOV R7,#0FFHSE22: MOV DPL,R3MOV DPH,R2MOVX A,DPTRMOV DPL,R5MOV DPH,R4MOVX DPTR,ACJNE R3,#0FFH,LO42INC R2LO42:INC R3CJNE R5,#0FFH,LO43INC R4LO43:INC R5CJNE R7,#00H,LO44CJNE R6,#0
2、0H,LO45SJMP $NOPLO44: DEC R7 SJMP SE22LO45: DEC R7DEC R6SJMP SE22END二、拆字程序(把7000H的内容拆开,高位送7001H低位,低位送7002H低位。7001H/7002H高位清零,一般本程序用于把数据送显示缓冲区时用。)ORG 0000HMOV A,#34HMOV DPTR,#7000HMOVX A,DPTRMOV R1,ASWAP AANL A,#0FHMOV DPTR,#7001HMOVX DPTR,AMOV DPTR,#7000HMOV A,R1ANL A,#0FHMOV DPTR,#7002HMOVX DPTR,AS
3、JMP $END内部:ORG 0000HMOV A,#34HMOV R0,#30HMOV R0,ASWAP AANL A,#0FHMOV R0,#31HMOV R0,AMOV R0,#30HMOV A,#34HMOV R0,AANL A,#0FHMOV R0,#32HMOV R0,ASJMP $END7000H,7001H的低位相拼后送入7002H:ORG 0000HMOV A,#12HMOV DPTR,#7000HMOVX DPTR,AANL A,#0FHMOV R0,AMOV A,#34HMOV DPTR,#7001HMOVX DPTR,AANL A,#0FHSWAP AORL A,R0M
4、OV DPTR,#7002HMOVX DPTR,ASJMP $END把7000H内容拆开,高位送7001H低位,低位送7002H低位,7001H、7002H高位清零外部:ORG 0000HMOV DPTR,#7000HMOVX A,DPTRMOV B,AANL A,#0F0HSWAP AINC DPTRMOVX DPTR,AMOV A,BANL A,#0FHINC DPTR MOVX DPTR,ASJMP $ END内部:ORG 0000HMOV R0,#30HMOV A,R0MOV B,AANL A,#0F0HSWAP AINC R0MOV R0,AMOV A,BANL A,#0FHINC
5、R0 MOV R0,ASJMP $ END四、查找相同数个数(在7000H-700FH中查出几个字节是零,统计“00”的个数再显示在30H单元内。)ORG 0000HSS:MOV R0,#10H MOV R1,#00H MOV DPTR,#7000HAA:MOVX A,DPTR CJNE A,#00H,BB INC R1BB:INC DPTR DJNZ R0,AA MOV 30H,R1 SJMP $ END五、P3.3输入、P1口输出(1、3.3口做输入口,外接一脉冲,每输入一个脉冲,P1口按十六进制加一。P1口做输出口,编写程序,使P1口接的8个发光二极管L1-L8按16进制加一方式点亮发光
6、二极管。)ORG 0000HCIA:MOV A,#00HCIA1:JB P3.3,CIA1LCALL DELAYJB P3.3,CIA1CIA2:JNB P3.3,CIA2LCALL DELAYJNB P3.3,CIA2INC APUSH ACCMOV P1,APOP ACCAJMP CIA1DELAY:MOV R6,#20HDELAY1:MOV R7,#50HDJNZ R7,$DJNZ R6,DELAY1RETEND六、并行I/O口8255扩展(模拟交通灯)交通灯 ORG 0 MOV DPTR,#0FF2BH MOV A,#80H MOVX DPTR,A MOV DPTR,#0FF29H M
7、OV A,#09H MOVX DPTR,A INC DPTR MOV A,#24H MOVX DPTR,A ACALL DELAY1 LOOP3:MOV DPTR,#0FF29H MOV A,#01H MOVX DPTR,A INC DPTR MOV A,#86H MOVX DPTR,A ACALL DELAY1 LOOP:MOV R0,#3 MOV DPTR,#0FF29H MOV A,#01H MOVX DPTR,A INC DPTR MOV A,#45H MOVX DPTR,A ACALL DELAY2 MOV DPTR,#0FF29H MOV A,#01H MOVX DPTR,A IN
8、C DPTR MOV A,#04H MOVX DPTR,A ACALL DELAY2 DJNZ R0,LOOP MOV DPTR,#0FF29H MOV A,#0CH MOVX DPTR,A INC DPTR MOV A,#30H MOVX DPTR,A ACALL DELAY1 LOOP2:MOV R0,#3 MOV DPTR,#0FF29H MOV A,#0AH MOVX DPTR,A INC DPTR MOV A,#28H MOVX DPTR,A ACALL DELAY2 MOV DPTR,#0FF29H MOV A,#08H MOVX DPTR,A INC DPTR MOV A,#20
9、H MOVX DPTR,A ACALL DELAY2 DJNZ R0,LOOP2 AJMP LOOP3DELAY1:MOV R7,#10 DELAY3:MOV R6,#200 DELAY6:MOV R5,#250 DJNZ R5,$ DJNZ R6,DELAY6 DJNZ R7,DELAY3 RET DELAY2:MOV R7,#10 DELAY4:MOV R6,#100 DELAY5:MOV R5,#250 DJNZ R5,$ DJNZ R6,DELAY5 DJNZ R7,DELAY4 RET END七、串并转换实验ORG 0000HLJMP MAINORG 000BHAJMP PT0FOR
10、G 0033HMAIN:MOV SP,#60H MOV TMOD,#01H MOV TL0,#00H MOV TH0,#4BH MOV R0,#0H MOV R4,#20 MOV SCON,#00H CLR TI CLR RI SETB TR0SETB ET0SETB EASJMP $PT0F:PUSH ACC PUSH PSW CLR EA CLR TR0 MOV TL0,#00H MOV TH0,#4BH SETB TR0 DJNZ R4,EXIT MOV R4,#20 MOV DPTR,#TAB MOV A,R0 MOVC A,A+DPTR CLR TI MOV SBUF,A INC R
11、0 CJNE R0,#0AH,EXIT MOV R0,#00HEXIT:SETB EA SETB ET0 SETB TR0 POP PSW POP ACC RETITAB:DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6HEND1.R0(30H)内部RAM区域首地址内的R1(20H)个字节数据传送到(R2,R3)目的RAM区 ORG 0000H MOV R0,#30H MOV R1,#20H MOV R2,#60H MOV R3,#00H MAIN:MOV A,R0 MOV DPH,#60H MOV DPL,#00H MOVX DPTR,A I
12、NC R0 INC R3 DJNZ R2,MAINEND2.在7000H和700FH中查出几个字节是零,统计00的个数,显示在30H上 ORG 0000H MOV R0,#00H MOV R1,#00H MOV DPTR,#7000H MAIN:MOVX A,DPTR CJNE A,#00H,LOOP INC R0 LOOP:INC DPTR INC R1 CJNE R1,#10H,MAIN MOV 30H,R0 SJMP $ END3.外部3000H-300FH内容传送到内部30H-3FH中 ORG 0000H MOV R2,#30H MOV R3,#00H MOV R4,#10H MOV R0,#30HMAIN:MOV DPTR,#3000H MOVX A,DPTR MOVX R0,A INC R3 INC R0 DJNZ R4