ساخت ترمومتر و ترموستات
در این بخش تیم الکترونیک و برنامه نویسی الکترونیک ۹۸, اقدام به طراحی و انتشار پروژه ای کاربردی و حرفه ای با عنوان, ساخت ترمومتر و ترموستات بسیار پیشرفته با تراشه DS18B20, برای شما علاقه مندان به پروژه های میکروکنترلر AVR کرده است. همانطور که می دانید سنسورهای بسیار زیادی برای اندازه گیری دما و ساخت دماسنج در بازار موجود می باشد که هر کدام دارای محدوده اندازه گیری و پروتکل ارتباطی خاصی می باشند، به همین دلیل تا کنون پروژه های بسیار زیادی با موضوع اندازه گیری و کنترل دمای محیط در سایت الکترونیک 98 منتشر کرده ایم، که هدف اصلی از انتشار این پروژه ها آشنایی شما دوستان عزیز با راه اندازی انواع حسگرهای دما با میکروکنترلرهای AVR می باشد.
نقشه شماتیک پروژه
سنسور دما DS18B20
در پروژه قبلی (اندازه گیری همزمان دمای چهار نقطه با سنسور DS18B20) شما را با نحوه راه اندازی سنسور دمای DS18B20 با میکروکنترلرهای AVR و شیوه اندازه گیری دما با سنسور مذکور آشنا کردیم. حال می خواهیم پروژه قبلی را گسترش دهیم و با استفاده از سنسور دمای DS18B20 یک دستگاه اندازه گیری و کنترل دما (ترمومتر و ترموستات) طراحی کنیم. در این پروژه ابتدا دما با استفاده از سنسور دمای DS18B20 اندازه گیری می شود و سپس مقدار دما توسط میکروکنترلر ATmega8 بر روی یک ال سی دی کاراکتری در ابعاد 2*16 نمایش داده می شود. در صورتی که دمای اندازه گیری شده در محدود رنج دمایی از قبل تنظیم شده باشد، رله خروجی دستگاه فعال می شود.
برنامه میکروکنترلر به زبان بیسیک BASIC در نرم افزار BASCOM-AVR
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
$regfile = "m8def.dat" $crystal = 4000000 '-------------------------------------------- $hwstack = 80 $swstack = 80 $framesize = 80 '-------------------------------------------- Declare Sub Mk_init() Declare Sub Selectmode() Declare Sub Thermo_lcd(thermo As Integer) Declare Sub Thermocontrol(thermo As Integer , Thermosetting As Integer) Declare Sub Modify_setting_button() Declare Sub Modify_setting_lcd(thermo As Integer) Declare Function Read_thermo(thermo As Byte) As Byte '-------------------------------------------- 1wire_pin Alias Portd.0 Button_plus Alias Pind.1 Button_minus Alias Pind.2 Led_read_1wire Alias Portc.0 Out_thermostat Alias Portc.1 Sreaker Alias Portc.2 '-------------------------------------------- Const Button_delay = 24 Const Button_force_delay = 200 Const Thermostat_type = 0 Const Error_sound_state = 1 Const Button_force_time = 2 Const Thermo_mode_save_time = 8 Const Button_beep_state = 1 Const Button_mode_time = 4 '-------------------------------------------- Dim Flaginputtermo As Byte Dim Thermo_mode_state As Byte Dim Button_plus_state As Byte Dim Button_minus_state As Byte Dim Button_force_counter As Byte Dim Temp_1wirearray(9) As Byte Dim 1wire_array(9) As Byte Dim Error_thermo_counter As Byte Dim Thermo_mode As Byte Dim Thermo_mode_counter As Byte Dim Thermo_mode_save_counter As Byte Dim Currenttermo As Integer At 1wire_array Overlay Dim Thermo_setting As Integer Dim Modify_thermo_setting As Integer Dim Ee_thermosetting As Eram Integer '-------------------------------------------- Config Lcd = 16 * 2 Config Lcdbus = 4 Config Lcdmode = Port Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , Rs = Portb.4 , E = Portb.5 Config 1wire = 1wire_pin Config Led_read_1wire = Output Config Out_thermostat = Output Config Sreaker = Output Config Button_plus = Input Config Button_minus = Input Config Timer1 = Timer , Prescale = 64 On Timer1 Timer1_interrupts Stop Timer1 '-------------------------------------------- Config Watchdog = 2048 '-------------------------------------------- Call Mk_init() Enable Interrupts '-------------------------------------------- Do Reset Watchdog If Flaginputtermo = 1 Then Flaginputtermo = 0 If Read_thermo(1wire_array(1)) = 1 Then If Thermo_mode = 0 Then Call Thermo_lcd(currenttermo) End If Call Thermocontrol(currenttermo , Thermo_setting) Error_thermo_counter = 0 Else If Error_thermo_counter >= 2 Then #if Error_sound_state = 1 Sound Sreaker , 2000 , 80 Sreaker = 0 #endif Sreaker = 0 Error_thermo_counter = 0 Cls : Lcd "Sensor error!" Thermo_mode = 0 Else Incr Error_thermo_counter End If End If End If Call Selectmode() If Thermo_mode = 2 Then Call Modify_setting_button() End If Loop End '-------------------------------------------- Timer1_interrupts: Flaginputtermo = 1 If Thermo_mode = 0 And Thermo_mode_state = 1 Then If Thermo_mode_counter < 200 Then Incr Thermo_mode_counter Elseif Thermo_mode = 2 Then If Thermo_mode_save_counter < 200 Then Incr Thermo_mode_save_counter If Button_force_counter < 200 Then Incr Button_force_counter End If Return '-------------------------------------------- Sub Mk_init() Out_thermostat = 0 Sreaker = 0 Error_thermo_counter = 0 Thermo_mode = 0 Thermo_mode_state = 0 Thermo_mode_counter = 0 Thermo_mode_save_counter = 0 Thermo_setting = Ee_thermosetting '-------------------------------------------- Cursor Off Deflcdchar 1 , 228 , 234 , 228 , 224 , 224 , 224 , 224 , 224 Cls Lcd " electronics 98 " Lowerline Lcd "Thermometer..." '-------------------------------------------- If Thermo_setting < -880 Or Thermo_setting > 2000 Then #if Error_sound_state = 1 Sound Sreaker , 2000 , 80 Sreaker = 0 #endif Cls Lcd "Error EEPROM" Thermo_setting = 0 Ee_thermosetting = Thermo_setting End If '-------------------------------------------- 1wreset 1wwrite &HCC 1wwrite &H44 Wait 2 Shiftlcd Left Wait 1 Timer1 = 0 Flaginputtermo = 0 Enable Timer1 Start Timer1 Start Watchdog End Sub '-------------------------------------------- Sub Selectmode() If Thermo_mode = 0 Then If Button_minus = 0 Then '-------------------------------------------- #if Button_beep_state = 1 If Button_minus_state = 0 Then Waitms Button_delay If Button_minus = 0 Then Button_minus_state = 1 Sound Sreaker , 80 , 400 Sreaker = 0 Else Button_minus_state = 0 End If End If #endif '-------------------------------------------- If Thermo_mode_state = 0 Then Thermo_mode_counter = 0 Thermo_mode_state = 1 Else If Thermo_mode_counter >= Button_mode_time Then Thermo_mode = 1 End If Else Thermo_mode_counter = 0 Thermo_mode_state = 0 Button_minus_state = 0 End If Else '-------------------------------------------- If Thermo_mode_state = 1 Then Thermo_mode_counter = 0 Thermo_mode_state = 0 Cls Lcd Spc(4) ; "Setting" End If '-------------------------------------------- If Thermo_mode = 1 Then If Button_minus = 1 Then Waitms Button_delay If Button_minus = 1 Then Thermo_mode = 2 Modify_thermo_setting = Thermo_setting Thermo_mode_save_counter = 0 Button_plus_state = 0 Button_minus_state = 0 Call Modify_setting_lcd(modify_thermo_setting) End If End If Elseif Thermo_mode > 2 Then Thermo_mode = 0 Thermo_mode_counter = 0 Thermo_mode_state = 0 Button_plus_state = 0 Button_minus_state = 0 End If End If End Sub '-------------------------------------------- Sub Modify_setting_button() Local Temp_shift As Byte Local Temp_1 As Byte '-------------------------------------------- If Button_plus = 0 And Button_minus = 1 Then Waitms Button_delay If Button_plus = 0 Then Thermo_mode_save_counter = 0 If Button_force_counter >= Button_force_time Then If Modify_thermo_setting < 1980 Then Modify_thermo_setting = Modify_thermo_setting + 16 Call Modify_setting_lcd(modify_thermo_setting) Waitms Button_force_delay End If Else If Button_plus_state = 0 Then Button_plus_state = 1 #if Button_beep_state = 1 Sound Sreaker , 80 , 400 Sreaker = 0 #endif If Modify_thermo_setting < 2000 Then Temp_shift = Modify_thermo_setting And 15 Temp_1 = Lookup(temp_shift , Button_modify_label) Modify_thermo_setting = Modify_thermo_setting + Temp_1 Call Modify_setting_lcd(modify_thermo_setting) End If End If End If '-------------------------------------------- Else Button_plus_state = 0 End If '-------------------------------------------- Elseif Button_minus = 0 And Button_plus = 1 Then Waitms Button_delay If Button_minus = 0 Then Thermo_mode_save_counter = 0 If Button_force_counter >= Button_force_time Then If Modify_thermo_setting > -860 Then Modify_thermo_setting = Modify_thermo_setting - 16 Call Modify_setting_lcd(modify_thermo_setting) Waitms Button_force_delay End If Else If Button_minus_state = 0 Then Button_minus_state = 1 #if Button_beep_state = 1 Sound Sreaker , 80 , 400 Sreaker = 0 #endif If Modify_thermo_setting > -880 Then Temp_shift = Modify_thermo_setting And 15 Temp_1 = Lookup(temp_shift , Button_modify_label) Modify_thermo_setting = Modify_thermo_setting - Temp_1 Call Modify_setting_lcd(modify_thermo_setting) End If End If End If Else Button_minus_state = 0 End If Else Button_plus_state = 0 Button_minus_state = 0 Button_force_counter = 0 End If '-------------------------------------------- If Thermo_mode_save_counter >= Thermo_mode_save_time Then If Modify_thermo_setting <> Thermo_setting Then Ee_thermosetting = Modify_thermo_setting Thermo_setting = Modify_thermo_setting End If Thermo_mode_save_counter = 0 Thermo_mode = 0 Thermo_mode_counter = 0 Thermo_mode_state = 0 Button_plus_state = 0 Button_minus_state = 0 End If End Sub '-------------------------------------------- Sub Modify_setting_lcd(thermo As Integer) Local Lcd_out As Single Lcd_out = Thermo / 16 Cls Lcd Spc(4) ; "Setting" Lowerline Lcd "set t" ; Chr(1) ; ": " ; Fusing(lcd_out , "#.#") ; Chr(1) ; "C" End Sub '-------------------------------------------- Sub Thermo_lcd(thermo As Integer) Local Lcd_out As Single Cls Lcd_out = Thermo / 16 Lcd "Thermo: " ; Fusing(lcd_out , "#.#") ; Chr(1) ; "C" If Button_plus = 0 Then Waitms Button_delay If Button_plus = 0 Then Lcd_out = Thermo_setting / 16 Lowerline Lcd "set t" ; Chr(1) ; ": " ; Fusing(lcd_out , "#.#") ; Chr(1) ; "C" #if Button_beep_state = 1 If Button_plus_state = 0 Then Button_plus_state = 1 Sound Sreaker , 80 , 400 Sreaker = 0 End If #endif Else Button_plus_state = 0 End If Else Button_plus_state = 0 End If End Sub '-------------------------------------------- Sub Thermocontrol(thermo As Integer , Thermosetting As Integer) If Thermo <= Thermosetting Then #if Thermostat_type = 0 Out_thermostat = 1 #else Out_thermostat = 0 #endif Else #if Thermostat_type = 0 Out_thermostat = 0 #else Out_thermostat = 1 #endif End If End Sub '-------------------------------------------- Function Read_thermo(thermo As Byte) As Byte Local Temp As Byte Temp = 0 Disable Interrupts Led_read_1wire = 1 1wreset If Err = 0 Then 1wwrite &HCC 1wwrite &HBE Temp_1wirearray(1) = 1wread(9) 1wreset 1wwrite &HCC 1wwrite &H44 If Temp_1wirearray(9) = Crc8(temp_1wirearray(1) , 8) Then For Temp = 1 To 8 Thermo(temp) = Temp_1wirearray(temp) Next Temp Temp = 1 Led_read_1wire = 0 End If End If Enable Interrupts Read_thermo = Temp End Function '-------------------------------------------- Button_modify_label: Data 2 , 1 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1 , 1 |
همچنین فایل شبیه ساز این پروژه نیز که با نرم افزار Proteus 8 Professional طراحی شده، پیوست فایل پروژه جهت دانلود قرار داده شده است، که می تواند شما را در یادگیری هر چه بهتر مدار و نحوه عملکرد آن یاری نماید.
سلام
الان کیت این ترموستات رو موجود دارید ؟
سلام دوست عزیز
متاسفانه در حال حاضر این محصول به صورت کیت در فروشگاه موجود نمی باشد.
سلام کیت آماده این محصول موجود است؟
سلام دوست عزیز
خیر، متاسفانه کیت این محصول جهت ارائه موجود نیست.