mas maganda kung ang gamiting mong +Vref eh yung Vcc mo na at -Vref eh yung ground.
#include <16F877.h> #device ADC=10 #fuses HS,NOWDT,NOPROTECT #use delay(clock=10000000) //=========setup port for F877===================================== #byte lcdport = 0x06 // portA=05h B=06h C=07h D=08h E=09h #byte lcdport_tris = 0x86 // trisA=85h B=86h C=87h D=88h E=89h #bit nok_sclk = lcdport.5 //pin2 LCD portX5 #bit nok_sda = lcdport.6 //pin3 LCD portX6 #bit nok_dc = lcdport.7 //pin4 LCD portX7 #bit nok_cs = lcdport.0 //pin5 LCD portX0 #bit nok_res = lcdport.1 //pin8 LCD portX1 //============================================================ #include "3310.c" int16 value,value1;void init();void main() { init(); setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0_AN1_AN3); set_adc_channel(0); while(true) { delay_ms(1); value=read_adc(); value1=5.00 * value * 100.00/1023.00; nokia_gotoxy(1,1); printf(nokia_printchar,"adc RAW:%ld",value); nokia_gotoxy(1,2); printf(nokia_printchar," deg C:%f",(float)value1); //nokia_gotoxy(1,3); //printf(nokia_printchar," deg F : %ld",degf); } }void init() { lcdport_tris = 0x00; // lcdport all bits are outputs port_b_pullups(TRUE); nokia_init(); }
ooopppsss ..wala siya negative values.. pero ADC WILL NOT accept negative values.. pano kaya ito??? anyways, ok na rin itong toy room temp.. or pang READ ng temperature sa kilikili.. hehe addo-on nalang ng STORE VALUE (for reading) or freeze the current reading to be viewed, then after a few secs, read na ulit... more room for experimentations
add ka ng offset in such a way na yung minimum negative input mo eh equal to zero pagdating sa ADC pin, to do this you may use a summing amplifier or other techniques.
#include <16F877.h>//config bits#FUSES NOWDT //No Watch Dog Timer#FUSES HS //High speed Osc (> 4mhz)#FUSES NOPUT //No Power Up Timer#FUSES PROTECT //Code protected from reads#FUSES NOBROWNOUT //No brownout reset#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O#FUSES NOCPD //No EE protection#FUSES NOWRT //Program memory not write protected#FUSES NODEBUG //No Debug mode for ICD//10-bit adc output#device adc=10#use delay(clock=20000000)#byte lcdport = 0x06 // PORTB#include "3310_ccs.c" //3310 files here!void main(){ unsigned long adc_val; char adc_val_string[10]; float temp_val; char temp_val_string[10]; set_tris_b(0x00); setup_adc_ports(AN0_AN1_VSS_VREF); setup_adc(ADC_CLOCK_DIV_32); //LM35 connected to RA1/AN1 set_adc_channel(1); delay_us(50); nokia_init(); while(1) { nokia_clean_ddram(); //clear lcd screen adc_val = read_adc(); //read adc //display 10-bit adc nokia_gotoxy(2,1); printf(nokia_printchar, "ADC value:"); sprintf(adc_val_string, "%Lu" , adc_val); nokia_gotoxy(4,2); printf(nokia_printchar, adc_val_string); //display calculated temperature value temp_val = (adc_val / 1024.0) * 100.0; nokia_gotoxy(2,3); printf(nokia_printchar, "Temperature:"); sprintf(temp_val_string, "%0.2f" , temp_val); nokia_gotoxy(4,4); printf(nokia_printchar, temp_val_string); printf(nokia_printchar, " deg."); delay_ms(1000); }}