piclist 2001\01\10\160308a >
Thread: yet another algorithm challange
picon face BY : Drew Vassallo email (remove spam text)

>Actually, now that I did this table on paper, it's obvious that you can
>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
>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...

   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

;; 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

;; 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
   clrf Converted_Number
   clrf Converted_Number+1
   clrf Converted_Number+2
   clrf Converted_Number+3
   clrf Converted_Number+4
   clrf Converted_Number+5
   rlf Base_Number
   btfss STATUS, C
   goto Check_6
   movlw 0xFC
   addwf Converted_Number + 5
   rlf Base_Number
   btfss STATUS, C
   goto Check_5
   movlw 0x03
   addwf Converted_Number + 5
   movlw 0xF0
   addwf Converted_Number + 4
   rlf Base_Number
   btfss STATUS, C
   goto Check_4
   movlw 0x0F
   addwf Converted_Number + 4
   movlw 0xC0
   addwf Converted_Number + 3
   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 :)


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

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


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...