51单片机实验及代码

内容发布更新时间 : 2024/11/9 2:09:54星期一 下面是文章的全部内容请认真阅读。

.

MOVX @DPTR,A MOV A,R1 RR A

MOV R1,A LCALL DLEY

MOV DPTR,#8002H MOV A,R1

MOVX @DPTR,A

.

MOV DPTR,#8004H MOV A,R3

MOVX @DPTR,A MOV A,R1 RR A

MOV R1,A LCALL DLEY INC R0

CJNE R0,#33H,BCD LJMP MAIN CTAB:

PUSH DPH PUSH DPL

MOV DPTR,#TAB MOVC A,@A+DPTR POP DPL POP DPH RET TAB: DB

3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H DLEY:

MOV R7,#02H DL:MOV R6,#0FFH DL1:DJNZ R6,DL1 DJNZ R7,DL RET END

.

(2)扫描矩阵键盘,将对应键盘值送LED显示

.

ORG 0000H

LJMP START ORG 1000H START:

ACALL KEY1 AJMP START KEY1: ACALL KEY14 JNZ KEY3

KEY2: ACALL KEY16 AJMP KEY1 KEY3: ACALL KEY16 ACALL DELAY ACALL KEY14 JNZ KEY4 ACALL KEY16 AJMP KEY1

KEY4: MOV R2, #0FEH MOV R4, #00H

KEY5: MOV DPTR,#8002H MOV A, R2 MOVX @DPTR, A MOV DPTR,#8001H MOVX A,@DPTR JB ACC.0,KEY6 MOV A, #00H AJMP KEY9

KEY6: JB ACC.1,KEY7 MOV A, #06H AJMP KEY9

KEY7: JB ACC.2,KEY8 MOV A, #0CH AJMP KEY9

KEY8: JB ACC.3, KEY12 MOV A, #12H KEY9: ADD A, R4 KEY10: MOV R5,A KEY11: ACALL KEY14

.

JNZ KEY11 MOV A,R5 ACALL KEY15 RET

KEY12: INC R4 MOV A, R2

JNB ACC.5,KEY13 RL A

.

MOV R2, A AJMP KEY5

KEY13: AJMP KEY1

KEY14: MOV DPTR,#8002H MOV A,#00H MOVX @DPTR,A MOV DPTR,#8001H MOVX A,@DPTR CPL A

ANL A, #0FH RET

KEY15: MOV DPTR,#TABLE MOVC A,@A+DPTR MOV R3,A

KEY16: MOV DPTR,#8002H MOV A,#01H MOVX @DPTR,A

MOV DPTR,#8004H MOV A,R3 MOVX @DPTR,A ACALL DELAY RET

DELAY: MOV R7,#12 LOOP: MOV R6,#250 DJNZ R6,$ DJNZ R7,LOOP RET TABLE:

DB

7EH,7EH,5EH,79H,71H,3FH,7EH,7EH,39H,4FH,5BH,06H,

.

7EH,7EH,7CH,7DH,6DH,66H ,7EH,7EH,77H,6FH,7FH,07H

END

实验六:D/A和A/D

(1)利用实验箱上的电位器提供模拟量输入,将模拟量转换成二进制数字量,将转换的结果用P1口输出到二极管显示;

ORG 0000H LJMP MAIN ORG 0100H

MAIN:

MOV DPTR,#8000H MOV A,#00H MOVX @DPTR,A MOV R2,#100 DJNZ R2,$ MOVX A,@DPTR MOV P1,A LJMP MAIN

END

(2)用DAC0832将一个数值转换为模拟电压,该模拟电压接ADC0809的一个模拟输入进行模/数转换,转换结果通过P1口送到二极管显示。

ORG 0000H

LJMP MAIN ORG 0100H

MAIN:

MOV A,#90H MOV DPTR,#9000H MOVX @DPTR,A MOV DPTR,#8000H MOVX @DPTR,A MOV R2,#64H DJNZ R2,$

.

.

MOVX A,@DPTR MOV P1,A SJMP $ END

实验七:电子钟

实现一个24小时制的电子钟程序,在6个数码管上显示时分秒(用定时器0中断更新计时,以压缩BCD码形式保存在内部RAM的30H、31H和32H单元);可以通过串行口调时!

ORG 0000H

AJMP MAIN ORG 000BH LJMP CLOCK ORG 0023H LJMP INPUT ORG 0100H

MAIN:

MOV TMOD,#21H CLR A MOV 30H,A MOV 31H,A MOV 32H,A

MOV TH0,#3CH MOV TL0,#0B0H

MOV 50H,#14H ;50 * 20 MOV TH1,#0F3H

MOV TL1,#0F3H ;波特率

MOV SCON,#50H SETB PS

MOV IE,#92H SETB TR1 SETB TR0 SLED:

MOV R0,#30H MOV R1,#20H LJMP LED

.

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4 ceshi