; ALL angles are 0 to 255
; I think zero is 3 oclock and 64 is 12 oclock
;variables
;Angle, Length - line parameters
;XPos, YPos - start coords
;AccLo, AccHi - 16 bit accumulator
;Pointer - 16 bit memory pointer
;Temp - guess
;b_Sign - a bit variable to hold the sign value
;the way I assign bit variables is as follows
cblock 0xnn
Flags
endc
#define b_Sign Flags,7
#define b_Crytical Flags,6
;etc.
;The code
RadialLine bcf STATUS,C
rlf Length,F
movfw Angle
call GetCos
call Calc
addwf XPos,W
movwf XEnd
movfw Angle
call GetSine
call Calc
sublw 0
addwf YPos,W
movwf YEnd
goto Line
Calc bcf b_Sign
btfss AccHi,7
goto NoNeg
bsf b_Sign
call Negate
NoNeg bcf STATUS,C
rrf AccHi,F
rrf AccLo,F
bcf STATUS,C
rrf AccHi,F
rrf AccLo,F
bcf STATUS,C
rrf AccHi,F
rrf AccLo,F
movfw Length
call Mult8x8
movfw AccHi
btfsc b_Sign
sublw 0
return
;will multiply W by AccLo and return the result in AccHi:Lo
Mult8x8
clrf AccHi
clrf Count
bsf Count,3
rrf AccLo,F
Loop btfsc STATUS,C ;SKPNC
addwf AccHi,F
rrf AccHi,F
rrf AccLo,F
decfsz Count,F
goto Loop
return
GetCos addlw .64
;will return a 10 bit (+sign) value equal to (sin(w)+1)*512
GetSine movwf Temp
btfsc Temp,6 ;are we in 2nd or 4th quadrant
sublw 0 ;negate - note 64 will become 192
andlw 0x7f ;and now back to 64
addlw low SineTab
movwf Pointer
movlw high SineTab
btfsc STATUS,C
addlw 1
movwf Pointer+1
call SetEEAdd
call ReadEEWord
btfss Temp,7 ;are we in the 3rd or 4th quadrant
return
SineTab
dw 0,25,50,75,100,125,150,175
dw 199,224,248,273,297,321,344,368
dw 391,414,437,460,482,504,526,547
dw 568,589,609,629,649,668,687,706
dw 724,741,758,775,791,807,822,837
dw 851,865,878,890,903,914,925,936
dw 946,955,964,972,979,986,993,999
dw 1004,1008,1012,1016,1019,1021,1022,1023
dw 1024
dw -.122
; need to negate Acc
Negate
comf AccLo,F
comf AccHi,F
incfsz AccLo,F
return
incf AccHi,F
return
;Note:- the various banking instructions may be wrong.
; they are correct for 16F88 and 16F688
; this could be converted to use the retlw type table instead.
SetEEAdd bsf STATUS,RP1 ;#2
movfw Pointer
movwf EEADR
movfw Pointer+1
movwf EEADRH
bcf STATUS,RP1
return
ReadEEWord bsf STATUS,RP1 ;#2
bsf STATUS,RP0 ;#3
bsf EECON1,EEPGD
bsf EECON1,RD
nop
nop
bcf STATUS,RP0 ;#2
movfw EEDAT
movwf Acc
movfw EEDATH
movwf Acc+1
incfsz EEADR,F ;Increment address
goto DoneREE
incf EEADRH,F
DoneREE bcf STATUS,RP1 ;#0
return