problem with led

Thread Starter

255s

Joined Sep 25, 2012
2
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.

Rich (BB code):
#include <12F510.h>
#include <stdio.h>
#FUSES NOWDT,INTRC,NOPROTECT,NOMCLR
#use delay(clock=8000000)
#define adc
#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3
#define GP4 PIN_B4
#define GP5 PIN_B5

unsigned int value,i;
unsigned long int n;


void LED_RED(void)
{
   output_low (GP4);
   output_high (GP5);
} 

void LED_GREEN(void)
{
   output_high (GP4);
   output_low (GP5);
} 

void LED_OFF(void)
{
   output_low (GP4);
   output_low (GP5);
} 

void main()
{
   setup_comparator(NC_NC); 
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(AN0_AN2);
   
   while (TRUE)
   {
     read_adc (ADC_ON); 
      LED_OFF();
      delay_ms(500);
      set_adc_channel(0);
      delay_us(40); 
      value=read_adc(ADC_START_AND_READ); 
      if (value>140)
      {
      for (i=0;i<=n;i++)
      {
      LED_RED();
      delay_ms(500);
      LED_OFF();
      delay_ms(500);
      }
      }
      else
      {
      LED_GREEN();
      delay_ms(1000);
      }
      }
      }
please guide me to light up the led based on ADC value.......
 
Last edited by a moderator:
Top