By raising the divider in (_XTAL_FREQ/40000.0) to give a lower delay,
Don't do this. The delay_ms() function will then not be milliseconds, but something else. If you want a shorter delay then change the value of x in delay_ms(x). If 1ms is too long then change the name of your macro to something more appropriate, eg. delay_us() or my_delay().
Use a define so you only have to change the delay value in one place, like this:-
#define TICK 18
...
for(i=0; i<ADRES; i++) delay_ms(TICK); // Delay = 1sec/v
How can I make the LED switching on/off into a separate delay, so that they will stay flickering in the intermittent color for a short while, after the button press? A loop inside a loop I would guess?
Yes, just create an outside loop that repeats the blinking pattern a certain number of times after the button press.
I can't seem to find any PWM functions on this PIC, since this would cut off some code, and make me explore some new features + make for a better LED driver.
First get it to work properly, and don't get carried away trying to make it 'better' or adding features unless there is a real need for it.
The first thing I would look at is ADC accuracy. To get a stable result you will probably have to take several readings and average them.
Also, I need some sort of "interval" on the voltage, since this is for a lithium cell, and it will need the color to be red at 3V and go towards blue at 4.2V.
Subtract 3V from the ADC reading (or make it zero if already less then 3V). If the analog input is scaled to get a reading 255 at 4.2V then you have 16.5mV per step. 3V/16.5mV = 182. Subtract 182 from the ADC reading and you get a range of 0-73 representing 3.0 to 4.2 Volts.
Make your flicker routine loop 73 times, with a step delay of 1/73 = 13ms giving a 1 second flicker period (or use a shorter delay if you want it to flicker faster). When the loop count is less than or equal to the ranged ADC value turn the Blue LED on and the Red LED off, when it is above do the opposite.
I see now that the chip is quite inadequate for the task I wanted it to do.
It is quite adequate for what you
wanted it to do.
Looking at the PIC16 family with 14 pins, would any of these be able to do the task of:
Have the battery indicator formulated in this thread (Only 2 color LED version is needed).
Be able to run a step up converter for lithium cell to 5V, at a reasonable frequency (500kHz-1MHz).
Be able to run a step down converter for 5V to lithium cell.
Have room for a few other button press features for some extra fun.
Some of the latest chips may be able to do all that, but do you have the programming skills to get it all working properly?
the batteries are 3200mah 4.35V cell
This is a large cell and potentially very dangerous. I would not consider using a PIC to charge it unless I was very sure that my code was safe.