Discussion in "PIC Microcontroller Discussion" started by    abdul991    Apr 25, 2013.
Thu Apr 25 2013, 07:11 AM
Hi, guys... I've upgraded my project from AT89S52 TO PIC ...

Lately i have implemented 2ds1820- using two Microcontroller pins - Read ROM command. i've attached the code....

Thu Apr 25 2013, 07:15 AM
And then using the received addresses i've implemented the Match Rom Command for a single IC and then implemented ConvTemp Command and ReadScratchPad Command using 1-wire, 2ds1820 IC. Here is the code attached.. I'm using MPLAB -PIC kit2 and xtal 12MHz....
 ajay_bhargav like this.
Tags DS1820 interfacingDS1820 with PIC microcontroller1 wire protocol1 wire pic microcontrollerDS1820 digital thermometer pic microcontroller
Fri Apr 26 2013, 04:14 AM
Thanks for sharing.. your post is now tagged.
Sun May 05 2013, 12:21 PM
I;m trying for searchRom command for 2 DS1820 1-Wire IC. i took the code from


Customized it with my 12MHz xtal and Hyperterminal
But i am getting partial o/p.
i.e the two rom addresses with other values repeating every 240 bytes ...
I've attached the code as well as the o/p snapshot....
Mon May 06 2013, 09:44 AM

i.e the two rom addresses with other values repeating every 240 bytes ...


Can you explain with example, coz nothing is understandable from screenshot you've posted.
Mon May 06 2013, 03:19 PM
in the snapshot the highlighted part is the actual ROM address i require.. But the display is continuous which i don't understand.. i altered the code a little bit and got the o/p as attached below.

Explaination for the search Rom :

See the concept is Search Rom command gives 64 bits of ds1820 rom address for each ds1820 IC connected on the 1 wire.

This 64bit is permanently stored in FndROM[3][8].

The procedure is as follows
1. Reset is done in Finddevices() and it calls to initialize in First().
2. First() initializes lastDiscrep = 0; doneFlag = FALSE; // will explain later
3. First() calls next().
4. Next() initializes few more variables // explained below.
5. mask bit k=1 used for storing the read bit in Rom[n] while securing other bits of that byte from getting altered.
6. m=1 is the bit counter. So total 65 bits has to be counted.
7. n=0 is the byte counter. Total 0-7 bytes. do-while() of the Next() exits if n>7, indicating that one DS1820IC has been detected.
8. O/p write bit is g. What g holds is written back to the 1-Wire, so that , the particular DS1820 IC's are 'alive' on 1-wire for the remaining bits to be read.
9. the nxt is used to return true/false value to the FindDevice(), if false is returned the search is ended/closed.
10. Every time the Next() is called – if there are DS-ic’s on 1-wire then 8-bytes are put in the ROM[] and then stored into the FndROM[][] inside the FindDevice().

11. So, when PIC sends F0 command, each 1-Wire™ device will returns the bit, and its compliment bit. That is for each 64 bits , two bits are read by PIC .
PIC reads each of these two bits as the 'And' result of the bit- each DS1820 puts on 1-wire.

12. if PIC reads 11 then no devices are present and Next() returns false.
13. if 01 is read, by PIC, all the DS1820 devices have 0 at that bit position.
14. if 10 is read, all the 1-wire devices have 1 at that read bit position.
15. if 00 is read, some DS1820 device have 0 and some have 1 at that bit position.

16. this 00 condition is the discrepancy condition, used to identify and narrow down the 1-wire devices.
17. from here it gets little tricky.
18. In this case(when 00 is read) if 0 is written back in g then those 1-wire devices which had ‘0’ in the bit position will remain alive in search loop inside the do-while in Next().
19. Value of x is also tricky but easy. You need to figure is out yourself.
20. Then for 00- case initially 0 is written back by PIC and descepMarker stores the latest bit position at which '00' case existed.
21. when Next() is called again, if 00 case occurs ,if descrepMarker == bitposition then ‘1’ is written back into g on the 1-wire. so that the DS1820 ic having '1' at this bit position is/are selected and remain alive.
22. Rest of the code is to be understood alone.
23. I've below posted the part when case '00' occurs (2nd else)

else    // 1st else
// when this condition will never occur x=0.
0) // 01 or 10  condition
g = x>
1; // bit write value for search

else   // 2nd else  00 condition
// if this discrepancy is before the last
// discrepancy on a previous Next then pick
// the same as last time
g = ((ROM[n]&k)>
else // if equal to last pick 1
g = (m==lastDiscrep); // if not then pick 0
// if 0 was picked then record
// position with mask k
if (g==0)  discrepMarker = m;

}   // 2nd else is closed 

if(g==1) // isolate bit in ROM[n] with mask k
ROM[n] |= k;
ROM[n] &= ~k;
write_bit(g); // ROM search write
m++; // increment bit counter m
k = k<<1; // and shift the bit mask k
if(k==0) // if the mask is 0 then go to new ROM

n++;    k++;

}  // 1st else closed
}while(n<8); //loop until through all ROM bytes 0-7

[ Edited Thu May 09 2013, 07:58 AM ]
Wed May 08 2013, 04:20 AM
Trust me abdul, you've written quite a logic there. It becomes more and more complex as I keep on reading. And it needs time for me to understand I am always in hurry when answering posts right now I do not have any answer for your problem. But I might answer later.
Thu May 09 2013, 07:17 AM
k. no problem. its has complex logic.. i know for sure... i will clarify if any doubt is there in the code as best i can... But entire code cannot be explained...
Fri May 10 2013, 07:17 AM


 ajay_bhargav like this.
Tags DS1820 interfacingDS1820 with PIC microcontroller1 wire protocol1 wire pic microcontrollerDS1820 digital thermometer pic microcontroller
Mon May 13 2013, 04:32 AM
ah! relaxed!! so what was the issue?? and how did you solve it.

Get Social


Powered by e107 Forum System


Wed Jan 22 2020, 11:46 PM
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Wed Jan 22 2020, 04:49 PM
casino online online casino real money casino games big fish casino play casino
Tue Jan 14 2020, 12:38 PM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 07:14 PM
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 04:00 PM
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 06:00 PM
how to interface 8051 microcontroller with NRF24L01+ module
Sun Oct 13 2019, 03:53 AM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 03:48 PM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 01:07 PM
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Thu Sep 19 2019, 02:18 AM
Caryn Kover
Thank you for your time,



Sun Jan 19 2020, 02:13 AM
Sat Jan 11 2020, 10:42 AM
Tue Jan 07 2020, 06:53 PM
Tue Jan 07 2020, 12:42 PM
Sun Dec 29 2019, 05:54 AM
Fri Dec 27 2019, 06:14 PM
Sat Dec 14 2019, 12:31 PM
Thu Dec 12 2019, 12:04 PM


Guests: 46, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38116
Newest member: Nippy56
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 17 2020, 10:24 PM
We will need the circuit diagram.A Proteus simulat...
Billz Avatar
Posted By Billz
Sat Jan 11 2020, 05:43 PM
hi everyone please attached files are my c code fo...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jan 07 2020, 08:18 PM
Not a stupid question.Setting up "Eclipse" can be...
elt Avatar
Posted By elt
Tue Jan 07 2020, 07:06 PM
So i have just began learning programming micros a...
Billz Avatar
Posted By Billz
Mon Jan 06 2020, 09:22 PM
I think it would be better if you guys try to come...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jan 06 2020, 12:22 AM
Can you post a circuit diagram and any code you ha...
Billz Avatar
Posted By Billz
Sun Jan 05 2020, 08:17 PM
Need help regarding C code (specifically for PIC 1...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Dec 30 2019, 06:42 PM
Can you give more details of your problem.
Rupeshpatil Avatar
Posted By Rupeshpatil
Fri Dec 27 2019, 06:21 PM
How to copy program my old microcontroller to new ...
ilylily07 Avatar
Posted By ilylily07
Thu Dec 12 2019, 02:26 PM
wil do.thank you for your advice!