[SOLVED] How to compare the two temperatures from lm35 to pic18f4550?

Status
Not open for further replies.

vgavale

Newbie level 2
Joined
Feb 28, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
91
can read the values of two lm35 also can display. but how to compare both temperature?
i want to compare values t1 and t2.plz help.


[c code]


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
LCD DATA port----PORT B
signal port------PORT D
    rs-------RE0
    rw-------RE1
    en-------RE2
*/
#include <p18f4550.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
 
//LCD data pins connected to PORTD and control pins connected to PORTE
#define LCD_DATA    PORTB               //LCD data port
#define ctrl        PORTD              //LCD signal port
#define en          PORTDbits.RD7      // enable signal
#define rw          PORTDbits.RD6      // read/write signal
#define rs          PORTDbits.RD5     // register select signal
#define Channel0 0b00000000
#define Channel1 0b00000100
 
void ADC_Init();
void Select_Channel(unsigned char Channel);
unsigned int Get_ADC_Result(void);
void Start_Conversion(void);
 
void myMsDelay (unsigned int time);
 
//LCD function definitions
void LCD_Busy(void);
void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);
void LCD_write_string(static char *str);
 
/*The following lines of code perform interrupt vector relocation to work with the USB bootloader. These must be
used with every application program to run as a USB application.*/
extern void _startup (void);
#pragma code _RESET_INTERRUPT_VECTOR = 0x1000
 
void _reset (void)
{
        _asm goto _startup _endasm
}
 
#pragma code
#pragma code _HIGH_INTERRUPT_VECTOR = 0x1008
void high_ISR (void)
{
}
 
#pragma code
#pragma code _LOW_INTERRUPT_VECTOR = 0x1018
void low_ISR (void)
{
}
#pragma code
//Function to generate delay
void myMsDelay (unsigned int time)
{
        unsigned int i, j;
        for (i = 0; i < time; i++)
                for (j = 0; j < 710; j++);/*Calibrated for a 1 ms delay in MPLAB*/
}
 
 
// Function to initialise the LCD
void init_LCD(void)
{
    LCD_cmd(0x38);      // initialization of 16X2 LCD in 8bit mode
    myMsDelay(15);
 
    LCD_cmd(0x01);      // clear LCD
    myMsDelay(15);
 
    LCD_cmd(0x0C);      // cursor off
    myMsDelay(15);
 
    LCD_cmd(0x80);      // ---8 go to first line and --0 is for 0th position
    myMsDelay(15);
 
            // ---8 go to first line and --0 is for 0th position
 
    return;
}
//Function to pass command to the LCD
void LCD_cmd(unsigned char cmd)
{
    LCD_DATA = cmd;
    rs = 0;
    rw = 0;
    en = 1;
    myMsDelay(15);
    en = 0;
    myMsDelay(15);
    return;
}
 
//Function to write data to the LCD
void LCD_write(unsigned char data)
{
    LCD_DATA = data;
    rs = 1;
    rw = 0;
    en = 1;
    myMsDelay(5);
    en = 0;
    myMsDelay(5);
    return ;
}
//Function to split the string into individual characters and call the LCD_write function
void LCD_write_string(static char *str)   //store address value of the string in pointer *str
{
    int i = 0;
    while (str[i] != 0)
    {
        LCD_write(str[i]);      // sending data on LCD byte by byte
        myMsDelay(15);
                i++;
    }
    return;
}
 
void ADC_Init()
{
 ADCON0=0b00000000; //A/D Module is OFF no channel selected
 ADCON1=0b00001110; // Reference as VDD & VSS, AN0 set as analog pins
 ADCON2=0b10001110; // Result is right Justified
                    //Acquisition Time 2TAD
                    //ADC Clk FOSC/64
 ADCON0bits.ADON=1; //Turn ON ADC module
}
 
void Select_Channel(unsigned char Channel)
{
 ADCON0=ADCON0 & 0b11000001;    
 ADCON0=ADCON0 | Channel;   //selecting channel no 0
}
 
void Start_Conversion()
{
 ADCON0bits.GO=1;
}
 
 
//If you do not wish to use adc conversion interrupt you can use this
//to do conversion manually. It assumes conversion format is right adjusted
unsigned int Get_ADC_Result()
{
 
 unsigned int ADC_Result=0;
 while(ADCON0bits.GO);
 ADC_Result=ADRESL;
 ADC_Result|=((unsigned int)ADRESH) << 8;
return ADC_Result;
 
}
 
 void main(void)
{
//unsigned int adc_val;
unsigned int a;
unsigned char i=0;
unsigned char pot0[6],pot1[6];
unsigned float val,val1;
unsigned double t2,t1,x1,x2;
//char buffer[20];
 
   char var1[] = "LM35 test";
     ADCON1 = 0x0F;        //Configuring the PORTE pins as digital I/O 
     TRISB = 0x00;         //Configuring PORTD as output
     TRISD = 0x00;         //Configuring PORTE as output  
     TRISAbits.TRISA0=1;        //RA0=Input for analog input
    TRISDbits.TRISD3=0; //ULN ON
     TRISDbits.TRISD4=0;    //Buzzer set
        
     
    
     init_LCD();           // initialization of LCD
     myMsDelay(50);       // delay of 50 mili seconds
      ADC_Init();
     LCD_write_string(var1);
while(1)
{
 
Select_Channel(Channel0);
Start_Conversion();
 
val= Get_ADC_Result();
 
t1=(double) val*50/1023*1000;   //atm temp
     x1=(double)t1/100;
//unsigned float  x;
 
  itoa(x1,pot0);
  //LCD_cmd(0xC0); // Move cursor to line 2 position 1
  // LCD_cmd(0x8c);
 for(i=0;pot0[i]!='\0';i++)
{
     LCD_write (pot0[i]);
}
  myMsDelay(1);
 
 
 
** * *// LCD_write(val); * * * * *// Display the temperature*
* * * //*LCD_write(0xDF);
* * * * //LCD_write('C');
 
Select_Channel(Channel1);
Start_Conversion();
val1= Get_ADC_Result();
t2=(double) val1*50/1023*1000;
     x2=(double)t2/100;
itoa(x2,pot0);
 
 // LCD_cmd(0x8c);
  for(i=0;pot1[i]!='\0';i++)
{
     LCD_write (pot1[i]);
}
  myMsDelay(100);
 
 
 
** * *// LCD_write(val); * * * * *// Display the temperature*
* * * //*LCD_write(0xDF);
* * * * //LCD_write('C');
//}
 
//while(1)
//{
 
LCD_cmd(0xC0); // Move cursor to line 2 position 1
/*if(t1<15)
//{
  w hile(t2!=80)*/
while((t1<15) && (t2 != 80))  
{
     for(i=0;pot0[i]!='\0';i++)
    {
     LCD_write (pot0[i]);
    }
 myMsDelay(100);
 
}
  *
* * *LCD_write(0xDF);
* * LCD_write('C');
 
  myMsDelay(1);
   
    PORTDbits.RD3=0;
     PORTDbits.RD4=1;
 
 
 /*else if(15<t1<25)
{
  while(t2!=60)*/
while((15<t1<25) && (t2 !=60))
{
     for(i=0;pot0[i]!='\0';i++)
    {
     LCD_write (pot0[i]);
    }
}
LCD_write(0xDF);
* * LCD_write('C');
  myMsDelay(1);
   
    PORTDbits.RD3=0;
     PORTDbits.RD4=1;
 
 
}
/*else
{
 
  while(t2!=40)*/
while((t1>25) && (t2!=40))
{
     for(i=0;pot0[i]!='\0';i++)
    {
     LCD_write (pot0[i]);
    }
}
    LCD_write(0xDF);
* * LCD_write('C');
    myMsDelay(1);
    PORTDbits.RD3=0;
    PORTDbits.RD4=1;
 
}
}
}

 
Last edited by a moderator:

hello


Compare to what ?
some threshold values ?
compare each other, wich is superior as the other ?
explain more ..


you better have to use raw value (ADC result) for comparaison
so between integer value..if scaling in physical unit (°C) are the same for both sensors
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…