To enhance commercial implementation, visible light communication (VLC) should facilitate dimming control and reliable data transmission simultaneously, where users can adjust the brightness levels arbitrarily. Constant weight code (CWC) based dimming method can achieve higher spectral efficiency, but the codewords need further selection to exponentially map the massage. In this paper, based on CWC, we proposed a method to achieve dimming control as well as improve error performance via optimizing the average Hamming distance of the codeword set. Simulation results show that the optimal codeword set can achieve better error performance.