Encoder with a hexagonal lattice photonic crystal was performed by OCDMA simulation model. Filtering of photonic crystal cavity was used for encoding in spectral domain, and the distance between the dot defects was used for encoding in time domain because of its slow light effects caused by dispersion, whose time delay reached orders of ns magnitude. According to the simulation, the BER of OCDMA system with PC encoder is 10-23, while BER is 10-18 in the system with FBG encoder. By contrast, it is indicated that PC encoder requires strict demands on its own structure. With mismatching of encoder and decoder in receiving terminal, BER decrease to 10-7, and the performance of OCDMA system is serious affected.