binary counter 32-bit spi
It is not clear to me why you would build external modulo-32 bit counter where all these functions can be easily implemented witn 8051 microcontroller, but, if it is only for the sake of excercises then I would go for "old" goodies such as 74393 (dual 4-bit binary counter with reset).
You will need 3 of these counters to build full 32-bit binary counter.
Other candidates can be selected from the 4000 family. Here you can use 4020 (14-bit) or 4040(12-bit) binary counters.
All 32 outputs can be connected to 8051 ports P0, P1 and P2.
Also keep in mind that single-channel encoders (tachometers), are inherently less accurate than dual-channel versions and cannot register direction. Inaccurate readings often result when the code wheel stops on or near a slot's edge and vibrations move the code wheel back and forth. If the slot edge interrupts the light beam, the counter increments with each transition.
At this stage there is no point in discussing the software side of your project.
Firstly, you need to design the hardware and then we can help you (if needed) in writing the code.
Other question is how, or in what form, are you going to use/display the result of the 32-but counter?
Regards,
IanP