Mike - K8LH
Well-Known Member
Nice work Mike. I like it. I see how TRIS is setup for us during the first OwReset call. That's an excellent find for saving 2 words.
You can reclaim one word in the section between PutDigit and PutOnes in your example. Just change the skpnz to skpz and remove the goto PutIt instruction on the next line (just before the PutOnes label).
I reworked that Bin2packedBcd routine to make it a little more general purpose (below). It now works correctly for 8 bit input values of 0..255 using only 12 words and 2 variables. I should probably pass it along to James Newton over at PICLIST.
I setup my temperature variables a bit differently and saved about 4 words (the BinPrep code segment below). I didn't see the need to copy the four fraction bits in TempLo into a new variable. I don't clear the bits in the upper nybble because the AND 0x0F sequence in your FracDigit routine (called PutFraction in my program) does that for us. I use TempHi to hold the 7 bit temperature value (0..125). The AbsFunc code leaves zeros in TempHi bits 7 through 3 so we don't need to clear those bits before copying the low order temperature bits from TempLo into TempHi.
More later. Mike, K8LH
You can reclaim one word in the section between PutDigit and PutOnes in your example. Just change the skpnz to skpz and remove the goto PutIt instruction on the next line (just before the PutOnes label).
I reworked that Bin2packedBcd routine to make it a little more general purpose (below). It now works correctly for 8 bit input values of 0..255 using only 12 words and 2 variables. I should probably pass it along to James Newton over at PICLIST.
I setup my temperature variables a bit differently and saved about 4 words (the BinPrep code segment below). I didn't see the need to copy the four fraction bits in TempLo into a new variable. I don't clear the bits in the upper nybble because the AND 0x0F sequence in your FracDigit routine (called PutFraction in my program) does that for us. I use TempHi to hold the 7 bit temperature value (0..125). The AbsFunc code leaves zeros in TempHi bits 7 through 3 so we don't need to clear those bits before copying the low order temperature bits from TempLo into TempHi.
More later. Mike, K8LH
Code:
Send232 " " ; print <space>
AbsFunc
movlw " " ;
btfss TempHi,7 ; negative?
goto PutSign ; no, branch, else
comf TempLo,F ; two's compliment it
comf TempHi,F ;
incf TempLo,F ;
skpnz ;
incf TempHi,F ;
movlw "-" ;
PutSign
call Put232 ; print " " or "-"
[COLOR=Blue]BinPrep
movlw 0xF0 ; W = 11110000
andwf TempLo,W ; W = LLLL0000, F = LLLLFFFF
iorwf TempHi,F ; F = LLLL0HHH
swapf TempHi,W ; W = 0HHHLLLL, 0..127
[/COLOR][COLOR=DarkOrchid]Bin2Bcd
clrf tens ; tens equates to 'OwByte'
decf tens,F ; preset 'tens' to -1
div10 movwf ones ; ones equates to 'TempHi'
incf tens,F ; bump 'tens', 0x00..0x25
movlw 6 ; using "packed bcd" format
addwf tens,W ; bcd "digit carry"?
skpndc ; no, skip, else
movwf tens ; adjust 'tens'
movlw 10 ; ones = ones - 10
subwf ones,W ; borrow (negative)?
bc div10 ; no, branch, else[/COLOR]
PrintIt
Last edited: