ค่าที่ได้ผมออกมาตามนี้ไม่รู้มันถูกรึป่าว แถม ค่าที่วัดจากเซนเซอร์มันแกว่งยุ2ค่าครับ 284.02กับ325.37ประมาณนี้ครับ
ช่วยดูให้หน่อยครับว่าโค้ดผมถูกมั้ยครับ
#include <16F887.h> #device adc=10 #fuses HS,NOWDT,NOPROTECT,NOLVP #define LCD_ENABLE_PIN PIN_D2 #define LCD_RS_PIN PIN_D0 #define LCD_RW_PIN PIN_D1 #define LCD_DATA4 PIN_D4 #define LCD_DATA5 PIN_D5 #define LCD_DATA6 PIN_D6 #define LCD_DATA7 PIN_D7 #use delay(clock=8000000) #include <lcd.c> #include <touch.c> // Read 1 wire BYTE ReadTemp_DS18B20(void) { BYTE i, buffer[9]; BYTE temp,sign; if (touch_present()) { touch_write_byte(0xCC); touch_write_byte (0x44); delay_ms(100); touch_present(); touch_write_byte(0xCC); touch_write_byte (0xBE); for(i=0; i<9;i++) buffer = touch_read_byte(); } temp = (buffer[1]<<4)|(buffer[0]>>4); if(buffer[1]&0xF0) temp=(-1)*temp; return(temp); } void main(void) { BYTE DS18B20_temp; SETUP_ADC(ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_8); SETUP_ADC_PORTS(sAN0|VSS_VDD); float averageVoltage; float CoefficientVolatge; float ECcurrent; float TempCoefficient; float ECcurrent1; lcd_init(); while(TRUE) { DS18B20_temp=ReadTemp_DS18B20(); SET_ADC_CHANNEL(0); averageVoltage=READ_ADC(); averageVoltage=(float)5000/1024*averageVoltage; TempCoefficient=(float)1.0+0.0185*(DS18B20_temp-25.0); CoefficientVolatge=(float)averageVoltage/TempCoefficient; ECcurrent=(float)CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge+CoefficientVolatge/10; lcd_putc("\f"); lcd_gotoxy(3,1); printf(lcd_putc,"Temp :%d %cC",DS18B20_temp,0xDF); lcd_gotoxy(3,2); printf(lcd_putc,"EC :%f ", ECcurrent); delay_ms(1000); } } |