New to programming. Using PIC18F4520 with a MM74C922N 4x4 matrix keypad connected to Port A bits 0 to 3. Basically this keypad has a 4 bit output(DCBA) that corresponds to what key was pressed based on the table below. What I want to do is to have a variable switch between 2 states when the '1' key is pressed(DCBA = 0000). When '1' is pressed, variable = 1. When '1' is pressed again, variable = 2. When '1' is pressed yet again, variable = 1. So and and so forth... Any help is appreciated
Code:
char keypressed[16] = { '1', '2', '3', 'F', '4', '5', '6', 'E', '7', '8', '9', 'D', 'A', '0', 'B', 'C' };
if(key == keypressed[0])
... //Variable setting

As per your comment, you want to switch back and forth between values for a particular variable.
In order to achieve this you can store those two values in an array and then use XOR operation to change the index of the array and assign the value to the variable as show in the sample/example code below: