Discussion in "PIC Microcontroller Discussion" started by    abdul991    Apr 25, 2013.
Thu Apr 25 2013, 03: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, 03: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, 12:14 AM
Thanks for sharing.. your post is now tagged.
Sun May 05 2013, 08:21 AM
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, 05: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, 11:19 AM
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, 03:58 AM ]
Wed May 08 2013, 12: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, 03: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, 03: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, 12:32 AM
ah! relaxed!! so what was the issue?? and how did you solve it.

Get Social


Powered by e107 Forum System


Wed May 20 2020, 03:59 AM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sun May 03 2020, 01:08 AM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 07:09 PM
Sir kindly send the code file i2c for 8051
Sat Mar 14 2020, 04:06 AM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 06:25 PM
how can get hadwere of this project
Sat Mar 07 2020, 09:41 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 09:28 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 02:42 PM
Pearl Olin
Wed Jan 22 2020, 10: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.
Tue Jan 14 2020, 11:38 AM
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



Thu May 21 2020, 08:44 AM
Wed May 20 2020, 09:28 PM
Wed May 20 2020, 03:05 PM
Wed May 20 2020, 07:52 AM
Wed May 20 2020, 03:15 AM
Tue May 19 2020, 06:08 PM
Tue May 19 2020, 02:22 PM
Mon May 18 2020, 09:50 PM


Guests: 29, Members: 0 ...

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

Members: 38211
Newest member: Davidthils
Forum Activity
xrxx Avatar
Posted By xrxx
Thu Apr 30 2020, 06:59 AM
BCD MULTIPLICATIONAssume that you have to 2 BCD nu...
liqian Avatar
Posted By liqian
Tue Apr 28 2020, 05:26 AM
I happened to see your post and I got many useful ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Apr 28 2020, 04:21 AM
The code is hard to read.Please zip it and attach ...
rogermado Avatar
Posted By rogermado
Sun Apr 26 2020, 01:53 AM
@ExperimenterUK, thanks for your reply. You'll fin...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Apr 25 2020, 05:42 PM
Some simulators handle displays better than others...
rogermado Avatar
Posted By rogermado
Sat Apr 25 2020, 03:59 PM
Hello everyone, sorry in advance if i'm not in the...
PHANTOM28 Avatar
Posted By PHANTOM28
Fri Feb 28 2020, 10:25 AM
Hi.I hope you all can help me. I am relatively ne...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 21 2020, 05:05 PM
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Feb 21 2020, 04:45 AM
Yes you can do that.1. Create a channel @Thingspea...
ananyagupta Avatar
Posted By ananyagupta
Thu Feb 20 2020, 03:58 AM
With regards to the particular characters sent to ...