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

📄 fantest.asm

📁 用汇编语言写的风扇转速测试程序,用于转速测试,传感器用KEYENCE
💻 ASM
📖 第 1 页 / 共 4 页
字号:
         JC LEDOFF
	 MOV C, P0.1
	 JC LEDOFF
         SETB P0.2
	 JMP LED
LEDOFF:  CLR P0.2
LED:     RET
/*************** send data to PC through RS232  *************************************/
SEND:  CLR ES
       MOV A, #0A5H
       MOV SBUF, A
SEND0: JBC   TI,SEND1
       JMP SEND0
SEND1: MOV A, #5AH
       MOV   SBUF, A
SEND2: JBC   TI,SEND3
       JMP SEND2
SEND3: MOV R1, #6BH        ;Send display vaule
       MOV R5, #8
SEND4: MOV A, @R1
       ORL A, #30H
       MOV SBUF, A
SEND5: JBC TI, SEND6
       JMP SEND5
SEND6: DEC R1
       DJNZ R5, SEND4
       MOV A, 2DH         ; Send "0.00"
       ORL A, #30H
       MOV   SBUF, A
SEND7: JBC   TI,SEND8
       JMP SEND7
SEND8: MOV A, 2CH
       ORL A, #30H
       MOV   SBUF, A
SEND9: JBC   TI,SENDH
       JMP SEND9
SENDH: MOV R0, #48H       ; Send upper limit
       MOV R6, #5
SENDH1:MOV A, @R0 
       ORL A, #30H
       MOV SBUF, A
SENDH2:JBC TI, SENDH3
       JMP SENDH2
SENDH3:DEC R0
       DJNZ R6, SENDH1
       MOV R1, #4DH       ; Send lower limit
       MOV R7, #5
SENDL1:MOV A, @R1
       ORL A, #30H
       MOV SBUF, A
SENDL2:JBC TI, SENDL3
       JMP SENDL2
SENDL3:DEC R1
       DJNZ R7, SENDL1
SEND10:MOV A, #5AH
       MOV SBUF, A
SEND11:JBC   TI,SEND12
       JMP SEND11
SEND12:MOV A, #0A5H
       MOV   SBUF, A
SEND13:JBC   TI,SEND14
       JMP SEND13
SEND14:SETB ES
       RET
/*************** write Fan Q'ty to 02h 24c02 *************************************/
BYTE_FILL:
         MOV B, #120                   ; re-try counter
X52:     MOV A, #PADDR                ;  programable addr=0, paddr=0, a=0        
         LCALL WRITE_BYTE              ;  try to write
	 JNC X53                       ;  jump x53 if write ok
	 DJNZ B, X52                   ;  try again
	 SETB C                        ;  set time out error flag
	 JMP X54
X53:     CLR C                         ; clear error flag
X54:     RET
WRITE_BYTE:
         RL A                     ;a=00h, RL while,  still a=0, c=0
	 ORL A, #DADDR            ;a=a0h, write device address
	 CLR ACC.0                ;write commands, a=10100000h
	 LCALL START
	 JC X49
         LCALL SHOUT
	 JC X48
         MOV A, #02H               ; write rom address	 
	 LCALL SHOUT
	 JC X48
	 MOV A, 5FH                ; write a byte data 	 
	 LCALL SHOUT
	 JC X48
	 LCALL STOP
         CLR C                     ; write ok c=0, fail c=1
         JMP X49
X48:     LCALL STOP
X49:     RET
/*************** read Fan Q'ty from 02h 24c02 *************************************/
VERIFY_BYTE_FILL:                        ; Single byte read
         MOV B, #120                      ; retry counter
X81:     MOV A, #PADDR                   ; programmable address(0--7)
         LCALL READ_RANDOM               ; try to read
	 JNC X82                         ; jump X82 if read ok
	 DJNZ B, X81                     ; try again
	 SETB C
	 JMP X83                         ; set error flag and exit
X82:     CLR C                           ; clr error flag
X83:     RET

READ_RANDOM:                             ; 24C02 random read func
         PUSH B                          ; init value B=120
	 MOV B, A                        ; A=#PADDR, B=#PADDR	 
	 RL A                            ; programmable address to bit 3:1
	 ORL A, #DADDR                   ; add fixed address
	 CLR ACC.0                       ; Write operation
	 LCALL START
	 JC X47                          ; abort if bus not available
         LCALL SHOUT
	 JC X46                          ; Abort if no ACK signal
	 MOV A, #02H                      ; send rom address
	 LCALL SHOUT
	 JC X46
         MOV A, B                         ; A=#PADDR 
	 LCALL READ_CURRENT               ; Call current address read function
         JMP X47
X46:     LCALL STOP
X47:     POP B
         RET
READ_CURRENT:                             ; 24c02 read current address func
         RL A                             ; programmable address to bit 3:1
	 ORL A, #DADDR
	 SETB ACC.0                       ; READ func
	 LCALL START
	 JC X45                           ; abort if bus not available
	 LCALL SHOUT                      ; send device address
	 JC X44                           ; Abort if no ACK signal
	 LCALL SHIN                       ; receive data byte
	 MOV 4FH, A                      ; re-save data which read from rom 00h
	 LCALL NAK                        ; send do not acknowledge byte
         LCALL STOP
         CLR C                            ; write ok c=0, fail c=1
         JMP X45
X44:     LCALL STOP
X45:     RET
/*************** write H limit to 03h 24c02 *************************************/
                                         ; Fill every byte in a 24c02 with same value
                                         ; write one page at time
PAGE_FILL_HI:				 ; Return CY set to indicate write time out
         MOV B, #120
X63:	 MOV A, #PADDR                   ; programmable address
	 LCALL WRITE_BLOCK_HI               ; try write
	 JNC X64                         ; jump x64 if write ok
	 DJNZ B, X63                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X66
X64:	 CLR C                           ; clr error flag
X66:     RET 
        ; Write from a byte to one page of data to an 24c02
        ; Called with programmable address in A, address of first byte
	; Does not wait for write cycle to complete
WRITE_BLOCK_HI:	 
	 RL A
	 ORL A, #DADDR
	 CLR ACC.0
	 LCALL START                      ;Write into device address
	 JC X38
	 CALL SHOUT
	 JC X37
	 MOV A, #03H                       ; Write into rom address, from 00h to ffh unit        
	 LCALL SHOUT
	 JC X37
	 MOV R3, #5                      ; byte per page, kount=8
	 MOV R1, #59H                    ; get data from 59h unit
X36:     MOV A, @R1                      ; Write 8 byte data continoius to i2c rom
         LCALL SHOUT
	 JC X37                          ; receive ACK signal
	 INC R1
	 DJNZ R3, X36
         LCALL STOP
         CLR C                           ; write ok c=0, fail c=1
         JMP X38	
X37:     LCALL STOP
X38:     RET
/*************** write L limit to 0Ah 24c02 *************************************/   
PAGE_FILL_LO:				 ; Return CY set to indicate write time out
         MOV B, #120
X63L:	 MOV A, #PADDR                   ; programmable address
	 LCALL WRITE_BLOCK_LO            ; try write
	 JNC X64L                        ; jump x64 if write ok
	 DJNZ B, X63L                    ; try again
	 SETB C                          ; set timeout error flag
	 JMP X66L
X64L:	 CLR C                           ; clr error flag
X66L:    RET 
        ; Write from a byte to one page of data to an 24c02
        ; Called with programmable address in A, address of first byte
	; Does not wait for write cycle to complete

WRITE_BLOCK_LO:	 
	 RL A
	 ORL A, #DADDR
	 CLR ACC.0
	 LCALL START                      ;Write into device address
	 JC X38L
	 CALL SHOUT
	 JC X37L
	 MOV A, #0AH                       ; Write into rom address, from 00h to ffh unit        
	 LCALL SHOUT
	 JC X37L
	 MOV R3, #5                      ; byte per page, kount=8
	 MOV R1, #59H                    ; get data from 5Ah unit
X36L:    MOV A, @R1                      ; Write 8 byte data continoius to i2c rom
         LCALL SHOUT
	 JC X37L                          ; receive ACK signal
	 INC R1
	 DJNZ R3, X36L
         LCALL STOP
         CLR C                           ; write ok c=0, fail c=1
         JMP X38L	
X37L:    LCALL STOP
X38L:    RET 
/*************** Read H limit from 03h 24c02 *************************************/  
                                     ; Verify that all byte in a 24c02 match a fill value
                                     ; read and verify one page at a time
VERIFY_PAGE_HI:		             ; Copy device page to buffer
X71:	 MOV A, #PADDR                   ; programmable address
	 LCALL READ_BLOCK_HI             ; try write
	 JNC X72                         ; jump x74 if write ok
	 DJNZ B, X71                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X73
X72:     CLR C
X73:     RET   
                                         ; read from one byte to one page of data from 24c02
                                          ; Perform a Random read which is extended into a sequential read
	 		                  ; when more than one byte is read, Called with programmable address
READ_BLOCK_HI:  	 		  ; in A, address of first byte in register pair ADDR_HI: ADDR_LO
	 RL A				  ; byte count in register kount
	 ORL A, #DADDR			  ; Return data in buffer
	 MOV R5, A
	 CLR ACC.0
	 LCALL START 
	 JC X35	
	 LCALL SHOUT                      ; Write into device address
	 JC X34
	 MOV A, #03H
	 CALL SHOUT                       ; Write rom address
	 JC X34
	 MOV A, R5
	 SETB ACC.0                       ; send read command and receive data
	 LCALL START
	 JC X34
	 LCALL SHOUT                      ; Re-write device address
	 JC X34
	 MOV R4, #5                       ; byte Q'TY per page
	 MOV R0, #44H                     ; Save data which Read from I2c Rom to 44h--48h unit  
X31:     LCALL SHIN                       ; Read 8 time from rom
         MOV @R0, A
	 CJNE R4, #1, X32
	 LCALL NAK
	 JMP X33
X32:     CALL ACK
         INC R0
	 DJNZ R4, X31
X33:     LCALL STOP
         CLR C
	 JMP X35
X34:     LCALL STOP
X35:     RET  
/*************** write L limit to 0Ah 24c02 *************************************/
VERIFY_PAGE_LO:		                 ; Copy device page to buffer
X71L:	 MOV A, #PADDR                   ; programmable address
	 LCALL READ_BLOCK_LO             ; try write
	 JNC X72L                         ; jump x74 if write ok
	 DJNZ B, X71L                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X73L
X72L:    CLR C
X73L:    RET   
                                          ; read from one byte to one page of data from 24c02
                                          ; Perform a Random read which is extended into a sequential read
	 		                  ; when more than one byte is read, Called with programmable address
READ_BLOCK_LO:  	 		  ; in A, address of first byte in register pair ADDR_HI: ADDR_LO
	 RL A				  ; byte count in register kount
	 ORL A, #DADDR			  ; Return data in buffer
	 MOV R6, A
	 CLR ACC.0
	 LCALL START 
	 JC X35L	
	 LCALL SHOUT                      ; Write into device address
	 JC X34L
	 MOV A, #0AH
	 CALL SHOUT                       ; Write rom address
	 JC X34L
	 MOV A, R6
	 SETB ACC.0                       ; send read command and receive data
	 LCALL START
	 JC X34L
	 LCALL SHOUT                      ; Re-write device address
	 JC X34L
	 MOV R4, #5                       ; byte Q'TY per page
	 MOV R0, #49H                     ; Save data which Read from I2c Rom to 49h--4Dh unit  
X31L:    LCALL SHIN                       ; Read 8 time from rom
         MOV @R0, A
	 CJNE R4, #1, X32L
	 LCALL NAK
	 JMP X33L
X32L:    CALL ACK
         INC R0
	 DJNZ R4, X31L
X33L:    LCALL STOP
         CLR C
	 JMP X35L
X34L:    LCALL STOP
X35L:    RET  
/*************** write data value to 10h 24c02 *************************************/
PAGE_FILL_SAVE:				 ; Return CY set to indicate write time out
         MOV B, #120
X631:	 MOV A, #PADDR                   ; programmable address
	 LCALL WRITE_BLOCK_SAVE               ; try write
	 JNC X641                         ; jump x64 if write ok
	 DJNZ B, X631                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X661
X641:	 CLR C                           ; clr error flag
X661:     RET 
        ; Write from a byte to one page of data to an 24c02
        ; Called with programmable address in A, address of first byte
	; Does not wait for write cycle to complete

WRITE_BLOCK_SAVE:	 
	 RL A
	 ORL A, #DADDR
	 CLR ACC.0
	 LCALL START                      ;Write into device address
	 JC X381
	 CALL SHOUT
	 JC X371
	 MOV A, #10H                       ; Write into rom address, from 00h to ffh unit        
	 LCALL SHOUT
	 JC X371
	 MOV R3, #5                      ; byte per page, kount=8
	 MOV R1, #64H                    ; get data from 67h unit
X361:    MOV A, @R1                      ; Write 8 byte data continoius to i2c rom
         LCALL SHOUT
	 JC X371                          ; receive ACK signal
	 INC R1
	 DJNZ R3, X361
         LCALL STOP
         CLR C                           ; write ok c=0, fail c=1
         JMP X381	
X371:     LCALL STOP
X381:     RET
/*************** read value from 10h 24c02 *************************************/
                                     ; Verify that all byte in a 24c02 match a fill value
                                     ; read and verify one page at a time
VERIFY_PAGE_SAVE:		             ; Copy device page to buffer
X712:	 MOV A, #PADDR                   ; programmable address
	 LCALL READ_BLOCK_SAVE             ; try write
	 JNC X722                         ; jump x74 if write ok
	 DJNZ B, X712                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X732
X722:     CLR C
X732:     RET   
                                          ; read from one byte to one page of data from 24c02
                                          ; Perform a Random read which is extended into a sequential read
	 		                  ; when more than one byte is read, Called with programmable address
READ_BLOCK_SAVE:  	 		  ; in A, address of first byte in register pair ADDR_HI: ADDR_LO
	 RL A				  ; byte count in register kount
	 ORL A, #DADDR			  ; Return data in buffer
	 MOV R5, A
	 CLR ACC.0
	 LCALL START 
	 JC X352	
	 LCALL SHOUT                      ; Write into device address
	 JC X342
	 MOV A, #10H
	 CALL SHOUT                       ; Write rom address
	 JC X342
	 MOV A, R5
	 SETB ACC.0                       ; send read command and receive data
	 LCALL START
	 JC X342
	 LCALL SHOUT                      ; Re-write device address
	 JC X342
	 MOV R4, #5                       ; byte Q'TY per page
	 MOV R0, #64H                     ; Save data which Read from I2c Rom to 44h--48h unit  
X312:    LCALL SHIN                       ; Read 8 time from rom
         MOV @R0, A
	 CJNE R4, #1, X322
	 LCALL NAK
	 JMP X332
X322:    CALL ACK
         INC R0
	 DJNZ R4, X312
X332:    LCALL STOP
         CLR C
	 JMP X352
X342:    LCALL STOP
X352:    RET 
/*************** write data value (dot) to 16h 24c02 *************************************/
PAGE_FILL_SAVE1:				 ; Return CY set to indicate write time out
         MOV B, #120
X6311:	 MOV A, #PADDR                   ; programmable address
	 LCALL WRITE_BLOCK_SAVE1               ; try write
	 JNC X6411                         ; jump x64 if write ok
	 DJNZ B, X6311                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X6611
X6411:	 CLR C                           ; clr error flag
X6611:   RET 
; Write from a byte to one page of data to an 24c02
; Called with programmable address in A, address of first byte
; Does not wait for write cycle to complete
WRITE_BLOCK_SAVE1:	 
	 RL A
	 ORL A, #DADDR
	 CLR ACC.0
	 LCALL START                      ;Write into device address
	 JC X3811
	 CALL SHOUT
	 JC X3711
	 MOV A, #16H                       ; Write into rom address, from 00h to ffh unit        
	 LCALL SHOUT
	 JC X3711
	 MOV R3, #2                      ; byte per page, kount=8
	 MOV R1, #2CH                    ; get data from 67h unit
X3611:    MOV A, @R1                      ; Write 8 byte data continoius to i2c rom
         LCALL SHOUT
	 JC X3711                          ; receive ACK signal
	 INC R1
	 DJNZ R3, X3611
         LCALL STOP
         CLR C                           ; write ok c=0, fail c=1
         JMP X3811	
X3711:     LCALL STOP
X3811:     RET
/*************** read value from 16h 24c02 *************************************/
VERIFY_PAGE_SAVE1:		             ; Copy device page to buffer
X7121:	 MOV A, #PADDR                   ; programmable address
	 LCALL READ_BLOCK_SAVE1             ; try write
	 JNC X7221                         ; jump x74 if write ok
	 DJNZ B, X7121                     ; try again
	 SETB C                          ; set timeout error flag
	 JMP X7321
X7221:     CLR C
X7321:     RET   
                                          ; read from one byte to one page of data from 24c02
                                          ; Perform a Random read which is extended into a sequential read
	 		                  ; when more than one byte is read, Called with programmable address
READ_BLOCK_SAVE1:  	 		  ; in A, address of first byte in register pair ADDR_HI: ADDR_LO
	 RL A				  ; byte count in register kount
	 ORL A, #DADDR			  ; Return data in buffer
	 MOV R5, A
	 CLR ACC.0
	 LCALL START 
	 JC X3521	
	 LCALL SHOUT                      ; Write into device address
	 JC X3421
	 MOV A, #16H
	 CALL SHOUT                       ; Write rom address
	 JC X3421
	 MOV A, R5

⌨️ 快捷键说明

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