interfacing LM35 to 89c51 microcontroller.

Status
Not open for further replies.


in your code
<b> value = ((ADC_VALUE)* 0.48876);</b>
you are converting result value is in volts but LM35 the output is per 1deg temperature 10mv output.
so convert the digital value to millivolts and the divide by 10 then display.
 

i am writing this code is avr code not a c code
but tnx for the ur replying
i am modified this program
Code:
#include<stdio.h>
#include<string.h>

#include<avr/io.h>
#include<util/delay.h>

#include "uart.h"

void ADC_Init();
char read_adc();
unsigned char ADC_calculating();
unsigned char array[10];

void main()
{
	
	_delay_ms(50);

	UART_Init(25);
    UART_TransmitString("Testing the room temperature:\r\n");

	DDRB = 0x01;
	PORTB= 0x01;
	
	DDRB = 0x00;
	PORTB= 0x00;

	ADC_Init();

	while(1)
	{
		if(bit_is_clear(PINB,0))
		{
			ADC_calculating();

			while(bit_is_clear(PINB,0));
		}
	}
}

void ADC_Init()
{
	ADCSRA = 0x00;

	ADMUX  = 0x40;
	ADCSRA = 0x86;
}

char read_adc()
{
    //select the ADC channel  
	ADMUX |= 0x01;
	
	//START THE ADC CONVERATION

	ADCSRA |= (1<<ADSC);

	//WAIT FOR CONVERATION TO COMPLETE

	while(!(ADCSRA) & (1<< ADIF));

	//CLEAR ADIF BY WRITING ONE TO IT

	ADCSRA |= 0x01;

	return(ADC);
}

unsigned char ADC_calculating()
{
	char ADC_VALUE;
	char value,temp; 

	ADC_VALUE = read_adc();

	itoa(ADC_VALUE, array, 10);
	UART_TransmitString("ADC:");
	UART_TransmitString(array);
	UART_TransmitString("\r\n");

	value = (((ADC_VALUE )/ 1023) * 5000);

	itoa(value, array, 10);
	UART_TransmitString("Ref:");
	UART_TransmitString(array);
	UART_TransmitString("\r\n");
	
	temp = value/10;

	itoa(temp, array, 10);
	UART_TransmitString("temp:");
	UART_TransmitString(array);
	UART_TransmitString("\r\n");
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…