At the outset i feel something wrong with powering, as you have applied 5V Dc to Vcc (pin 40). BTW, why not use 89S52 instead of plain8051 and it is flash programmable and cheap also?
I wonder whether this connection is to pin39, as Pin40 is to be connected to 5Vdirectly? this can be checked from the source code perhaps?
try to put 0.1 decoupling caps across pins 20 and 40 of the 8051/89S52.
have different paths of 5V supply for micro and for other loads.
It is also preferred to have independent regulators for either side.