Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#define PORT3 P3
main()
{
unsigned char variable;
variable = PORT3;
}
The above code just reads from the port register and copies to the variable. If you want that particular variable should hold only 5 bits then use bit field option
unsigned char variable : 5;
The C language has plenty of ways to do it, I think. I use to write code according to a problem. But the problem isn't clear in the present case.Is there an easy way to store nibbles to a variable?
variable1 = port_input_register & 0xf;
variable2 = port_input_register >>4;
sorry,I don't understand the question. In my example, the upper nibble is written to variable2. The data is shifted to the lower nibble of the variable, which implicitely masks the bits.I suggest to visualize the operation by pencil and paper.
variable2 = port_input_register & 0xf0;