Hi, Diego.

As with all variables with non-trivial dependency you probably
have to define it volatile, to turn off optimization for this variable.
Like this:

volatile unsigned char stim;

Well, and probably "ss" variable too.

Good luck!