⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 电压表(最大-瞬时-最小).asm

📁 基于841的电压表小程序
💻 ASM
字号:
   $MOD841
;using 30h-32h to store the instant result,33h-35h to store the biggest value,36h-38h to store the smallest value
        CHAN  EQU   00H
        CSEG
        SP0   EQU   50H
        CLK81 EQU   P3.5
        DAT81 EQU   P3.3
        RESH	EQU	39H
        RESL	EQU	3AH
        KEYVAL	EQU	3BH
        MOSTH	EQU	3CH
        MOSTL	EQU	3DH
        LEASTH	EQU	3EH
        LEASTL	EQU	3FH
	TRANSH	EQU	40H
	TRANSL	EQU	41H
	STOREPOINT	EQU	42H
;--------------------------------------
        ORG    0000H
        LJMP   MAIN
        ORG    0003H
        LJMP   KEY_SERVER
        ORG    0033H
        LJMP   ADI_SERVER
        ORG    0060H
MAIN:   MOV    R0,#0FFH
        CLR    A
QING:   MOV    @R0,A
        DJNZ   R0,QING
        MOV    SP,#SP0
        LCALL  YS
;---------------------------------------
        LCALL  INI8281
        LCALL  INI841
HERE:	JMP	$
;---------------------------------------
INI841:
	MOV    ADCCON1,#0A8H
        MOV    ADCCON2,#CHAN
        MOV    ADCCON3,#07H
        SETB   EA
        SETB   EX0
        SETB   PADC
        CLR    PX0
        RET
;----------------------------------------
INI8281:SETB   CLK81
        SETB   DAT81
        MOV    A,#12H
        LCALL  WTO81
        MOV    A,#80H
        LCALL  WTO81
        RET
;----------------------------------------

KEY_SERVER:
	MOV	A,#93H
	LCALL	WTO81
	LCALL	RDKEYVAL
	SETB   ADCCON2.4
	SETB   EADC
        RETI
ADI_SERVER:                     ;CARE: Firstly you must give value to the least(H/L)
	CLR	EADC
       	MOV    RESL,ADCDATAL
        MOV    RESH,ADCDATAH
        ;MOV	RESL,#0FFH
        ;MOV	RESH,#0FH
        MOV	A,MOSTH
        CJNE	A,RESH,CHECKMH
        MOV	A,MOSTL
	CJNE	A,RESL,CHECKML
        MOV	MOSTH,RESH
        MOV	MOSTL,RESL
        LJMP	ADEND
CHECKMH:			;check largest number's high bit
        JNC	CHECKL
        MOV     MOSTH,RESH
        MOV	MOSTL,RESL
        LJMP	ADEND
CHECKML:
	JNC	CHECKL
	MOV	MOSTH,RESH
	MOV	MOSTL,RESL
	LJMP	ADEND
CHECKL:
	MOV	A,LEASTL
	JNZ	CHECKLCON		;if LEASTL is zero then move current value to it,this happen at the first time
	MOV	A,LEASTH
	JNZ	CHECKLCON
	MOV     LEASTH,RESH
	MOV	LEASTL,RESL
	LJMP 	ADEND
CHECKLCON:
        MOV	A,LEASTH
        CJNE	A,RESH,CHECKLH
        MOV	A,LEASTL
        CJNE	A,RESL,CHECKLL
        MOV	LEASTH,RESH
        MOV	LEASTL,RESL
        LJMP	ADEND
CHECKLH:
	JC      ADEND
	MOV	LEASTH,RESH
        MOV	LEASTL,RESL
        LJMP	ADEND
CHECKLL:
	JC	ADEND
	MOV	LEASTH,RESH
	MOV	LEASTH,RESL
ADEND:
	LCALL  PROCESS
        ;LCALL  MYDIS
	LCALL	DISALL
RETI

PROCESS:
	MOV	R1,#30H		;init the memory to store the result
	MOV	R0,#9
	CLR	A
INITRESMEMO:
	MOV	@R1,A
	INC	R1
	DJNZ	R0,INITRESMEMO
	MOV	R3,#0FFH        ; R3 is a shift bit counter from 0 to 11
	MOV	TRANSH,RESH
	MOV	TRANSL,RESL
	MOV	STOREPOINT,#30H
	LCALL	BEGSHIFT
	MOV	R3,#0FFH
	MOV	TRANSH,MOSTH
	MOV	TRANSL,MOSTL
	MOV	STOREPOINT,#33H
	LCALL	BEGSHIFT
	MOV	R3,#0FFH
	MOV	TRANSH,LEASTH
	MOV	TRANSL,LEASTL
	MOV	STOREPOINT,#36H
	LCALL	BEGSHIFT
RET

BEGSHIFT:
        CLR	C
        MOV	A,TRANSH
        RRC	A
        MOV	TRANSH,A
        MOV	A,TRANSL
        RRC	A
        MOV	TRANSL,A
        INC	R3
        JC	ADDTAB          ;if the bit is 1 then add the table value else continue shift
        LJMP	SHIFTEND
ADDTAB:
	MOV	R4,#03H         ;preserve the offset of value in one table
	MOV	R0,STOREPOINT         ;preserve the entrance address of the display result
	MOV	DPTR,#TAB
	CLR	C
	MOV	A,R3
	MOV	B,#3
	MUL	AB      	;WARNNING!!!! MUL can change PSW.7(or C) bit
	MOV     R7,A

TABLOOP:                        ;WARNNING!!!!In this area C can only changed by DA
        MOV	A,R7            ;calculate the proper table entrance
       	MOVC	A,@A+DPTR
	MOV	B,@R0
	ADDC	A,B
      	DA	A
	MOV	@R0,A
      	INC	DPTR
	INC	R0
	DJNZ	R4,TABLOOP   	;using DJNZ not CJNE because the latter one can change C
SHIFTEND:
	CJNE	R3,#11,BEGSHIFT
RET

MYDIS:
MOV	A,#14H
LCALL	WTO81
MOV     A,30H
ANL	A,#0FH
ORL	A,#70H
LCALL	WTO81

MOV	A,#14H
LCALL	WTO81
MOV	A,30H
ANL	A,#0F0H
SWAP	A
ORL	A,#60H
LCALL	WTO81

MOV	A,#14H
LCALL	WTO81
MOV	A,31H
ANL	A,#0FH
ORL	A,#50H
LCALL	WTO81

MOV	A,#14H
LCALL	WTO81
MOV	A,31H
ANL	A,#0F0H
SWAP	A
ORL	A,#40H
LCALL	WTO81

MOV	A,#14H
LCALL	WTO81
MOV	A,32H
ANL	A,#0FH
ORL	A,#30H
LCALL	WTO81

MOV	A,#02H
LCALL	WTO81
MOV	A,32H
ANL	A,#0F0H
SWAP	A
MOV	DPTR,#MYTABLE
MOVC	A,@A+DPTR
LCALL	WTO81
RET

DISALL:			;35H34H33H	32H31H30H	38H37H36H
MOV	A,#00H	;TO display the biggest value
LCALL	WTO81
MOV	A,35H
ANL	A,#0F0H
SWAP	A
MOV	DPTR,#MYTABLE
MOVC	A,@A+DPTR
LCALL	WTO81
MOV	A,#14H
LCALL	WTO81
MOV	A,35H
ANL	A,#0FH
ORL	A,#10H
LCALL	WTO81

MOV	A,#03H	;TO display the instant value
LCALL	WTO81
MOV	A,32H
ANL	A,#0F0H
SWAP	A
MOV	DPTR,#MYTABLE
MOVC	A,@A+DPTR
LCALL	WTO81
MOV	A,#14H
LCALL	WTO81
MOV	A,32H
ANL	A,#0FH
ORL	A,#40H
LCALL	WTO81

MOV	A,#06H	;TO display the smallest value
LCALL	WTO81
MOV	A,38H
ANL	A,#0F0H
SWAP	A
MOV	DPTR,#MYTABLE
MOVC	A,@A+DPTR
LCALL	WTO81
MOV	A,#14H
LCALL	WTO81
MOV	A,38H
ANL	A,#0FH
ORL	A,#70H
LCALL	WTO81
RET

WTO81:	MOV	R6,#08H
WAT:	CLR	CLK81
	LCALL	DELAY
	SETB	CLK81
	JB	DAT81,WAT
	CLR	CLK81
	LCALL	DELAY
	SETB	CLK81
	JNB	DAT81,$
WTB81:	RLC	A
	MOV	DAT81,C
        CLR	CLK81
	LCALL	DELAY
	SETB	CLK81
	LCALL	DELAY
	LCALL	DELAY
	DJNZ	R6,WTB81
	SETB	DAT81
        RET

RDKEYVAL:
	CLR	CLK81
	LCALL	DELAY
	SETB	CLK81   ; P3.5
	JB	DAT81,$ ; P3.3
  	CLR	CLK81
	LCALL	DELAY
	SETB	CLK81
  	MOV	R6,#08H
RD1:
   LCALL	DELAY
   LCALL	DELAY
   LCALL	DELAY
   MOV	C,DAT81
   LCALL	DELAY
   RLC	A
   CLR	CLK81
   LCALL	DELAY
   SETB	CLK81
   DJNZ	R6,RD1
   MOV	KEYVAL,A
   RET
;----------------------------------------------
DELAY:  NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        RET
YS:
	MOV     R5,#00H
        MOV     R4,#50H
YS1:    DJNZ    R5,$
        DJNZ    R4,YS1
        RET

TAB:                                    ;every three value is one display bit's power and its sequence is from LOW bit to HIGH
        DB 22H,10H,00H,24H,01H,00H      ;000183
	DB 44H,02H,00H,88H,04H,00H      ;000244
	DB 76H,09H,00H,53H,19H,00H
    	DB 06H,39H,00H,12H,78H,00H
    	DB 25H,56H,01H,50H,12H,03H
    	DB 00H,25H,06H,00H,50H,12H
MYTABLE:
DB	40H,79H,24H,30H,19H,12H,02H,78H,00H,10H
END


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -