problem with led

Discussion in 'Embedded Systems and Microcontrollers' started by 255s, Sep 25, 2012.

  1. 255s

    Thread Starter New Member

    Sep 25, 2012
    2
    0
    Hi.

    I have two LED connected to GP4 and GP5 and a POT connected to GP0/AN0.The LED does not glow different rates according the to ADC reading.

    Code ( (Unknown Language)):
    1.  
    2. #include <12F510.h>
    3. #include <stdio.h>
    4. #FUSES NOWDT,INTRC,NOPROTECT,NOMCLR
    5. #use delay(clock=8000000)
    6. #define adc
    7. #define GP0 PIN_B0
    8. #define GP1 PIN_B1
    9. #define GP2 PIN_B2
    10. #define GP3 PIN_B3
    11. #define GP4 PIN_B4
    12. #define GP5 PIN_B5
    13.  
    14. unsigned int value,i;
    15. unsigned long int n;
    16.  
    17.  
    18. void LED_RED(void)
    19. {
    20.    output_low (GP4);
    21.    output_high (GP5);
    22. }
    23.  
    24. void LED_GREEN(void)
    25. {
    26.    output_high (GP4);
    27.    output_low (GP5);
    28. }
    29.  
    30. void LED_OFF(void)
    31. {
    32.    output_low (GP4);
    33.    output_low (GP5);
    34. }
    35.  
    36. void main()
    37. {
    38.    setup_comparator(NC_NC);
    39.    setup_adc(ADC_CLOCK_INTERNAL);
    40.    setup_adc_ports(AN0_AN2);
    41.    
    42.    while (TRUE)
    43.    {
    44.      read_adc (ADC_ON);
    45.       LED_OFF();
    46.       delay_ms(500);
    47.       set_adc_channel(0);
    48.       delay_us(40);
    49.       value=read_adc(ADC_START_AND_READ);
    50.       if (value>140)
    51.       {
    52.       for (i=0;i<=n;i++)
    53.       {
    54.       LED_RED();
    55.       delay_ms(500);
    56.       LED_OFF();
    57.       delay_ms(500);
    58.       }
    59.       }
    60.       else
    61.       {
    62.       LED_GREEN();
    63.       delay_ms(1000);
    64.       }
    65.       }
    66.       }
    67.  
    please guide me to light up the led based on ADC value.......
     
    Last edited by a moderator: Sep 25, 2012
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    255s likes this.
  3. 255s

    Thread Starter New Member

    Sep 25, 2012
    2
    0
    Thanks.......
     
Loading...