You have to use an output current sensor (ACS714).
For stage 1: by reading the output current value with your PIC (ADC pin) you could increase/decrease the PWM ratio to keep that output current at a constant value (18 A). You don't have to worry about the output voltage as the battery internal resistance will self regulate it.
For stage 2, you have to read the output voltage and modify the PWM ratio accordingly to keep the output voltage constant (14.5 V). The output current will drop slowly (the battery internal resistance will increase durring charging).
For stage 3, you only have to watch for the output voltage, too (but for a lower value: 13.8V).