waveout bit p3.7 ORG 0000H AJMP MAIN ORG 000BH AJMP T0IN ORG 0013H AJMP SAVE ORG 0100H
MAIN: MOV SP,#7FH
START: CLR EA ACALL BUFF ACALL DISP ACALL SETT ACALL SETINT SETB EA ACALL waveSEND ACALL D10MS ACALL D10MS AJMP START
BUFF: MOV 30H,#00H mov 31h,#00h mov 32h,#00h mov 33h,#00h mov 34h,#00h mov 35h,#00h RET
setT: MOV TMOD,#01H ;T0 方式1定时 T1方式1定时 MOV TL0,#00H MOV TH0,#00H SETB ET0 SETB TR0 RET setint: SETB EX1 RET
T0IN: NOP CLR EA ACALL BUFF ACALL DISP RETI
wavesend:MOV R0,#10h WAV10: setb waveout nop nop nop nop nop nop nop nop nop nop NOP clr waveout nop nop nop nop nop nop nop nop NOP djnz r0,wav10 RET
SAVE: NOP CLR TR0 CLR EA MOV R2,TH0 MOV R3,TL0 ACALL BCD acall disp ACDLL D10MS RETI
BCD: mov r6,#0 ;求出距离 mov r7,#15 ;声速 acall qmul mov a,r6 mov r2,a mov a,r7 mov r3,a ;结果存入r2r3 acall ibtd2 mov a,r6 anl a,#0fh mov 35h,a mov a,r6 anl a,#0f0h swap a mov 34h,a mov a,r5 anl a,#0fh mov 33h,a mov a,r5 anl a,#0f0h swap a mov 32h,a mov a,r4 anl a,#0fh mov 31h,a ret sub1: mov 31h,#00h mov 32h,#00h mov 33h,#00h mov 34h,#00h mov 35h,#00h ret
;********************************* ;* 双字节HEX->BCD * ;* 入口:R2R3为双字节16位二进制数 * ;* 出口:R4R5R6为转换完的压缩BCD * ;********************************* IBTD2: CLR A MOV R4,A MOV R5,A MOV R6,A MOV R7,#16 LM_BCD: CLR C MOV A,R3 RLC A MOV R3,A MOV A,R2 RLC A MOV R2,A MOV A,R6 ADDC A,R6 DA A MOV R6,A MOV A,R5 ADDC A,R5 DA A MOV R5,A MOV A,R4 ADDC A,R4 DA A MOV R4,A DJNZ R7,LM_BCD RET ;-------------------------------- ;无符号双字节快速乘法 ;-------------------------------- ;功能:(R2R3)*(R6R7)->(R4R5R6R7) ;入口:R2R3中存放被乘数,R6R7中存放乘数 ;出口:积存放在R4R5R6R7中 QMUL: MOV A,R3 MOV B,R7 MUL AB ;(R3)*(R7) XCH A,R7 ;(R7)=(R3*R7)L MOV R5,B ;(R7)=(R3*R7)H MOV B,R2 MUL AB ;(R2)*(R7) ADD A,R5 MOV R4,A CLR A ADDC A,B MOV R5,A ;(R5)=(R2*R7)H MOV A,R6 MOV B,R3 MUL AB ;(R3)*(R6) ADD A,R4 XCH A,R6 XCH A,B ADDC A,R5 MOV R5,A MOV F0,C ;暂存Cy MOV A,R2 MUL AB ;(R2)*(R6) ADD A,R5 MOV R5,A CLR A MOV ACC.0,C MOV C,F0 ;加以前加法的进位 ADDC A,B MOV R4,A RET d10ms: mov r5,#20 lp_dl2: mov r7,#200 lp_dl1: mov r6,#203 djnz r6,$ djnz r7,lp_dl1 djnz r5,lp_dl2 ret
DISP: CLR RS1 ;第2组工作区 SETB RS0 MOV SCON,#00H MOV R0,#35h MOV R1,#6 LP_D: MOV DPTR,#TAB MOV A,@R0 MOVC A,@A+DPTR CJNE R1,#3,DN ANL A,#7FH ;7F显示小数点 DN: MOV SBUF,A JNB TI,$ CLR TI DEC R0 DJNZ R1,LP_D CLR RS1 CLR RS0 RET TAB: DB 0C0H,0F9H,0A4H,0B0H,99H ;01234 DB 92H,82H,0F8H,80H,90H ;56789 ;DB 88H,83H,0C6H,0A1H,86H,8EH ;ABCDEF DB 0C7H,8CH,0C1H,89H,0FFH ;LPUH灭码
END |