piclist 2001\01\10\160308a >
Thread: yet another algorithm challange
www.piclist.com/techref/microchip/devices.htm?key=pic
picon face BY : Drew Vassallo email (remove spam text)



>Actually, now that I did this table on paper, it's obvious that you can
>just
>use bit pairs for lookups (ie., 0, 3, C, and F).  Mask off the unused bits
>and send the remaining bit pair to the lower nibble.  This reduces your
>table to only 4 lines, but increases your code length.  I'd say you could
>do
>this pretty easily.

Ok, I had some free time.  This should work, but it's untested.

;;Result of 2x original byte is in Converted_Number (LSB)
;; and Converted_Number + 1 (MSB)
;;Result of 6x original byte is in Converted_Number (LSB), etc...
CBLOCK 0x0C
   Count
   Base_Number
   Converted_Number:6
ENDC

2x_Convert
   movf Base_Number, w    ; in your example, "0xA1" moves to W
   swapf Base_Number, f   ; force "A" to lower nibble
   andlw 0x0F             ; Mask off the upper nibble
   call Get_2x_Conversion
   movwf Converted_Number ; dump off lower byte
   movf Base_Number, w
   andlw 0x0F             ; mask off the upper nibble
   call Get_2x_Conversion
   movwf Converted_Number + 1  ; dump off upper byte

Get_2x_Conversion
;; Conversion is 0->0, 1->3, 2->C, 3->F for each bit pair
;; Make sure you watch PCLATH and compensate accordingly
   addwf PCL
dt 0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F, 0xC0, 0xC3, 0xCC
dt 0xCF, 0xF0, 0xF3, 0xFC, 0xFF

6x_Convert
;; This is a little more difficult, requiring 3 nibbles per bit pair
;; or 3 bytes per original nibble (6 bytes total per original byte).
;; You could keep these 2 methods different, or convert the 2x method to
;; this bit-pair method.
;; 00->000, 01->03F, 10->FC0, 11->FFF
   clrw
   clrf Converted_Number
   clrf Converted_Number+1
   clrf Converted_Number+2
   clrf Converted_Number+3
   clrf Converted_Number+4
   clrf Converted_Number+5
   clrc
   rlf Base_Number
   btfss STATUS, C
   goto Check_6
   movlw 0xFC
   addwf Converted_Number + 5
Check_6
   rlf Base_Number
   btfss STATUS, C
   goto Check_5
   movlw 0x03
   addwf Converted_Number + 5
   movlw 0xF0
   addwf Converted_Number + 4
Check_5
   rlf Base_Number
   btfss STATUS, C
   goto Check_4
   movlw 0x0F
   addwf Converted_Number + 4
   movlw 0xC0
   addwf Converted_Number + 3
Check_4
   rlf Base_Number
   btfss STATUS, C
   goto Check_3
   movlw 0x3F
   addwf Converted_Number + 3
etc... repeat for lower nibble.

I haven't tried this, so you're on your own :)

--Andrew

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistserv.....spamRemoveMEmitvma.mit.edu with SET PICList DIGEST in the body


<F1630gxapzhad2VqKwR00009db1@hotmail.com>

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) yet another algorithm challange

month overview.

new search...