PIC 16F876 Automotive Ammeter

by Jody Wisman

for the Olimex sponsored PCB contest

This is a replacement for the Ampere meter in a old Dodge (from 1978 or so)… It indicates the current flow and the amount of current. So you can see if you are charging the battery or discharging the battery and with how much current… Software in CCS C. PCB in Mentor Graphics.

Code excerpt: See code.zip for full source code

...
    While(1)
    {
		set_adc_channel(0);
		delay_ms(5);
        Current = read_adc();
		set_adc_channel(1);
		delay_ms(5);
        PWM_value = read_adc();
		set_pwm2_duty(PWM_value);
        if((Current > 0) && (Current < 23))		{ Current = 0;};
        if((Current > 23) && (Current < 46))	{ Current = 25;};
        if((Current > 46) && (Current < 69))	{ Current = 50;};
        if((Current > 69) && (Current < 93))	{ Current = 75;};
        if((Current > 93) && (Current < 116))	{ Current = 100;};
        if((Current > 116) && (Current < 139))	{ Current = 125;};
        if((Current > 139) && (Current < 163))	{ Current = 150;};
        if((Current > 163) && (Current < 186))	{ Current = 175;};
        if((Current > 186) && (Current < 209))	{ Current = 200;};
        if((Current > 209) && (Current < 233))	{ Current = 225;};
        if((Current > 233) && (Current < 255))	{ Current = 250;};

        switch(Current)
        {
        case 0:
            output_high(LED1);
            output_high(LED2);
            output_high(LED3);
            output_high(LED4);
            output_high(LED5);
            output_high(LED6);
            output_low(LED7);
            output_low(LED8);
            output_low(LED9);
            output_low(LED10);
            output_low(LED11);
            break;
        case 25:
            output_low(LED1);
            output_high(LED2);
            output_high(LED3);
...