Code:
;''''''''''''''' Process LONG term '''''''''''''''''''''''''''''''''
bcf STATUS, C
rrf LongD ;Easiest to work with LongD/2 everywhere
btfss STATUS, C ; as Loc works on 2 deg intervals
goto NoLongMinsUpdate
movlw LOW(d'6000') ;Add 1 degree's worth of carry into the
addwf LongMLo ; minutes registers if LongD/2 has a carry
btfsc STATUS, C
incf LongMHi
movlw HIGH(d'6000') ;LongM in range 0 - 12000
addwf LongMHi
NoLongMinsUpdate ;LongD' now in range 0 - 90
btfss NEGLONG
goto PosLong
comf LongD
incf LongD ;LongD' now in 2's complement +/-90
movf LongMLo, w ;Normalise LongM = 12000 - LongM
sublw LOW(d'12000')
movwf LongMLo ;if borrow, C = 0, so increment the subtrahend
btfss STATUS, C
incf LongMHi
movf LongMHi, w
sublw HIGH(d'12000')
movwf LongMHi
decf LongD ;Correct Degrees
PosLong
movlw d'90'
addwf LongD ;Normalise D' to 0-180
movf LongD, w
movwf ALo
clrf AHi
movlw d'10'
call DivMod ;Mod out in A, Div out in B
movf BLo, W
addlw "A"
movwf Loc1
movf ALo, w
addlw "0"
movwf Loc3
rrf LongMHi ;Divide by 4 to give range 0 - 2999
rrf LongMLo
rrf LongMHi
rrf LongMLo
movlw 0x3F
andwf LongMHi
movf LongMLo, w ;Mins * 100 / 4 DIV 125
movwf ALo
movf LongMHi, w
movwf AHi
movlw d'125'
call DivMod ;Mod out in A, Div out in B
movf BLo, w
addlw "A"
movwf Loc5
;Recover MOD term (scaled 0 - 124) which stays in ALo
clrf AHi
bcf STATUS, C
rlf ALo ;Scale to 0 - 248
movlw d'25'
call DivMod ;Mod out in A, Div out in B
movf BLo, w
addlw "0"
movwf Loc7 ;Result in LongD, LongMHi, LongMLo , NEGLONG
;'''''''''''''''''''Now DO LAT term , LatD is already in range 0 - 90''''''''''''''''''
btfss NEGLAT
goto PosLat
comf LatD
incf LatD ;LatD now in 2's complement +/-90
movf LatMLo, w ;Normalise LatM = 6000 - LatM
sublw LOW(d'6000')
movwf LatMLo
btfss STATUS, C ;if borrow, C = 0, so increment the subtrahend
incf LatMHi
movf LatMHi, w
sublw HIGH(d'6000')
movwf LatMHi
decf LatD ;Correct the degrees
PosLat
movlw d'90'
addwf LatD ;Normalise to 0-180
movf LatD, w
movwf ALo
clrf AHi
movlw d'10'
call DivMod ;Mod out in A, Div out in B
movf BLo, W
addlw "A"
movwf Loc2
movf ALo, w
addlw "0"
movwf Loc4
bcf STATUS, C
rrf LatMHi ;Divide by 2 to give range 0 - 2999
rrf LatMLo
movf LatMLo, w ;Mins * 100 / 2 DIV 125
movwf ALo
movf LatMHi, w
movwf AHi
movlw d'125'
call DivMod ;Mod out in A, Div out in B
movf BLo, w
addlw "A"
movwf Loc6
;Recover MOD term (scaled 0 - 124) which stays in ALo
clrf AHi
bcf STATUS, C
rlf ALo ;Scale to 0 - 248
movlw d'25'
call DivMod
movf BLo, w
addlw "0"
movwf Loc8 ;Result in LatD, LatMHi, LatMLo , NEGLAT
ShowLoc
movf Loc1, W
call LcdData
movf Loc2, W
call LcdData
movf Loc3, W
call LcdData
movf Loc4, W
call LcdData
movf Loc5, W
call LcdData
movf Loc6, W
call LcdData
movf Loc7, W
call LcdData
movf Loc8, W
call LcdData
return
Bookmarks