#include "C:\MentorProjects\Current_Dodge\PIC CODE\Current Dodge.h" #define LED1 PIN_C0 // RODE LED +50 AMPERE #define LED2 PIN_B4 // GELE LED +40 AMPERE #define LED3 PIN_C2 // GELE LED +30 AMPERE #define LED4 PIN_C3 // GELE LED +20 AMPERE #define LED5 PIN_C4 // GELE LED +10 AMPERE #define LED6 PIN_C5 // GROENE LED 0 AMPERE #define LED7 PIN_C6 // GELE LED -10 AMPERE #define LED8 PIN_C7 // GELE LED -20 AMPERE #define LED9 PIN_B0 // GELE LED -30 AMPERE #define LED10 PIN_B1 // GELE LED -40 AMPERE #define LED11 PIN_B2 // RODE LED -50 AMPERE #define PWM PIN_C1 // PWM OUTPUT void main() { int16 Current, PWM_value; setup_adc_ports(AN0_TO_AN1|VSS_VDD); setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_ccp2(CCP_PWM); set_pwm2_duty(512); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); 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); 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 50: output_low(LED1); output_low(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 75: output_low(LED1); output_low(LED2); output_low(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 100: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_high(LED5); output_high(LED6); output_low(LED7); output_low(LED8); output_low(LED9); output_low(LED10); output_low(LED11); break; case 125: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_low(LED7); output_low(LED8); output_low(LED9); output_low(LED10); output_low(LED11); break; case 150: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_high(LED7); output_low(LED8); output_low(LED9); output_low(LED10); output_low(LED11); break; case 175: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_high(LED7); output_high(LED8); output_low(LED9); output_low(LED10); output_low(LED11); break; case 200: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_high(LED7); output_high(LED8); output_high(LED9); output_low(LED10); output_low(LED11);; break; case 225: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_high(LED7); output_high(LED8); output_high(LED9); output_high(LED10); output_low(LED11); break; case 250: output_low(LED1); output_low(LED2); output_low(LED3); output_low(LED4); output_low(LED5); output_high(LED6); output_high(LED7); output_high(LED8); output_high(LED9); output_high(LED10); output_high(LED11); break; } } }