Termometer Digital Pada LM35
- Langsung dikalibrasi dalam derajat Celcius
- Linear faktor konversi 10,0 mV / º C
- Akurasi dijamin sebesar 0,5 º C (di +25 º C)
- Jangkauan kerja dari -55 º C sampai 150 º C
- Cocok untuk pengukuran jarak jauh
- Biaya Murah
- Konsumsi arus kurang dari 60 mA
- Rendahnya impedansi output, 0,1 ohm pada 1 mA beban.
Rancangan skema termometer digital saya adalah pengembangan dari termometer digital sederhana (atau lebih tepatnya, versi pada ATTiny261). Termometer digital ini menggunakan hasil modifikasi dari LM35 dengan output diferensial. Sirkuit LM35 ditunjukkan pada gambar di bawah ini :
Seperti yang dapat dilihat dari gambar, sinyal output diukur dengan voltmeter. Pada suhu nol, tegangan output dari 0.69V (dengan menggunakan BC857A transistor). Suhu di bawah nol menyebabkan penurunan tegangan output (10 mV per 1 º C).Kenaikan suhu di atas nol menyebabkan peningkatan tegangan output. Skema termometer ditunjukkan gambar dibawah ini :
Kode Program :
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
#include <tiny261.h>
// Declare your global variables here
/*
*/
#include <delay.h>
#include <math.h>
#define DISP1_ON PORTA&=0xEF //PORTA&=~(1<<4)
#define DISP2_ON PORTA&=0xDF //PORTA&=~(1<<5)
#define DISP3_ON PORTA&=0xF7 //PORTA&=~(1<<3)
#define DISP4_ON PORTA&=0xFD //PORTA&=~(1<<1)
#define DISP1_OFF PORTA|=~0xEF //PORTA|=(1<<4)
#define DISP2_OFF PORTA|=~0xDF //PORTA|=(1<<5)
#define DISP3_OFF PORTA|=~0xF7 //PORTA|=(1<<3)
#define DISP4_OFF PORTA|=~0xFD //PORTA|=(1<<1)
#define A_ON PORTB&=~(1<<2)
#define B_ON PORTB&=~(1<<0)
#define C_ON PORTA&=~(1<<0)
#define D_ON PORTA&=~(1<<6)
#define E_ON PORTA&=~(1<<7)
#define F_ON PORTB&=~(1<<3)
#define G_ON PORTB&=~(1<<1)
#define DP_ON PORTA&=~(1<<2)
#define A_OFF PORTB|=(1<<2)
#define B_OFF PORTB|=(1<<0)
#define C_OFF PORTA|=(1<<0)
#define D_OFF PORTA|=(1<<6)
#define E_OFF PORTA|=(1<<7)
#define F_OFF PORTB|=(1<<3)
#define G_OFF PORTB|=(1<<1)
#define DP_OFF PORTA|=(1<<2)
#define Minus 1
#define Plus 0
#define MinusOn PORTB&=~(1<<6)
#define MinusOff PORTB|=(1<<6)
unsigned char signs;
void init_all(void);
void display_temp(unsigned int);
void display_digit(unsigned char);
unsigned int get_temp(void);
void main(void)
{
unsigned int temp;
unsigned char i;
init_all();
while(1)
{
temp=get_temp();
delay_ms(10);
display_temp(temp);
}
}
void init_all(void)
{
//set output pins
DDRA|=(1<<4);
DDRA|=(1<<5);
DDRA|=(1<<3);
DDRA|=(1<<1);
DDRB|=(1<<2);
DDRB|=(1<<0);
DDRA|=(1<<0);
DDRA|=(1<<6);
DDRA|=(1<<7);
DDRB|=(1<<3);
DDRB|=(1<<1);
DDRA|=(1<<2);
DDRB|=(1<<6);
//turn all displays OFF
DISP1_OFF;
DISP2_OFF;
DISP3_OFF;
DISP4_OFF;
A_OFF;
B_OFF;
C_OFF;
D_OFF;
E_OFF;
F_OFF;
G_OFF;
DP_OFF;
//initialize ADC
//AVCC reference select at 2.56V
ADMUX |= (1<<7);
ADMUX &= ~(1<<6);
ADCSRB |= (1<<4);
//right adjust the ADC result
ADMUX &= ~(1<<5);
//analog channel select
ADMUX &= ~(1<<4);
ADMUX |= (1<<3);
ADMUX &= ~(1<<2);
ADMUX &= ~(1<<1);
ADMUX &= ~(1<<0);
//ADC enable
ADCSRA |= (1<<7);
//ADC Stop
ADCSRA &= ~(1<<6);
//Disable free run
ADCSRB &=0xF8;
//clear ADC interrupt flag
ADCSRA |= (1<<4);
//disable ADC interrupt
ADCSRA &= ~(1<<3);
//ADC CK prescaler set to 2
ADCSRA &= ~(1<<2);
ADCSRA &= ~(1<<1);
ADCSRA &= ~(1<<0);
}
unsigned int get_temp(void)
{ int ADC_result;
int temperature;
//start ADC
ADCSRA |= (1<<6);
//wait for conversion complete
while((ADCSRA & 0b00010000) != 0b00010000)
{;}
//clear ADC interrupt flag
ADCSRA |= (1<<4);
//get result
ADC_result = ADCL + ADCH*256 ;
ADC_result= ADC_result-275;
temperature=(5* ADC_result)>>1;
if (temperature < 0)
{
temperature = abs(temperature);
signs=Minus;
}
else signs = Plus;
return ((unsigned int) temperature);
}
void display_temp( unsigned int data)
{
unsigned char hundredths, tenths, ones;
hundredths =(unsigned char)(data/100);
tenths = (data - (unsigned int)hundredths*100)/10;
ones = data - (unsigned int)hundredths*100 - (unsigned int)tenths*10;
if(signs == Minus) MinusOn;
else MinusOff;
DISP1_ON;
DISP2_OFF;
DISP3_OFF;
DISP4_OFF;
display_digit(hundredths);
delay_ms(5);
DISP1_OFF;
DISP2_ON;
DISP3_OFF;
DISP4_OFF;
display_digit(tenths);
delay_ms(5);
DISP1_OFF;
DISP2_ON;
DISP3_OFF;
DISP4_OFF;
display_digit('.');
delay_ms(5);
DISP1_OFF;
DISP2_OFF;
DISP3_ON;
DISP4_OFF;
display_digit(ones);
delay_ms(5);
DISP1_OFF;
DISP2_OFF;
DISP3_OFF;
DISP4_ON;
display_digit('C');
delay_ms(5);
}
void display_digit(unsigned char data)
{
switch(data)
{
case 0 :
{
A_ON;
B_ON;
C_ON;
D_ON;
E_ON;
F_ON;
G_OFF;
DP_OFF;
break;
}
case 1 :
{
A_OFF;
B_ON;
C_ON;
D_OFF;
E_OFF;
F_OFF;
G_OFF;
DP_OFF;
break;
}
case 2 :
{
A_ON;
B_ON;
C_OFF;
D_ON;
E_ON;
F_OFF;
G_ON;
DP_OFF;
break;
}
case 3 :
{
A_ON;
B_ON;
C_ON;
D_ON;
E_OFF;
F_OFF;
G_ON;
DP_OFF;
break;
}
case 4 :
{
A_OFF;
B_ON;
C_ON;
D_OFF;
E_OFF;
F_ON;
G_ON;
DP_OFF;
break;
}
case 5 :
{
A_ON;
B_OFF;
C_ON;
D_ON;
E_OFF;
F_ON;
G_ON;
DP_OFF;
break;
}
case 6 :
{
A_ON;
B_OFF;
C_ON;
D_ON;
E_ON;
F_ON;
G_ON;
DP_OFF;
break;
}
case 7 :
{
A_ON;
B_ON;
C_ON;
D_OFF;
E_OFF;
F_OFF;
G_OFF;
DP_OFF;
break;
}
case 8 :
{
A_ON;
B_ON;
C_ON;
D_ON;
E_ON;
F_ON;
G_ON;
DP_OFF;
break;
}
case 9 :
{
A_ON;
B_ON;
C_ON;
D_ON;
E_OFF;
F_ON;
G_ON;
DP_OFF;
break;
}
case '.' :
{
DP_ON;
break;
}
case 'C' :
{
A_ON;
B_ON;
C_ON;
D_ON;
E_OFF;
F_OFF;
G_OFF;
DP_ON;
break;
}
default: break;
}
}
|
Tidak ada komentar:
Posting Komentar