Charging a Li-ion battery with a Buck Convertor & ATmega8
Below is the circuit referred to by Bruce Abbott.
Copied from here
and part of this "Instructable.


  ... My doubts are with the drive of the P-MOSFET. In order to drive the transistor, I see that the author used a voltage divider and a BJT. From my understanding, the BJT is used to increase the pin current of the MCU, but why is the pin voltage divided using that voltage divider? 


There are two P MOSFETS. They are named - using names helps people answer questions more easily and reliably - here, Q1.  Similarly specifying R2 &amp; R10 helps people to zero in on your question.

When the microcontroller (U4) starts the state of pin 17 which drives the MOSFET Q1's gate is undefined. Without R10 the gate may float high and allow Q1 to turn on unintentionally.
Q4 does not have a similar pulldown (but ideally should have) but, as long as Q1 is off initially the state of Q3 is less important.  

In your case, having Q1 and Q3 on or partially on unintentionally could apply 20V to a 7.4V nominal LiIon battery. Magic smoke may then be emitted by some or all of Q1 Q3 D1 U3, the battery and maybe other components as well. This is unlikely to be desirable :-).