Writing ISR to read 4-bit output from 74c922 keypad encoder ic

I downloaded your latest code, keypad_4x3_Program_Working_CORRECTLY_ISR_and_setflag_test_5.ino, and I see you have the attachInterrupt() commented out. I am goig to assume you commented it out because it didn't work, but looking at your code, I see the following lines:

int DATA_AV=12;
const int pin2ISR = 2;
attachInterrupt(pin2ISR,readEncoder , RISING); // assuming you uncommented it to test

If you have Data Available wired to pin 12, it's never going to give you an interrupt on pin 2.

Of course, I may be misunderstanding the attachInterrupt statement.

You might as well get rid of the Serial. print statements in the ISR, as they won't work. The LED on pin 6 will indicate going through the interrupt, but then if you're testing the ISR, you should comment out the line that sets it HIGH near the top of loop(). In fact you should probably toggle it on/off each time through the interrupt, and comment out all the other lines that set it LOW, or you won't even see it if it does go on. Things happen mighty quick in Arduino county.

Graynomad mentioned the best way to optimize your endless if statements. He suggested using the low order 4 bits of PortD, and using

total = PIND & 0xF;

That's probably not the best port to use, since Tx and Rx are on bits 0 and 1, but basically, any 4 consecutive bits in one port are desirable for this purpose.

Suppose you used PortD, bits 3, 4, 5, and 6 (which are Arduino pins 3, 4, 5, and 6). You could then read them with the single line:

total = (PIND & 0x78) >> 3 ;

Read this as "get bits 3, 4, 5, and 6, and shift that value 3 bits to the right", which will give you the value of the pressed key. If the value is wrong, you can change the wires between the keypad and the 74c922. It'll save you a whack of parsing.