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

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

medo30975
:: مهندس ::
تاريخ التسجيل: May 2009
المشاركات: 2
نشاط [ medo30975 ]
قوة السمعة:0
قديم 23-09-2013, 11:48 AM المشاركة 1   
ha مشكلة بقراءة حساس DS18B20 Twitter FaceBook Google+



قمت بأستخدام حساس الحرارة يسds18b20 وعرض الناتج على 4digit 7segment ولكن لا تظهر اى قرأءة برجاء من اى السادة الاعضاء محاولة قراءة الكود ويعطينى رأية عن الخطأ

الادوات المستخدمة :-
pic 16f877a
7seg common anode
ds18b20
mikroc pro for pic v6

************************************************** ***********
/*
'************************************************* ******************************
' Lesson nr.14:
' Digital thermometer with DS18B20 and 7- Segments.
' Done by:
' Aureliu Raducu Macovei, 2010.
' Description:
' In this experiment we will work with one-wire communication.
' The thermal sensor used is "DS18B20" and measured value is displayed
' on the 7-segment digits. PORTB will be used for character
' (RB0=a,RB1=b...RB6=g,RB7=dp)and for digits RA0=digit1...RA3=digit4.
' Data wire from DS18B20 is conected to RA4.
' Test configuration:
' MCU: PIC16F628A
' Test.Board: WB-106 Breadboard 2420 dots
' SW: MikroC PRO for PIC 2010 (version v4.15)
' Configuration Word
' Oscillator: INTOSC:I/O on RA.6, I/O on RA.7
' Watchdog Timer: OFF
' Power up Timer: Disabled
' Master Clear Enable: Enabled
' Browun Out Detect: Enabled
' Low Voltage Program: Disabled
' Data EE Read Protect: Disabled
' Code Protect: OFF
'************************************************* ******************************
*/
unsigned short i, DD0=0xBF, DD1=0xBF,DD2=0xBF, DD3 =0xC6, N_Flag;
unsigned temp_value=0; // Variable to store temperature register value
unsigned short mask(unsigned short num) // Mask for 7 segment common cathode;
{
switch (num)
{
case 0 : return 0xC0; // 0;
case 1 : return 0xF9; // 1;
case 2 : return 0xA4; // 2;
case 3 : return 0xB0; // 3;
case 4 : return 0x99; // 4;
case 5 : return 0x92; // 5;
case 6 : return 0x82; // 6;
case 7 : return 0xF8; // 7;
case 8 : return 0x80; // 8;
case 9 : return 0x90; // 9;
case 10 : return 0xBF; // Symbol '-'
case 11 : return 0xC6; // Symbol C
case 12 : return 0xFF; // Blank
} //case end
}

void display_temp(short DD0, short DD1, short DD2, short DD3)
{
for (i = 0; i<=4; i++)
{
PORTC = DD3;
RA0_bit = 1; // Select C Digit;
RA1_bit = 0;
RA2_bit = 0;
RA3_bit = 0;
delay_ms(700);
PORTC = DD0;
RA0_bit = 0;
RA1_bit = 1; // Select Ones Digit;
RA2_bit = 0;
RA3_bit = 0;
delay_ms(700);
PORTC = DD1;
RA0_bit = 0;
RA1_bit = 0;
RA2_bit = 1; // Select Tens Digit;
RA3_bit = 0;
delay_ms(700);
PORTC = DD2;
RA0_bit = 0;
RA1_bit = 0;
RA2_bit = 0 ;
RA3_bit = 1; // Select +/- Digit;
delay_ms(700);
}return;
}

void DS18B20() //Perform temperature reading
{
Display_temp(DD0, DD1, DD2, DD3);
Ow_Reset(&PORTA, 4); // Onewire reset signal
Ow_Write(&PORTA, 4, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 4, 0x44); // Issue command CONVERT_T
Display_temp(DD0, DD1, DD2, DD3);
Ow_Reset(&PORTA, 4);
Ow_Write(&PORTA, 4, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 4, 0xBE); // Issue command READ_SCRATCHPAD
Display_temp(DD0, DD1, DD2, DD3);
// Next Read Temperature
temp_value = Ow_Read(&PORTA, 4); // Read Byte 0 from Scratchpad
temp_value = (Ow_Read(&PORTA, 4) << 8) + temp_value; // Then read Byte 1 from
// Scratchpad and shift
// 8 bit left and add the Byte 0
if (temp_value & 0x8000) {
temp_value = ~temp_value + 1;
N_Flag = 1; // Temp is -ive
}
if (temp_value & 0x0001) temp_value += 1; // 0.5 round to 1
temp_value = temp_value >> 4 ; //<<< // 1 for DS1820 and
// 4 for DS18B20;
}

void main()
{
CMCON |= 7; // Disable Comparators
TRISC = 0; // Set PORTB direction to be output
PORTC = 0; // Turn OFF LEDs on PORTB
PORTA = 0;
TRISA0_bit = 0; // RA.0 to RA3 Output
TRISA1_bit = 0;
TRISA2_bit = 0;
TRISA3_bit = 0;

do { //--- main loop
N_Flag = 0; // Reset Temp Flag
DS18B20();
DD0 = temp_value%10; // Extract Ones Digit
DD0 = mask(DD0);
DD1 = (temp_value/10)%10; // Extract Tens Digit
DD1 = mask(DD1);
DD2 = temp_value/100; // Extract Hundred digit
if (N_Flag == 1) DD2=0x0A; // DD2 10 ??
else if (DD2 == 0) DD2 = 0x0D; // DD2 13 ??
DD2 = mask(DD2);
display_temp(DD0, DD1, DD2, DD3); // Infinite loop;
} while (1);
}

اعلانات
إضافة رد

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

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

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


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

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