delifadzli
Member level 2
#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);
}
}
}
Added after 1 minutes:
#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