51单片机常见汇编程序实验代码

更新时间:2023-12-14 22:55:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1. 将片外8000H-80FFH单元写入数据AB ····················································· 1 2. 将片内RAM20H单元中数据在数码管上显示出来······································ 1 3. 将片内ARM30H-40H单元清零 ······· 2 4. 将六位数显示在数码管上 ················ 2 5. 8255并口芯片的应用:交通灯控制系统的设计 ············································ 3 6. 将交通灯点亮 ······························· 3 7. AD转换实验 ································ 4 8. DA转换实验 ································ 5 9. 定时器的应用 ······························· 5 10. 开关控制LED的亮灭及速度 ········· 6 11. 计数器实验 ································ 6 12. 串并转换实验 ····························· 7 13. 直流电机速度检测 ······················· 7 14. 8255PB外接8个开关,编程将开关状态显示在数码管上(串并转换动态扫描方式) ··············································· 8 15. P3.4接开关K,编程将开关拨动次数,通过串并转换的方式进行显示 ············· 9 16. 比较片内RAM30H、31H两个单元值的大小,将较大的数显示在数码管上 ·· 10 17. 单片机P1口接8个开关,编程将开关状态显示在数码管上(串并转换动态扫描方式) ·········································· 10 18. 将片内50H单元的值显示在数码管上11 19. 开关K1接P1.0,K2接P1.1,编程实现当按下K1时在数码管上显示50H单元的值,按下K2在数码管上显示51H单元的值 ············································· 12

1. 将片外8000H-80FFH单元写入数据AB

ORG 0000H ;程序从0000H开始执行

AJMP MAIN ;跳转到主程序

ORG 0030H ;以免覆盖中断地址 MAIN: MOV SP,#60H; 避免堆栈和工作寄存器区冲突 MOV DPTR,#8000H MOV R0,#0 LOOP:

MOV A,#0ABH MOVX @DPTR,A

INC DPTR

INC R0

CJNE R0,#0,LOOP ; 判断

AJMP $; 等待

END ;调试-视图-M存储器(输入地址

X:8000H)

2. 将片内RAM20H单元中数据在数码管上显示出来 ORG 0000H ;程序从0000H开始执行

AJMP MAIN ;跳转到主程序

ORG 0030H

;以免覆盖中断地

址 MAIN: MOV SP,#60H ;避免堆栈和工作寄存器区冲突 MOV DPTR,#0E100H ;指向命令口地址

MOV A,#03H

;PA、PB口输出

MOVX @DPTR,A ;所有并口

显示程序先进行8155初始化

MOV 20H,#34H MOV A,20H

ACALL CHAI

LOOP: MOV R0,#10H ;第一个显示数的地址送R0

MOV R1,#2 ;显示2个数 MOV R2,#1 ;从倒数第一个数码管开始显示

ACALL DISPLAY LJMP LOOP ;判断

CHAI:

MOV B,#10H DIV AB MOV 10H,B MOV 11H,A

RET DISPLAY: MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET TAB: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

3. 将片内ARM30H-40H单元清零

ORG 0000H

;程序从0000H开始执

行 AJMP MAIN ;跳转到主程序

ORG 0030H

;以免覆盖中断地址

MAIN: MOV SP,#60H ;避免堆栈和工作寄存器区冲突 MOV R0,#30H MOV A,#0 LOOP:

MOV @R0,A INC R0

CJNE R0,#41H,LOOP ;判断

AJMP $ ;等待

END ;地址D:30H

4. 将六位数显示在数码管上 ORG 0000H ;程序从0000H开始执行

AJMP MAIN ;跳转到主程序

ORG 0030H

;以免覆盖中断地

址 MAIN: MOV SP,#60H ;避免堆栈和工作寄存器区冲突 MOV DPTR,#0E100H ;指向命令口地址

MOV A,#03H

;PA、PB口输出

MOVX @DPTR,A

;所有并口

显示程序先进行8155初始化 LOOP: MOV R0,#10H ;第一个显示数的

地址送R0 MOV 10H,#0H MOV 11H,#3H MOV 12H,#1H MOV 13H,#2H

MOV 14H,#1H MOV 15H,#1H MOV R1,#6 ;显示6个数 MOV R2,#1

;从倒数第一个数

码管开始显示

ACALL DISPLAY

LJMP LOOP DISPLAY: MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A

MOV ACC.0,C

ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET TAB: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

5. 8255并口芯片的应用:交通灯控制系统的设计 ORG 0000H AJMP START ORG 0030H

START:

MOV DPTR,#0AC03H

MOV A,#80H

MOVX @DPTR,A //8155初始化(所有并口显示中都要先8155初始化)

MOV R5,#0F0H ACALL DENG MOV R1,#20 ACALL DELAY MOV R0,#1 LOOP01:

MOV R5,#5AH ACALL DENG MOV R1,#100 ACALL DELAY

DJNZ R0,LOOP01

MOV R0,#3 // LED_2闪烁次数 LOOP02: MOV R5, #0FAH ACALL DENG MOV R1,#10 ACALL DELAY MOV R5,#50H ACALL DENG MOV R1,#10 ACALL DELAY DJNZ R0,LOOP02 MOV R5,#0A5H ACALL DENG MOV R1,#100 ACALL DELAY

MOV R0,#3 LOOP03: MOV R5, #0F5H ACALL DENG MOV R1,#10 ACALL DELAY MOV R5,#0A0H ACALL DENG MOV R1,#10 ACALL DELAY DJNZ R0,LOOP03

AJMP LOOP01

DENG:

MOV DPTR,#0AC00H //8155 PA口输出 MOV A,R5

MOVX @DPTR,A //8155 PA口送出显示参数

RET //100ms延时子程序 DELAY: MOV R7,#200 DEL: MOV R6,#229 DJNZ R6,$ DJNZ R7,DEL DJNZ R1,DELAY RET

END

6. 将交通灯点亮 ORG 0000H AJMP START

ORG 0030H

START:

MOV DPTR,#0AC03H MOV A,#80H MOVX @DPTR,A MOV DPTR,#0AC00H MOV A,#05AH MOVX @DPTR,A AJMP $

END

7. AD转换实验 ORG 0000 AJMP START ORG 000BH AJMP INT_0 ORG 0030H START:

MOV SP,#60H MOV TMOD,#01H MOV TH0,#4BH MOV TL0,#0FDH MOV R4,#2

SETB EA SETB ET0 SETB TR0

MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A MOV 22H,#9 MOV 23H,#0 MOV 24H,#8 MOV 25H,#0 LOOP:

MOV R0,#20H MOV R1,#6 MOV R2,#1 ACALL DISPLAY SJMP LOOP INT_0:

MOV TH0,#4BH MOV TL0,#0FDH DJNZ R4,EXIT PUSH ACC PUSH DPH PUSH DPL

MOV DPTR,#0A000H MOVX A,@DPTR MOV B,#10H

DIV AB

MOV 21H,A MOV 20H,B MOVX @DPTR,A MOV R4,#2

POP DPL POP DPH

POP ACC EXIT:

RETI DISPLAY:

MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A

MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8 RET

PBIT:

MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET DELAY: MOV R6,#4 DEL: MOV R7,#250

DJNZ R7,$ DJNZ R6,DEL

RET TAB:

DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

8. DA转换实验 ORG 0000 SJMP START ORG 0030H START: MOV SP,#60H MOV A,#0

LOOP1:

MOV DPTR,#0B000H MOVX @DPTR,A ACALL XS ACALL DELAY INC A

CJNE A,#0FFH,LOOP1 LOOP2: MOV DPTR,#0B000H MOVX @DPTR,A ACALL XS ACALL DELAY DEC A

CJNE A,#0,LOOP2 SJMP LOOP1 XS: PUSH ACC

MOV DPTR,#TAB MOV B,#51 DIV AB MOV R1,A XCH A,B MOV B,#5

DIV AB

MOVC A,@A+DPTR MOV R4,#8 ACALL S164 MOV A,R1

MOVC A,@A+DPTR MOV R4,#8 ACALL S164 MOV A,#0 CLR C MOV R4,#16

ACALL S164 POP ACC RET S164: RRC A MOV P1.0,C CLR P1.1 SETB P1.1 DJNZ R4,S164 RET

DELAY: MOV R7,#200

DEl: MOV R6,#229 DJNZ R6,$ DJNZ R7,DEL

RET TAB: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

9. 定时器的应用 ORG 0000H AJMP START ORG 00BH AJMP INT_0 ORG 0030H START:

MOV TMOD,#01H MOV TH0,#4BH MOV TL0,#0FDH MOV R0,#20 MOV R1,#0 SETB ET0 SETB TR0 SETB EA AJMP $ INT_0:

MOV TH0,#4BH MOV TL0,#0FDH DJNZ R0,EXIT MOV R0,#20 MOV A,R1 MOV DPTR,#TAB MOVC A,@A+DPTR MOV P1,A INC R1

CJNE R1,#8,EXIT

MOV R1,#0 EXIT: RETI TAB: DB

0FFH,0FAH,0F5H,0AFH,05FH,0AAH,55H,0H,0FF

H

END

10. 开关控制LED的亮灭及速度 ORG 0000H

;程序从0000H开始

执行

AJMP START ;跳转到主程序 ORG 0030H

;以免覆盖中断地

START: MOV R4,#1 ;立即数传送到累加器 LOOP: CLR P3.3 ;进位标志位清零 LOOP1: JNB P3.5,LOOP ;直接寻址位为0

则转移

JB P3.4,LOOP2 ;直接寻址位为1则转

移 JNB P3.4,$

INC R4 ;寄存器增1 LOOP2: CPL P3.3 ;累加器求反 MOV A,R4 ;寄存器内容传送到累加器A

MOV R5,A

;累加器内容传送到累

加器 ACALL DELAY ;调用延时函数

AJMP LOOP1 ;循环 DELAY: MOV R6,#200 DEL: MOV R7,#229 DJNZ R7,$

DJNZ R6,DEL ;寄存器减1,不为0则转移 DJNZ R5,DELAY RET ;子程序返回 END

11. 计数器实验 ORG 0000 SJMP START ORG 001BH LJMP INT_1 START:

MOV SP,#60H

MOV R5,#20

MOV TMOD,#15H MOV TH1,#4BH MOV TL1,#0FDH MOV TH0,#0 MOV TL0,#0 SETB ET1 SETB EA SETB TR1 SETB TR0

MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A LOOP:

MOV R0,#50H; MOV R1,#4 MOV R2,#1 LCALL DISPLAY

SJMP LOOP INT_1: MOV TH1,#4BH MOV TL1,#0FDH DJNZ R5,CON MOV R5,#20 PUSH ACC PUSH B MOV A,TL0 MOV B,#10H DIV AB MOV 50H,B MOV 51H,A MOV A,TH0 MOV B,#10H DIV AB MOV 52H,B MOV 53H,A MOV TH0,#0 MOV TL0,#0

POP B

POP ACC CON: RETI DISPLAY: MOV A,@R0

MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY

MOV A,#0

MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET

DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET TAB: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

12. 串并转换实验 ORG 0000 SJMP START ORG 0030H START:

MOV SP,#60H MOV R1,#0 MOV DPTR,#TAB

LOOP:

MOV A,#0

CLR C

MOV R4,#24 ACALL S164 MOV A,R1

MOVC A,@A+DPTR MOV R4,#8 ACALL S164 INC R1 MOV R5,#10 ACALL DELAY CJNE R1,#10,EXIT

MOV R1,#0 EXIT: SJMP LOOP S164: RRC A MOV P1.0,C CLR P1.1 SETB P1.1 DJNZ R4,S164

RET

DELAY: MOV R6,#200 DEL: MOV R7,#230 DJNZ R7,$ DJNZ R6,DEL DJNZ R5,DELAY RET

TAB:

DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H, 0FEH,0F6H

END

13. 直流电机速度检测 ORG 0000H AJMP MAIN ORG 001BH AJMP INT_1

ORG 0030H MAIN: MOV SP,#60H MOV TMOD,#15H MOV TH1,#4BH MOV TL1,#0FDH MOV R0,#20 MOV TH0,#0 MOV TL0,#0 SETB ET1

SETB EA

SETB TR0 SETB TR1

MOV R2,#00H

UP: MOV A,R2

MOV DPTR,#0A000H //注意片选接YC2,非YC3

MOVX @DPTR,A MOV R5,#1

ACALL DELAY ;100ms INC R2

CJNE R2,#0FFH,UP

DOWN:MOV A,R2

MOV DPTR,#0A000H MOVX @DPTR,A MOV R5,#1 ACALL DELAY ;100ms

DEC R2

CJNE R2,#00H,DOWN AJMP UP

INT_1: MOV TH1,#4BH

MOV TL1,#0FDH DJNZ R0,EXIT MOV R0,#20 PUSH ACC PUSH DPH PUSH DPL MOV A,TL0 ACALL XS MOV TL0,#0 MOV A,TH0 ACALL XS MOV TH0,#0 POP DPL POP DPH

POP ACC

EXIT: RETI

XS: MOV DPTR,#TAB ;MOV A,R2

MOV B,#10 ;显示10进制数 DIV AB XCH A,B ;MOV DPTR,#TAB MOVC A,@A+DPTR

ACALL FS

XCH A,B

;MOV DPTR,#TAB MOVC A,@A+DPTR ACALL FS

RET

FS: MOV R1,#8 YW:RRC A MOV P1.0,C CLR P1.1 SETB P1.1 DJNZ R1,YW

RET

DELAY:MOV R6,#200 DEL:MOV R7,#230 DJNZ R7,$ DJNZ R6,DEL DJNZ R5,DELAY

RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH END

14. 8255PB外接8个开关,编程将开关状态显示在数码管上(串并转换动态扫描方式) ORG 0000 AJMP START ORG 0030H

START:

MOV DPTR,#0AC03H MOV A, #82H MOVX @DPTR, A MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A LOOP:

MOV DPTR,#0AC01H MOVX A,@DPTR MOV B,#10H DIV AB MOV 10H,B MOV 11H,A MOV R0,#10H MOV R1,#2

MOV R2,#1

ACALL DISPLAY

SJMP LOOP

DISPLAY:MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET

DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

15. P3.4接开关K,编程将开关拨动次数,通过串并转换的方式进行显示 ORG 0000 SJMP START ORG 0030H START: MOV SP,#60H MOV R5,#0 LOOP:

JB P3.4,$ ACALL DELAY JB P3.4,LOOP INC R5 ACALL XS LOOP1:

JNB P3.4,$ ACALL DELAY JNB P3.4,LOOP1 INC R5 ACALL XS SJMP LOOP

DELAY: MOV R7,#200 DEL: MOV R6,#229

DJNZ R6,$ DJNZ R7,DEL RET

XS:

MOV DPTR,#TAB MOV A,R5 MOV B,#10H

DIV AB MOV R1,A

MOV A,B MOVC A,@A+DPTR MOV R4,#8 ACALL S164 MOV A,R1

MOVC A,@A+DPTR MOV R4,#8 ACALL S164 MOV A,#0 CLR C MOV R4,#16

ACALL S164 RET S164: RRC A MOV P1.0,C

CLR P1.1

SETB P1.1 DJNZ R4,S164 RET TAB: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB 0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

16. 比较片内RAM30H、31H两个单元值的大小,将较大的数显示在数码管上 ORG 0000 SJMP START ORG 0030H START:

MOV SP,#60H MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A

MOV 30H,#06H ;随便赋两个值,显示较大的

MOV 31H,#11H

MOV A,30H SUBB A,31H JC SMALL MOV B,#10H MOV A,30H DIV AB MOV 30H,B MOV 31H,A BIG: MOV R0,#30H

MOV R1,#2 MOV R2,#1 ACALL DISPLAY SJMP BIG SMALL: MOV B,#10H

MOV A,31H DIV AB MOV 30H,B MOV 31H,A SMALL1:MOV R0,#30H

MOV R1,#2 MOV R2,#1 ACALL DISPLAY

SJMP SMALL1

DISPLAY:MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET

DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

17. 单片机P1口接8个开关,编程将开关状态显示在数码管上(串并转换动态扫描方式)

ORG 0000H

SJMP START ORG 0030H START: MOV SP,#60H MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A LOOP:

MOV A,P1 MOV B,#10H DIV AB MOV 20H,B MOV 21H,A MOV R0,#20H MOV R1,#2 MOV R2,#1 ACALL DISPLAY

AJMP LOOP

DISPLAY:MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1: RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A

RL A

MOV R2,A

RET

DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

18. 将片内50H单元的值显示在数码管上 ORG 0000H SJMP START ORG 0030H START:

MOV SP,#60H

MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A LOOP:

MOV A,P1 MOV B,#10H DIV AB MOV 20H,B MOV 21H,A MOV R0,#20H MOV R1,#2 MOV R2,#1 ACALL DISPLAY

AJMP LOOP

DISPLAY:MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164: MOV DPTR,#TAB MOVC A,@A+DPTR P164_1:

RRC A

MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1 MOV 0FH,#8

RET

PBIT: MOV DPTR,#0E101H MOV A,R2 MOVX @DPTR,A RL A MOV R2,A

RET

DELAY: MOV R6,#4 DEL: MOV R7,#250 DJNZ R7,$ DJNZ R6,DEL

RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

19. 开关K1接P1.0,K2接P1.1,编程实现当按下K1时在数码管上显示50H单元的值,按下K2在数码管上显示51H单元的值 ORG 0000 SJMP START ORG 0030H

START: MOV SP,#60H

MOV DPTR,#0E100H MOV A,#3 MOVX @DPTR,A

MOV 50H,#18H ;50H,51H 随便赋两个值 MOV 51H,#22H LOOP:

JB P1.0,D50

JB P1.1,D51

SJMP LOOP D51: MOV R0,#10H

MOV R1,#2 MOV R2,#1 MOV A,51H MOV B,#10H DIV AB MOV 10H,B MOV 11H,A ACALL DISPLAY SJMP LOOP D50: MOV R0,#10H

MOV R1,#2 MOV R2,#1 MOV A,50H MOV B,#10H DIV AB MOV 10H,B MOV 11H,A ACALL DISPLAY

SJMP LOOP

DISPLAY:MOV A,@R0 MOV 0FH,#8 ACALL P164 ACALL PBIT ACALL DELAY MOV A,#0 MOVX @DPTR,A INC R0

DJNZ R1,DISPLAY

RET

P164:MOV DPTR,#TAB MOVC A,@A+DPTR P164_1:RRC A MOV R3,A MOV ACC.0,C ANL A,#0FDH MOV DPTR,#0E102H MOVX @DPTR,A ORL A,#0FEH MOVX @DPTR,A MOV A,R3 DJNZ 0FH,P164_1

MOV 0FH,#8

RET

PBIT:MOV DPTR,#0E101H MOV A,R2

MOVX @DPTR,A RL A MOV R2,A RET

DELAY:MOV R6,#4 DEL:MOV R7,#250 DJNZ R7,$

DJNZ R6,DEL RET

TAB:DB

0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H DB

0FEH,0F6H,0EEH,3EH,9CH,7AH,9EH,8EH

END

本文来源:https://www.bwwdw.com/article/34m5.html

Top