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.

interfacing LM35 to 89c51 microcontroller.

Status
Not open for further replies.
hi
this lm 35 interfacing with atmega8 in avr program
see and tell any misteck
the output is differnt form
tell me any correction of this program
Code:
#include<avr/io.h>
#include<util/delay.h>

#include "uart.h"

void ADC_Init();
float read_adc();

unsigned char ADC_calculating();
unsigned char a;
unsigned char b;

void main()
{

	char temp;

	_delay_ms(50);

	UART_Init(25);
	UART_TransmitString("To Display the Temperature in Centigrade \r\n");

	ADC_Init();
	
	while(1)
	{		
		//convert calue to tempature

		temp = ADC_calculating();

		a = temp % 10;
		b = temp / 10;
	
		_delay_ms(100);
				
		UART_TransmitByte(a+48);
		UART_TransmitByte(b+48);
		UART_TransmitString("\r\n");				

		_delay_ms(100);
	}
}

void ADC_Init()
{
	ADMUX  = (1<<REFS0);
	ADCSRA = 0x85;
}

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

	ADCSRA |= (1<<ADSC);

	//WAIT FOR CONVERATION TO COMPLETE

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

	//CLEAR ADIF BY WRITING ONE TO IT

	ADCSRA |= (1<< ADIF);

	return(ADC);
}

unsigned char ADC_calculating()
{
	float ADC_VALUE = 0;
	float value=0; 

	ADC_VALUE = read_adc();

	value = ((ADC_VALUE)* 0.48876);
	
	return(value);
}

- - - Updated - - -

the output of the proggram is
PHP:
To	Display	the	Temperature	in	Centigrade
00
8:
0<
4<
+$
0$
'%
*%
/%
'&
'&
(&
+&
,&
/&
)'
+'
*'
-'
0'
0'
0'
)(
*(
)(
+(
-(
-(
,(
.(
/(
.(
/(
()
')
0(
()
))
()
()
+)
+)
))
+)
,)
+)
+)
.)
.)
,)
-)
/)
.)
-)
/)
0)
.)
.)
0)
.)
-)
/)
/)
.)
.)
/)
/)
.)
/)
0)
/)
/)
0)
/)


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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top