You should type-cast the if(DEVICE_ID==ident)
to be if( (uint8_t)DEVICE_ID == (uint8_t)ident)
This has been an issue for me in the past.
And yes, declare ident as volatile, and for debugging purposes, try adding a delay before the comparison via a for-loop with __no_operation();
inside it. Note that there are 2 underscores in front of that, not 1 (intrinsic NOP instruction), and that a single NOP takes roughly ~29ns on a 168MHz board, measured via scope.
Also, since you have IAR, you might as well pop open the "assembly" view and look at what registers and/or constants are actually being compared. Open the "register" view as well...so you can see the register values themselves.