This thread has been stuck in a posting queue until it got flagged today!
If you have a 9v NiCad, and you plug in a 12v supply, then the PIC need not have anything to do with it. A simple Diode to block the 12v from directly connecting to the Battery with a Resistor across it to determine the charging current.
Ni-cads are a little wimpish and don't like being mistreated (chose NiMH's for a more robust device). If the 12v Supply is likely to be left connected for any length of time (ie sevaral days), simply select a Resistor that will give you a trickle charge rate between say 5mA and 8mA.
Bookmarks