The appropriate code for interfacing an accelerometer depends largely on the specific device.
You must specify the specific model of the accelerometer you intend on utilizing, before any meaningful advice or code examples can be offered.
Accelerometers typically fall into two categories of interfaces analog or digital.
Also as there are numerous 8051 variants, you will need to specify which particular of model/manufacturer you intend on utilizing in your design.
BigDog