Estoy tratando de leer la temperatura witr LM34 pero solo lee de 0 a 50 F y la rabia de ut se sabe de -50 a +300 F, así que pregunté mucho y encontré que mi circuito a continuación no puede lea un voltaje negativo,
entonces,¿quédebohacerparaleerelvoltajenegativo?Tambiénloencontréporqueusounsolopinparaleerlatemperatura,estohacequesolomidaunpardegrados,notodoslosgrados,asíque¿quédebohacerparaleertodoslosgradosycuálseríaelcódigo?micódigo
#include<util/delay.h>#include<stdio.h>#include<avr/io.h>//defineportC#defineLCD_DDDRDDRC/*LCDDATADDR*/#defineLCD_DPRTPORTC/*LCDDATAPORT*/#defineLCD_DPINPINC/*LCDDATAPIN*///defineportD#defineLCD_CDDRDDRD/*LCDCOMMANDDDR*/#defineLCD_CPRTPORTD/*LCDCOMMANDPORT*/#defineLCD_CPINPIND/*LCDCOMMANDPIN*/#defineLCD_RS0//LCDRS#defineLCD_RW1//LCDRW#defineLCD_EN2//LCDENvoiddelay_us(unsignedintd){while(d){_delay_us(1);d--;}}voidlcdCommand(unsignedcharcmnd){LCD_DPRT=cmnd;//sendcmndtodataportLCD_CPRT&=~(1<<LCD_RS);//RS=0forcommandLCD_CPRT&=~(1<<LCD_RW);//RW=0forwriteLCD_CPRT|=(1<<LCD_EN);//EN=1forH-to-Lpulsedelay_us(1);//waittomakeenablewideLCD_CPRT&=~(1<<LCD_EN);//EN=0forH-to-Tpulsedelay_us(100);//waittomakeenablewide}voidlcdData(unsignedchardata){LCD_DPRT=data;//senddatatodataportLCD_CPRT|=(1<<LCD_RS);//RS=1fordataLCD_CPRT&=~(1<<LCD_RW);//RW=0forwriteLCD_CPRT|=(1<<LCD_EN);//EN=1forH-to-Lpulsedelay_us(1);//waittomakeenablewideLCD_CPRT&=~(1<<LCD_EN);//EN=0forH-to-lpulsedelay_us(100);//waittomakeenablewide}voidlcd_init(){LCD_DDDR=0xff;//allpinsinportCoutputLCD_CDDR=0xff;//allpinsinportDoutputLCD_CPRT&=~(1<<LCD_EN);//LCD_EN=0delay_us(2000);//waitforinitlcdCommand(0x38);//init.lcd2line,5x7matrixlcdCommand(0x0e);//displayon,cursoronlcdCommand(0x01);//clearLCDdelay_us(2000);//waitlcdCommand(0x06);//shiftcursorright}voidlcd_gotoxy(unsignedcharx,unsignedchary){unsignedcharfirstCharAdr[]={0x80,0xc0,0x94,0xd4};lcdCommand(firstCharAdr[y-1]+x-1);delay_us(100);}voidlcd_print(char*str){while(*str){lcdData(*str++);}}intmain(void){charbuffer[3];DDRA|=0b00000111;//pin0,1,2output&pin3,4,5,6,7input.DDRB|=0xFF;//makeportBoutput.ADCSRA|=0x87;//makeADCenableandselectck/128.ADMUX|=0xE6;//2.56vvref,selectADC6andmakeleftjustified.lcd_init();lcd_gotoxy(1,1);lcd_print("temperature:");
while(1)
{
ADCSRA |= (1 << ADSC); //start conversion
while (ADCSRA & (1 << ADSC));
PORTB = ADCH;
if (ADCSRA&0b00000101)
{
sprintf(buffer, "%d", PORTB);
lcd_gotoxy(1, 2);
lcd_print(buffer);
}
}
return 0;
}