I have absolutely no idea about the corner detection thingy, but there is a reason that you always get negative R coeffs (assuming that this it is the R[u][v] assignment at the end you mean).
You state that R[u][v] = A*B-C*C-0.04*(A+B)*(A+B);
since at this point, C=A'*B', A=A'*A', B=B'*B' (I am using A' and B' for the original values for A and B before the A and B reassignment), you can rewrite this as:
R[u][v] = A'*A'*B'*B'-A'*B'*A'*B'-0.04*(A'*A'+B'*B')*(A'*A'+B'*B');
which is the same as
R[u][v] = -0.04*(A'*A'+B'*B')*(A'*A'+B'*B');
which is always negative since A'A' and B'B' are always positive.
So in case that it is a problem that R is always negative, I'd say that you'd need to look at this line and change it in some way suitable for your problem.