Richard, You are missing the masks on both the input and the output to ensure that the bits you want are changed while the ones you are not interested in are untouched. Take a look at my previous example where 0x03 is used to mask the input and the 0x33 is used to clear bits 7,6,3, and 2 before you merge the table value in. BAJ On Tue, Sep 15, 2015 at 10:53:39AM -0500, Richard R. Pope wrote: > Hello, > I have decided to use arrays as suggested by Allen. Arrays are=20 > easier for me to understand. Here is what I did: >=20 > int porta[3]; //The PORTA output arra= y > int portb[3]; //The PORTB output arra= y > int a; //The PORTA index=20 > variable > int b; //The PORTB=20 > indexvariable >=20 > //Load the arrays bits 7 6 5 4 =20 > 3 2 1 0 > porta[0] =3D 132; //Drk-Red 1 0 N = =20 > N 0 1 I I > porta[1] =3D 8; //Lit-Grn 0 =20 > 0 N N 1 0 I I > porta[2] =3D 64; //Lit-Yel 0 = =20 > 1 N N 0 0 I I > porta[3] =3D 128; //Lit-Red 1 =20 > 0 N N 0 0 I I >=20 > bits 7 6 5 4 3 2 1 0 > portb[0] =3D 36; //Drk-Red N N = =20 > 1 0 0 1 I I > portb[1] =3D 8; //Lit-Grn N = =20 > N 0 0 1 0 I I > portb[2] =3D 16; //Lit-Yel N = =20 > N 0 1 0 0 I I > portb[3] =3D 32; //Lit-Red N =20 > N 1 0 0 0 I I >=20 > So the next step is to use a =3D PORTA and b =3D PORTB. Then we do=20 > this: PORTA =3D porta[a]; and PORTB =3D portb[b]; Am I doing this correct= ly? > Thanks, > rich! >=20 > P.S. All of the help is greatly appreciated. > Thanks, > rich! >=20 > On 9/15/2015 9:48 AM, Byron Jeff wrote: > > 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 merg= e with 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 > > > > > --=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 .