Denny's previous post is essentially defines it: // Defining the table: unsigned char TableA[] =3D {0x82,0x04,0x40,0x80}; unsigned char mask =3D 0x33; // mask out bits 7,6,3, and 2 // Using the table: shadowA =3D PORTA & mask; // Get PORTA masking out output bits. inputA =3D shadowA & 0x03; // input is PORTA bits 1,0 shadowA =3D shadowA | TableA[inputA]; // Get output from table and merge wi= th shadow PORTA =3D shadowA; // Write the output from shadow back to PORTA Of course C can be obfuscated into a single statement: PORTA =3D shadowA | TableA[(shadowA =3D PORTA & mask) & 0x03]; Interesting what you can do when assignment is an expression and not a statement. BAJ On Mon, Sep 14, 2015 at 04:19:40PM -0500, Richard R. Pope wrote: > Byron, > Could you please translate this into C for me? > Thanks, > rich! >=20 > On 9/14/2015 11:14 AM, Byron Jeff wrote: > > Richard, > > > > Your description below screams table. Since it's only 2 bits, the table > > would be 4 entries long: > > > > TableA: ; W is input. Returns table entry in W. > > andlw 0x3 ; make sure only 2 lowest bits are used > > addwf PC,F ; jump to appropriate table entry > > retlw 0x82 ; return 1001 in bits 7-6,3-2 if input is 00 > > retlw 0x04 ; return 0010 in bits 7-6,3=3D2 if input is 01 > > retlw 0x40 ; return 0100 in bits 7-6,3=3D2 if input is 10 > > retlw 0x80 ; return 1000 in bits 7-6,3=3D2 if input is 11 > > > > Make a similar table for B. > > > > Then all you'd need to do is read the port, clear the output bits, call= the > > table routine, OR back in the results, and write the whole mess back to= the > > port. > > > > Hope this helps, > > > > BAJ > > > > On Mon, Sep 14, 2015 at 10:31:15AM -0500, Richard R. Pope wrote: > >> Jan-Erik, > >> I guess my next question is about packing the register. The RA0-= 1 > >> and RB0-1 bits are my inputs. On Port A the output pins are 2-3 and 6-= 7. > >> On Port B it is 2-5. So if I have two output registers. One called > >> OutputA and the other OutputB. When the input is 0-0 then the output i= s > >> 1-0-0-1. If the input is 0-1 then the output is 0-0-1-0. If it is 1-0 > >> the output is 0-1-0-0 and if it is 1-1 the the output is 1-0-0-0. I > >> guess we should define some constants called Bit# such as Bit0, Bit1, > >> Bit2 and so forth to Bit7. These should be set to 1, 2, 4, 8, and so > >> forth up to 128. We first have to clear the registers to zero with > >> OutputA or B =3D 0; So do we add RA, B 0 and 1 together? And here is w= here > >> I get lost. I just don't understand how to turn RA and B 0 and 1 in t= o > >> the proper number to put into the output bits. Would you please help m= e > >> with this. > >> Thanks, > >> rich! > >> > >> P.S. This is how it should look. > >> --------------------------------- ---------------------------------- > >> | Input | Output | > >> | Input | Output | > >> | Bits | Bits PortA | > >> | Bits | Bits PortB | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|-----|------| > >> | 1 | 0 | 2 | 3 | 6 | 7 | > >> | 1 | 0 | 2 | 3 | 4 | 5 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|-----|------| > >> | 0 | 0 | 1 | 0 | 0 | 1 | > >> | 0 | 0 | 1 | 0 | 0 | 1 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 0 | 1 | 0 | 1 | 0 | 0 | > >> | 0 | 1 | 0 | 1 | 0 | 0 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 1 | 0 | 0 | 0 | 1 | 0 | > >> | 1 | 0 | 0 | 0 | 1 | 0 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 1 | 1 | 0 | 0 | 0 | 1 | > >> | 1 | 1 | 0 | 0 | 0 | 1 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> Thanks, > >> rich! > >> > >> > >> On 9/13/2015 6:00 AM, Jan-Erik S=F6derholm wrote: > >> > >> --=20 > >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > >> View/change your membership options at > >> http://mailman.mit.edu/mailman/listinfo/piclist > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 Byron A. Jeff Associate Professor: Department of Computer Science and Information Technol= ogy College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .