The photodissociation of CO in circumstellar envelopes