----- Original Message ----- From: Jan-Erik Svderholm XA (TN/PAC) To: Sent: Saturday, July 26, 2003 12:29 AM Subject: [PIC]: "Reverse" table lookup ? > Hi. > Well, we all know how to do a computed table lookup in the > 16-series by adding directly to the PCL and executing a RETLW. > As when generating 7-seg-display codes from 0-9 binary values. > > But, if we already have the 7-seg-display-codes and want > the correspondent 0-9 binary value ? > > The two ways I see are (1) to build a 2**7 bits long table with a > lot of unused space and (2) use a series of sub/skip instructions. > > Anyone having a a better solution ? > > Jan-Erik. Hi Jan, Sounds like you want to generate a hashing code to find your 10 entries in a 128 element table. The hashing algorithm would be highly dependent on the way the outputs are wired to the display. Searching for 7 seg LED output paterns I found the following on http://www.melabs.com/resources/articles/ledart.htm Number Segments Hex 0 1100 0000 $C0 1 1111 1001 $F9 2 1010 0100 $A4 3 1011 0000 $B0 4 1001 1001 $99 5 1001 0010 $92 6 1000 0010 $82 7 1111 1000 $F8 8 1000 0000 $80 9 1001 1000 $98 From the above I worked out the following hash 0 0100 0000 0100 0000 0100 0000 0.00 1000 2 1 0111 1001 0111 101. 0111 11.. 0.11 11.. F 2 0010 0100 0010 0100 0010 0100 0010 0100 9 3 0011 0000 0011 0000 0011 0000 0011 0000 C 4 0001 1001 0001 101. 0001 11.. 0001 11.. 7 5 0001 0010 0001 0010 0001 01.0 0001 01.0 5 6 0000 0010 0000 0010 0000 01.0 0000 01.0 1 7 0111 1000 0111 1000 0111 1000 0.11 1000 E 8 0000 0000 0000 0000 0000 0000 0000 0000 0 9 0001 1000 0001 1000 0001 1000 0001 1000 6 0346 4122 0346 4140 0346 4500 0346 4500 The hashing algorithm and table lookup boils down to addlw 3 movwf acc movlw tbl >> 8 movwf PCLATH btfsc acc,6 bsf acc,3 rrf acc rrf acc,w andlw 0x0f addlw tbl & 0xff btfsc STATUS,C incf PCLATH movwf PCL tbl: retlw 8 ; 0 retlw 6 ; 1 retlw 0 ; 2 retlw 255 ; 3 retlw 255 ; 4 retlw 5 ; 5 retlw 9 ; 6 retlw 4 ; 7 retlw 255 ; 8 retlw 2 ; 9 retlw 255 ; A retlw 255 ; B retlw 3 ; C retlw 255 ; D retlw 7 ; E retlw 1 ; F Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads