📄 lcfmet737.asm
字号:
subwf REGC0,f
movf REGB1,w
skpc
incfsz REGB1,w
subwf REGC1,f
movf REGB2,w
skpc
incfsz REGB2,w
subwf REGC2,f
movf REGB3,w
skpc
incfsz REGB3,w
subwf REGC3,f
clrc
bsf REGA0,0 ;Set quotient bit
dremlt decfsz MCOUNT,f ;Next
goto dvloop
btfsc MTEMP,0 ;Check result sign
call negatea ;Negative
return
;*** SQUARE ROOT ***
;sqrt(REGA) -> REGA
;Return carry set if negative
sqrt rlf REGA3,w ;Trap negative values
skpnc
return
call movac ;Move REGA to REGC
call clrba ;Clear remainder (REGB) and root (REGA)
movlw D'16' ;Loop counter
movwf MCOUNT
sqloop rlf REGC0,f ;Shift two msb's
rlf REGC1,f ;into remainder
rlf REGC2,f
rlf REGC3,f
rlf REGB0,f
rlf REGB1,f
rlf REGB2,f
rlf REGC0,f
rlf REGC1,f
rlf REGC2,f
rlf REGC3,f
rlf REGB0,f
rlf REGB1,f
rlf REGB2,f
setc ;Add 1 to root
rlf REGA0,f ;Align root
rlf REGA1,f
rlf REGA2,f
movf REGA2,w ;Test if remdr (REGB) >= root (REGA)
subwf REGB2,w
skpz
goto ststgt
movf REGA1,w
subwf REGB1,w
skpz
goto ststgt
movf REGA0,w
subwf REGB0,w
ststgt skpc ;Carry set if remdr >= root
goto sremlt
movf REGA0,w ;Subtract root (REGA) from remdr (REGB)
subwf REGB0,f
movf REGA1,w
skpc
incfsz REGA1,w
subwf REGB1,f
movf REGA2,w
skpc
incfsz REGA2,w
subwf REGB2,f
bsf REGA0,1 ;Set current root bit
sremlt bcf REGA0,0 ;Clear test bit
decfsz MCOUNT,f ;Next
goto sqloop
clrc
rrf REGA2,f ;Adjust root alignment
rrf REGA1,f
rrf REGA0,f
return
;*** SIGNED BINARY TO DECIMAL ***
;REGA -> DIGITS 1 (MSD) TO 10 (LSD) & DSIGN
;DSIGN = 0 if REGA is positive, FF if negative
;Return carry set if overflow
;Uses FSR register
bin2dec
call clrdig ;Clear all digits
clrf MTEMP ;Reset sign flag
call chksgna ;Make REGA positive
skpnc
goto BLANKIT ;Overflow
movlw D'32' ;Loop counter
movwf MCOUNT
b2dloop rlf REGA0,f ;Shift msb into carry
rlf REGA1,f
rlf REGA2,f
rlf REGA3,f
movlw DIGIT10
movwf FSR ;Pointer to digits
movlw D'10' ;10 digits to do
movwf DCOUNT
adjlp rlf INDF,f ;Shift digit and carry 1 bit left
movlw -D'10'
addwf INDF,w ;Check and adjust for decimal overflow
skpnc
movwf INDF
decf FSR,f ;Next digit
decfsz DCOUNT,f
goto adjlp
decfsz MCOUNT,f ;Next bit
goto b2dloop
btfsc MTEMP,0 ;Check sign
comf DSIGN,f ;Negative
clrc
BLANKIT: movlw 48
iorwf DIGIT1,F
iorwf DIGIT2,F
iorwf DIGIT3,F
iorwf DIGIT4,F
iorwf DIGIT5,F
iorwf DIGIT6,F
iorwf DIGIT7,F
iorwf DIGIT8,F
iorwf DIGIT9,F
iorwf DIGIT10,F
movlw 10 ; blank leading zeros
movwf LOOP
movlw DIGIT1
movwf FSR
BLANK: movf LOOP,W
xorwf POINT,W
btfsc STATUS,Z
return
movf INDF,W
andlw 15
btfss STATUS,Z
return
bcf INDF,4
incf FSR,F
decfsz LOOP,F
goto BLANK
movlw 48
iorwf DIGIT10,F
return
; **************
;Negate REGA
;Used by chksgna, multiply, divide, mod, bin2dec, dec2bin
negatea movf REGA3,w ;Save sign in w
andlw 0x80
comf REGA0,f ;2's complement
comf REGA1,f
comf REGA2,f
comf REGA3,f
incfsz REGA0,f
goto nega1
incfsz REGA1,f
goto nega1
incfsz REGA2,f
goto nega1
incf REGA3,f
nega1
incf MTEMP,f ;flip sign flag
addwf REGA3,w ;Return carry set if -2147483648
return
;Check sign of REGA and convert negative to positive
;Used by multiply, divide, bin2dec
chksgna rlf REGA3,w
skpc
return ;Positive
;Set all digits to 0
;Used by bin2dec
clrdig clrf DSIGN
clrf DIGIT1
clrf DIGIT2
clrf DIGIT3
clrf DIGIT4
clrf DIGIT5
clrf DIGIT6
clrf DIGIT7
clrf DIGIT8
clrf DIGIT9
clrf DIGIT10
return
;Shift left REGA and REGC
;Used by multiply, divide
slac rlf REGA0,f
rlf REGA1,f
rlf REGA2,f
rlf REGA3,f
rlf REGC0,f
rlf REGC1,f
rlf REGC2,f
rlf REGC3,f
return
;Check sign of REGB and negative convert to positive
;Used by multiply, divide, mod
chksgnb rlf REGB3,w
skpc
return ;Positive
;Negate REGB
;Used by chksgnb, subtract, multiply, divide, mod
negateb movf REGB3,w ;Save sign in w
andlw 0x80
comf REGB0,f ;2's complement
comf REGB1,f
comf REGB2,f
comf REGB3,f
incfsz REGB0,f
goto negb1
incfsz REGB1,f
goto negb1
incfsz REGB2,f
goto negb1
incf REGB3,f
negb1
incf MTEMP,f ;flip sign flag
addwf REGB3,w ;Return carry set if -2147483648
return
movac movf REGA0,w
movwf REGC0
movf REGA1,w
movwf REGC1
movf REGA2,w
movwf REGC2
movf REGA3,w
movwf REGC3
return
;Clear REGB and REGA
;Used by sqrt
clrba clrf REGB0
clrf REGB1
clrf REGB2
clrf REGB3
;Clear REGA
;Used by multiply, sqrt
clra clrf REGA0
clrf REGA1
clrf REGA2
clrf REGA3
return
;Add REGB to REGA (Unsigned)
;Used by add, multiply,
addba movf REGB0,w ;Add lo byte
addwf REGA0,f
movf REGB1,w ;Add mid-lo byte
skpnc ;No carry_in, so just add
incfsz REGB1,w ;Add carry_in to REGB
addwf REGA1,f ;Add and propagate carry_out
movf REGB2,w ;Add mid-hi byte
skpnc
incfsz REGB2,w
addwf REGA2,f
movf REGB3,w ;Add hi byte
skpnc
incfsz REGB3,w
addwf REGA3,f
return
;*** SIGNED SUBTRACT ***
;REGA - REGB -> REGA
;Return carry set if overflow
subtract
call negateb ;Negate and add
skpnc
return ;Overflow
;*** SIGNED ADD ***
;REGA + REGB -> REGA
;Return carry set if overflow
add movf REGA3,w ;Compare signs
xorwf REGB3,w
movwf MTEMP
call addba ;Add REGB to REGA
clrc ;Check signs
movf REGB3,w ;If signs are same
xorwf REGA3,w ;so must result sign
btfss MTEMP,7 ;else overflow
addlw 0x80
return
; *************
SHOWOVERFLOW: movwf OVERFLOW
call CLRLINE2
call LCD21
bsf RSLINE,4
; movf INDCORRECT,W ; author's test section
; movwf REGA0
; movf LARGE,W
; movwf REGA0
; clrf REGA1
; clrf REGA2
; clrf REGA3
; call BIN2DEC
; call SHOWITALL
clrf LOOP
OVER2: movf LOOP,W
call OVERFLOWED
call LCDOUT
incf LOOP,F
btfss LOOP,3
goto OVER2
movlw ' '
call LCDOUT
movf OVERFLOW,W
call LCDOUT
goto MAIN
; ***********
CHECKZERO:
movf TMR1H,W
iorwf TMR1L,W
iorwf TIMEMSB,W
movf STATUS,Z
andlw $00000100
movwf OVERFLOW
TIMEEND: movlw %00000000 ; stop timer 1
movwf T1CON
clrf TMR1H
clrf TMR1L
clrf TIMEMSB
call LCD21
bsf RSLINE,4
clrf LOOP
TIMOUT2: movf LOOP,W
call TIMEDOUT
call LCDOUT
incf LOOP,F
btfss LOOP,4
goto TIMOUT2
call LCD1
bsf RSLINE,4
clrf LOOP
btfsc PORTA,4
goto TIMOUT4
TIMOUT3: movf LOOP,W
call CAPTIME
call LCDOUT
incf LOOP,F
btfss LOOP,4
goto TIMOUT3
goto MAIN
TIMOUT4: movf LOOP,W
call INDTIME
call LCDOUT
incf LOOP,F
btfss LOOP,4
goto TIMOUT4
goto MAIN
; ******* WRITE DATA TO EEPROM ROUTINE modified for PIC16F62x devices ********
;according to data sheet page 93 (is the same as for 16F87x devices
; except that PIR2 of '87x has become PIR1 for '62x and page 2/3 not used)
;This routine is entered with W holding
;the eeprom byte address at which data
;is to be stored. The data to be stored
;is held in PROMVAL, which is located in both pages at or above $70
SETPRM:
BANK1
movwf EEADR ;copy W into EEADR to set eeprom address
movf PROMVAL,W ;get data value from PROMVAL and hold in W
movwf EEDATA ;copy W into eeprom data byte register
bsf EECON1,WREN ;enable write flag
MANUAL: movlw $55 ;these lines cause the action required by
movwf EECON2 ;by the eeprom to store the data in EEDATA
movlw $AA ;at the address held by EEADR.
movwf EECON2
bsf EECON1,WR ;set the ``perform write'' flag
BANK0
CHKWRT: btfss PIR1,EEIF ;wait until bit 4 of PIR2 is set
goto CHKWRT
bcf PIR1,EEIF ;clear bit 4 of PIR2
return
;******** READ DATA FROM EEPROM ROUTINE modified for PIC16F62x devices ****
; the data sheet page 93 is wrong! This routine here works!
;This routine is entered with W holding
;the eeprom byte address to be read.
PRMGET: BANK1
movwf EEADR ;copy W into EEADR to set eeprom address
bsf EECON1,RD ;enable read flag
movf EEDATA,W ;read eeprom data now in EEDATA into W
BANK0
return
; ***********
CORRECTIT:
call LCD1
bsf RSLINE,4
btfss PORTA,4
goto CAPCRT
INDCRT: movlw 'I'
call LCDOUT
movlw 'N'
call LCDOUT
movlw 'D'
call LCDOUT
clrf CORRECTLOC
goto CORRECT2
CAPCRT: movlw 'C'
call LCDOUT
movlw 'A'
call LCDOUT
movlw 'P'
call LCDOUT
movlw 1
movwf CORRECTLOC
CORRECT2: clrf LOOP
CORRECT3: movf LOOP,W
call CORRECTMSG
call LCDOUT
incf LOOP,F
btfss LOOP,4
goto CORRECT3
COR3: call SHOWCORRECT
COR4: btfsc PORTA,2 ; is S3 (RA2) still pressed?
goto COR4 ; yes
call PAUSIT
COR5: btfss PORTA,2 ; is S3 (RA2) pressed?
goto COR5 ; no
btfsc PORTA,4
goto COR7
COR6: call INCIT
call SHOWCORRECT
call PAUSIT2
call PAUSIT2
goto COR5
COR7: call DECIT
call SHOWCORRECT
call PAUSIT2
call PAUSIT2
goto COR5
INCIT: movf CORRECTLOC,W
call PRMGET
movwf PROMVAL
addlw 1
movwf PROMVAL
xorlw 200
btfsc STATUS,Z
decf PROMVAL,F
movf CORRECTLOC,W
call SETPRM
return
DECIT: movf CORRECTLOC,W
call PRMGET
movwf PROMVAL
decf PROMVAL,F
btfsc STATUS,Z
incf PROMVAL,F
movf CORRECTLOC,W
call SETPRM
return
; **********
SHOWCORRECT:
movf CORRECTLOC,W
call PRMGET
movwf REGA0
clrf REGA1
clrf REGA2
clrf REGA3
call LCD21
bsf RSLINE,4
call BIN2DEC
movf DIGIT8,W
call LCDOUT
movf DIGIT9,W
call LCDOUT
movf DIGIT10,W
call LCDOUT
return
; **************
.org $2100 ; data eeprom values
DE 100,100,0,0,0,0
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -