Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with LM35 code as the LED is blinking

Status
Not open for further replies.

delifadzli

Member level 2
Joined
Feb 5, 2010
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
malaysia
Activity points
1,774
#include <16F877A.H>
#device ADC=10
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)


#include "E:\note ngaji\FYP\stuff last sem\code\led experiment\brum\Flexlcd2.c"

//==========================


void main(void)
{
int16 temp_adc;
int temp;

setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(PIN_A1);
set_adc_channel(1); //read analog input from channel 1


lcd_init();

lcd_putc("\fTemperature:\n");

while(1)
{
temp_adc = read_adc();

temp = 5.00*temp_adc*100.00/1023.00;
lcd_gotoxy(1,2);
printf(lcd_putc,"%d",temp);
delay_ms(3000);



if ((temp<20) && (input(PIN_B7)==1))

{
output_high(PIN_D7);
delay_ms(100);
}
else if ( (temp>= 20) && (temp_adc <30) && (input(PIN_B7)==1))
{
output_high(PIN_D6);
delay_ms(100);
}
else if ((temp_adc >= 30) && (input(PIN_B7)==1))
{
output_high(PIN_D5);
delay_ms(100);
}
else
{
output_high(PIN_D4);
delay_ms(100);
}
}

}
Code:
here is the source code that using LM35 as a sensor...

here i like to experiment with the temperature produce by LM35 to produce LED output.. For example, if the temperature >>30 deg--- the LED at Pin D5 should be on...am i right...the problem....the led doesn't on...easy compulsory to connect the LED with resistor??...urgent...even if u see it might be too simple for ur guys...

Added after 1 minutes:

Code:
#include <16F877A.H>
#device ADC=10
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)


#include "E:\note ngaji\FYP\stuff last sem\code\led experiment\brum\Flexlcd2.c"

//==========================


void main(void)
{
       int16 temp_adc;
       int temp;

        setup_adc(ADC_CLOCK_DIV_8);
        setup_adc_ports(PIN_A1);
        set_adc_channel(1); //read analog input from channel 1


        lcd_init();

         lcd_putc("\fTemperature:\n");

          while(1)
            {
            temp_adc = read_adc();

            temp = 5.00*temp_adc*100.00/1023.00;
         lcd_gotoxy(1,2);
            printf(lcd_putc,"%d",temp);
            delay_ms(3000);



            if ((temp<20) && (input(PIN_B7)==1))

      {
         output_high(PIN_D7);
         delay_ms(100);
      }
      else if ( (temp>= 20) && (temp_adc <30) && (input(PIN_B7)==1))
      {
         output_high(PIN_D6);
         delay_ms(100);
         }
      else if ((temp_adc >= 30) && (input(PIN_B7)==1))
         {
         output_high(PIN_D5);
         delay_ms(100);
         }
       else
      {
      output_high(PIN_D4);
      delay_ms(100);
       }
        }

}


correction

isn't compulsory to connect the LED with resistor....sorry for my english
 

want to ask....

what is the problem?
please be clear
 

Re: want to ask....

the LED just blinking . For example if temperature - more than 30 degree... the LED at pin D5 just blink...not totally on....isn't the code wrong?

Added after 27 minutes:

Code:
#include <16F877A.H>
#device ADC=10
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)


#include "E:\note ngaji\FYP\stuff last sem\code\led experiment\brum\Flexlcd2.c"

//==========================

#define      LED1     PIN_D7
#define      LED2     PIN_D6
#define      LED3     PIN_D5
#define      LED4     PIN_D4

void main(void)
{
       int16 temp_adc;
       int temp;

        setup_adc(ADC_CLOCK_DIV_8);
        setup_adc_ports(PIN_A1);
        set_adc_channel(1); //read analog input from channel 1


        lcd_init();

         lcd_putc("\fTemperature:\n");

          while(1)
            {
            temp_adc = read_adc();

            temp = 5.00*temp_adc*100.00/1023.00;
         lcd_gotoxy(1,2);
            printf(lcd_putc,"%d",temp);


         {
            if(input(PIN_B7)==1)
         {
    if((temp<20))
   {
       //delay_ms (500);
      output_high(LED1);

   }    else
   {
      output_low(LED1);
    }

    if ((temp>= 20) && (temp_adc <30))
   {
      output_high(LED2);

     }
      else
    {
     output_low(LED2);
     }

     if ((temp_adc >= 30))
    {
       output_high(LED3);

    }
     else
     {

     output_low(LED3);
     }
       }
else

   output_high(PIN_D4);
}
        }

}

ok...i managed to find the problem...mistype the delay value...done...thanks for ask....
 

want to ask....

you definitely can benefit a class or two on structured programming.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top