Charging the battery with a programmable power supply