قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots

أدوات الموضوع

الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 23-08-2013, 11:25 PM المشاركة 1   
افتراضي مقياس درجة حرارة رقمى دقيق موجب وسالب بالحساس DS18B20 ولغة Basic والمترجم Proton : Twitter FaceBook Google+



مقياس درجة حرارة رقمى دقيق موجب وسالب بالحساس DS18B20 ولغة Basic والمترجم Proton :
يتم الاتصال بين الحساس والميكروكونترولر PIC عن طريق بروتوكول الاتصال بسلك واحد "One Wire" ، حيث يتم قياس (قراءة) درجة الحرارة بالدرجات المئوية فى المدى 0-127 degree C (بدقة (0.06250C ثم عرضها على شلشة LCD . الشكل التالى يبين المخطط العام للتوصيل .




الدائرة الكهربية :









البرنامج الأساسى :

كود:
; Proton-DS18B20-Thermometer-Basic-program
Device 16F628A Declare Xtal 4 All_Digital true ;LCD default connections
Output PORTB
Symbol DQ = PORTB.0 ; Name RB0 as DQ ( data) Dim Fraction As Word ;next part of the decimal point temperatures Dim TEMP As Word ;variable holding temperature Dim C As Byte ;general purpose variable
loop:
OWrite DQ,1,[$CC,$44] ;Sends the command for the calculation of temperature
Repeat DelayMS 25 ; Repeat until the transaction is expected to ORead DQ,4, [C] ; going through the process PORTB.0 = 0 Until C <> 0 ; complete transaction
OWrite DQ, 1, [$CC, $BE] ;sending the command to read the temperature value from RAM
ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor , TEMP = 16 bits , ;bit0 to bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign
Cls Print Bin TEMP
GoTo loop End

الخطوات الأساسية للبرمجة باستخدام الحساس DS18B20 :

اعلانات

الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 23-08-2013, 11:31 PM المشاركة 2   
افتراضي


الخطوات الأساسية للبرمجة باستخدام الحساس DS18B20 :
1- تخطى كود نوع الجهاز (الأمر $CC ) وإرسال أمر بداية تحويل درجة الحرارة (الأمر $44 ) وحفظ بيانات نتيجة التحويل فى سجل بحكم 2 بايت .

كود:
OWrite DQ,1,[$CC,$44] 'Sends the command for the calculation of temperature

2- استقبال (قراءة) بيانات نتيجة التحويل من الحساس والتأكد من إكتمال عملية النقل .

كود:
Repeat DelayMS 25 ' Repeat until the transaction is expected to ORead DQ,4, [C] ' going through the process PORTB.0 = 0 Until C <> 0 ' complete transaction
3- تخطى كود نوع الجهاز $CC وإرسال أمر التجهيز لقراءة قيمة درجة الحرارة (الأمر $BE) .

كود:
OWrite DQ, 1, [$CC, $BE] 'sending the command to read the temperature value from RAM
4- قراءة قيمة درجة الحرارة من الحساس فى شكل 2 بايت ، البايت الأدنى LowByte والبايت الأعلى HighByte.

كود:
ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor , TEMP = 16 bits , ;bit0 to bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign
5- مسح شاشة LCD وطباعة محتويات المتغير TEMP فى الشكل الثنائى :

كود:
Cls Print Bin TEMP
ملاحظات :
1- الشكل التالى يبين شكل محتويات سجل درجة الحرارة والذى يتم نسخه إلى السجل TEMP :

2- والجدول التالى يبين بعض النتائج :
3- الأربع بتات من bit0 إلى البت bit3 تمثل جزء الكسر العشرى كما هو مبين أعلاه ، والسبع بتات التى تليها من البت bit4 إلى البت bit10 تمثل قيمة درجة الحرارة المئوية ، باقى البتات والمشار إليها بالحرف S للدلالة على كون درجة الحرارة موجبة (S=0) أو سالبة (S=1) .
4- لتجنب استخدام الكسور العشرية يتم حساب الجزء الكسرى : من البت bit 3(2-1 ) إلى البت
bit 0(2-4) بالشكل التالى :

كود:
Fraction=5000*TEMP.3 + 2500*TEMP.2 + 1250*TEMP.1 +625*TEMP.0 'Calculating portion after the comma
5- للحصول على قيمة درجة الحرارة يتم إزاحة محتويات المتغير TEMP إربع خانات جهة اليمين للتخلص من بتات جزء الكسر ، سواء بالقسمة على "16" أو استخدام معامل الإزاحة ">>4" .
6- نتيجة درجة الحرارة السالبة تكون فى شكل يسمى المكمل للعدد ويجب تحويله إلى العدد الأصلة كما سوف يتضح من الأمثلة التالية :
مثال 1 : درجة حرارة موجبة ولا تحتوى على كسر :

كود:
For +85 ( bit 15 = 0 ) Temp =0000 0101 0101 0000 Shift 4 bits : Temp = Temp/16 = 0000 0000 0101 0101 Get the value : Temp = $0055 = 85 decimal

مثال 2 : درجة حرارة سالبة ولا تحتوى على كسر :

كود:
For -55 (bit 15 = 1) Temp = 1111 1100 1001 0000 Inverse : Temp = ~Temp = 0000 0011 0110 1111 Add 1 : TEMP = ~TEMP + 1 = 0000 0011 0111 1111 Shift 4 bits : Temp = Temp/16 = 0000 0011 0111 Get the value : TEMP value = TEMP.LowByte = 0011 0111= $37 = 55 decimal
مثال 3 : درجة حرارة موجبة تحتوى على كسر :

كود:
For +10.125 ( bit 15 =0 means positive ) : 00000000 10100010 a- Fraction bit0 to bit3 = 0010 = 1/2 * bit3 + 1/4 * bit2 + 1/8 * bit1 + 1/16 * bit0 = 1/8 = 0.125 b- Integer : 0000 1010 = $0A = 10 degree c- Total = +10.125 degree
مثال 4 : درجة حرارة سالبة تحتوى على كسر :


كود:
For -10.125 ( bit 15 =1 means negative ): 1111 1111 0101 1110 a- Inverse : 0000 0000 1010 0001 b- Add 1 : : 0000 0000 1010 0010 c- Fraction bit0 to bit3 = 0010 = 1/2 * bit3 + 1/4 * bit2 + 1/8 * bit1 + 1/16 * bit0 = 1/8 = 0.125 d- Integer : 0000 1010 = $0A = 10 degree e- Total = -10.125 degree



البرنامج الأول : مقياس درجة حرارة موجبة لا يحتوى على كسر

اعلانات اضافية ( قم بتسجيل الدخول لاخفائها )
  

الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 23-08-2013, 11:34 PM المشاركة 3   
افتراضي


البرنامج الأول : مقياس درجة حرارة موجبة لا يحتوى على كسر
الدائرة الكهربية :
البرنامج :


كود:
;1-Proton-DS18B20-Thermometer-positve-integer Device 16F628A Declare Xtal 4 All_Digital true ;LCD default connections Output PORTB Symbol DQ = PORTB.0 ; Name RB0 as DQ ( data) Dim TEMP As Word ;variable holding temperature Dim C As Byte ;general purpose variable Print $FE ,1 ; clear LCD loop: OWrite DQ,1,[$CC,$44] ;Sends the command for the calculation of temperature Repeat DelayMS 25 ; Repeat until the transaction is expected to ORead DQ,4, [C] ; going through the process PORTB.0 = 0 Until C <> 0 ; complete transaction OWrite DQ, 1, [$CC, $BE] ;sending the command to read the temperature value from RAM ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor ;TEMP = 16 bits , bit0 t0 bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign If TEMP.15=0 Then 'Positive temperature TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits Print $FE,$1 ; line 1 beginning Print "+" ; start with "+" Print Dec TEMP,".0"," ","C" ; then temp. value in format "xxx.0 C" EndIf If TEMP.15=1 Then 'the temperature is below zero,give warning Print $FE,1 Print "Negative TEMP" DelayMS 100 GoTo loop EndIf GoTo loop End
البرنامج الثانى : مقياس درجة حرارة موجبة وسالبة لا يحتوى على كسر


الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 23-08-2013, 11:37 PM المشاركة 4   
افتراضي


البرنامج الثانى : مقياس درجة حرارة موجبة وسالبة لا يحتوى على كسر
الدائرة الكهربية :

البرنامج :
كود:
;2-Proton-DS18B20-Thermometer-positve-Negative-integer Device 16F628A Declare Xtal 4 All_Digital true ;LCD default connections Output PORTB Symbol DQ = PORTB.0 ; Name RB0 as DQ ( data) Dim TEMP As Word ;variable holding temperature Dim C As Byte ;general purpose variable Print $FE ,1 ; clear LCD loop: OWrite DQ,1,[$CC,$44] ;Sends the command for the calculation of temperature Repeat DelayMS 25 ; Repeat until the transaction is expected to ORead DQ,4, [C] ; going through the process PORTB.0 = 0 Until C <> 0 ; complete transaction OWrite DQ, 1, [$CC, $BE] ;sending the command to read the temperature value from RAM ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor ;TEMP = 16 bits , bit0 t0 bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign If TEMP.15=0 Then 'positive temperature TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits Print $FE,$1 ; beginning of line 1 Print "+" ; start with "+" Print Dec TEMP,".0"," ","C" ; then temp. value in format "xxx.0 C" EndIf If TEMP.15=1 Then 'negative temperature TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits TEMP = ~TEMP + 1 Print $FE,$1 ; line 1 beginning Print "-" ; start with "-" Print Dec TEMP.LowByte,".0"," ","C" ; then temp. value in format "xxx.0 C" EndIf GoTo loop End
البرنامج الثالث : مقياس درجة حرارة موجبة وسالبة ويحتوى على كسر :


الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 23-08-2013, 11:40 PM المشاركة 5   
افتراضي


البرنامج الثالث : مقياس درجة حرارة موجبة وسالبة ويحتوى على كسر :
الدائرة الكهربية :








البرنامج :

كود:
;3-Proton-DS18B20-Thermometer-positve-Negative-fraction Device 16F628A Declare Xtal 4 All_Digital true ;LCD default connections Output PORTB Symbol DQ = PORTB.0 ; Name RB0 as DQ ( data) Dim Fraction As Word ;next part of the decimal point temperatures Dim TEMP As Word ;variable holding temperature Dim C As Byte ;general purpose variable Print $FE ,1 ; clear loop: OWrite DQ,1,[$CC,$44] ;Sends the command for the calculation of temperature Repeat DelayMS 25 ; Repeat until the transaction is expected to ORead DQ,4, [C] ; going through the process PORTB.0 = 0 Until C <> 0 ; complete transaction OWrite DQ, 1, [$CC, $BE] ;sending the command to read the temperature value from RAM ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor ;TEMP = 16 bits , bit0 t0 bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign If TEMP.15=0 Then 'positive temperature Fraction=50*TEMP.3 + 25*TEMP.2 'Calculating portion after the comma TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits Print $FE,$1 ; line 1 beginning Print "+" ; start with "+" ; then temp. value in format "xxx.00 C" Print Dec TEMP,".",Dec2 Fraction," ","C" EndIf If TEMP.15=1 Then 'negative temperature TEMP = ~TEMP + 1 Fraction=50*TEMP.3 + 25*TEMP.2 'Calculating portion after the comma TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits Print $FE,$1 ; line 1 beginning Print "-" ; start with "-" ; then temp. value in format "xxx.00 C" Print Dec TEMP.LowByte,".",Dec2 Fraction," ","C" EndIf


الصورة الرمزية F.Abdelaziz
F.Abdelaziz
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
نشاط [ F.Abdelaziz ]
قوة السمعة:332
قديم 24-08-2013, 12:26 AM المشاركة 6   
افتراضي


البرنامج رقم 4 : استخدام الحساس DS18B20 مع السفن سيجمنت :

الدائرة الكهربية :













البرنامج :

كود:
;Proton-DS18B20-Thermometer-positve-integer-7-Segment
Device 16F628A Declare Xtal 4 All_Digital true
Dim TEMP As Word ; Dim ONES As Word ;DIGIT 0 for ONES 0 to 9 Dim TENS As Word ;DIGIT 1 for TENS 0 to 9 Dim HUNDREDS As Word ;DIGIT 2 for HUNDREDS 0 to 9 Dim C As Byte ;general purpose variable
Symbol Enable_ONES = PORTB.6 Symbol Enable_TENS = PORTB.5 Symbol Enable_HUNDREDS = PORTB.4 Symbol DQ = PORTA.0 ; Name RB0 as DQ ( data)
Output PORTB PORTB = 0 ;Clear PORTB
loop:
OWrite DQ,1,[$CC,$44] ;Sends the command for the calculation of temperature
Repeat DelayMS 25 ; Repeat until the transaction is expected to ORead DQ,4, [C] ; going through the process PORTB.0 = 0 Until C <> 0 ; complete transaction
OWrite DQ, 1, [$CC, $BE] ;sending the command to read the temperature value from RAM
ORead DQ,2,[TEMP.LowByte,TEMP.HighByte] ;temperature value read from the sensor ;TEMP = 16 bits , bit0 t0 bit3 for fraction ,bit4 t0 bit10 for integer , bit11 to bit15 for sign
If TEMP.15=0 Then 'Positive temperature TEMP = TEMP/16 ;Or TEMP = TEMP>>4 to remove fraction bits
Display: ;TEMP consists of ONES=TEMP Dig 0 TENS=TEMP Dig 1 HUNDREDS = TEMP Dig 2
PORTB=240 | ONES ; Sens ONES data ; Note : 240 = %11110000 , (|) OR to use bit0 to bit3 for 7 segment ;and make bit4 to bit7 high for enable function
;Enable (LE) 4511 ONES digit by low pulse Low Enable_ONES : DelayMS 1 : High Enable_ONES : DelayMS 1
PORTB=240 | TENS ; Send TENS data
;Enable (LE) 4511 TENS digit by low pulse Low Enable_TENS : DelayMS 1 : High Enable_TENS : DelayMS 1
PORTB=240 | HUNDREDS ; Send HUNDREDS data
;Enable (LE) 4511 HUNDREDS digit by low pulse Low Enable_HUNDREDS : DelayMS 1 : High Enable_HUNDREDS : DelayMS 1
EndIf
If TEMP.15=1 Then 'the temperature is below zero,give warning PORTB = 0 ; EndIf
GoTo loop End

إضافة رد

العلامات المرجعية

«     الموضوع السابق       الموضوع التالي    »
أدوات الموضوع

الانتقال السريع إلى


الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 09:37 PM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)

Powered by vBulletin® Version 3.8.6, Copyright ©2000 - 2025