The issue was bug in the compiler. And, therefore under very specific circumstances the compiler would not handle a bit as a bit, but a byte. As a bug it needed to be resolved. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The root cause was that the compiler was not checking whether the variable being used was a bit value.
Here is another way I did a while back. Just for reference.
Change the setbit routines to Macros and they will run somewhat faster.
Last edit: William Roth 2021-09-01
The issue was bug in the compiler. And, therefore under very specific circumstances the compiler would not handle a bit as a bit, but a byte. As a bug it needed to be resolved. :-)
Nevertheless,
The attached code works and demonstrates a way to set individual bits using a variable for the bit position and the bit state.