anil404
Newbie level 4
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 isPHP: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.