您需要使用额外的寄存器才能计数超过 255。以下代码应该可以工作:
计数器 = (COUNTERX2*255 + COUNTERX)
COUNT
BTFSC COUNTRX2,0 ; helper variable to hold more significant byte of counter
GOTO OVER255 ; if COUNTERX2 is not zero, it means counter > 255
INCF COUNTRX,1 ; if counter is less than 256, increment it
; COUNTERX is zero at this point only
; if it was earlier 255 and was just incremented
BTFSC STATUS,Z
INCF COUNTRX2,1 ; if COUNTERX is zero, increment COUNTERX2
GOTO NOTITSVALUE
OVER255
INCF COUNTRX,1 ; again increment COUTERX to continue counting
MOVLW D'44' ; = 300 - 256
MOVWF VALUE
MOVF COUNTRX,W
; 44 - COUNTERX, effectively 300 - (COUNTERX2*255 + COUNTERX)
SUBWF VALUE,W
BTFSC STATUS,Z
GOTO ITSVALUE
GOTO NOTITSVALUE
我用 MPLABX 模拟器对其进行了测试,它可以工作。它不可能是最佳的,因为我是汇编编程的初学者。