How to use mode 0 in 8051?
The loop waiting for the timer is run not at all, if TF0 is not set, or only once, because it resets the flag TF0 right in the first iteration:
            while (TF0 == 1)
            {
                TR0 = 0;
                TF0 = 0;
            }

Instead, reset the flag and then wait for it to be set by the timer:
            TF0 = 0;
            while (TF0 == 0)
            {
                /* nothing to be done here */
            }