So yesterday I wanted to get some temperature measurements from a DS18S20 thermometer to my PIC prototyping board. This thermometer uses the 1-Wire communication protocol so I searched around to find a 1-Wire library for the C18 compiler I am using. Maybe I am wrong but I couldn’t find any. So I created one, hence this post.
I had a post about the 1-Wire protocol a while back so you can read that if you are not familiar with it. To implement this protocol we need to work with precision timing. Ideally this could be written in asm. However, for convenience reasons I wrote this in C. I don’t really mind the minor performance penalty
Just to be clear, this is a library for the 1-Wire protocol, not for any of the supported devices. The library contains 3 main functions:
- 1-Wire Reset
- 1-Wire Write
- 1-Wire Read
Using these three operations we can have full communication with any 1-Wire device. Let me demonstrate first and then I will write about how you can use it in your project.
A brief demonstration
To demonstrate this operation, I connected a DS18S20 thermometer and connected the DQ line on my PIC’s Port C Pin 1. The procedure I will follow is:
- Issue a Reset pulse and observe the Presence of the thermometer
- Issue the Skip Rom command (0xCC)
- Issue the Convert T command (0×44)
- Wait for 1+ second
- Issue a Reset pulse and observe the Presence of the thermometer
- Issue the Skip Rom command (0xCC)
- Issue the Read Scratchpad command (0xBE)
- And read the next two bytes which represent the temperature
Lets see the C code I loaded on my board Continue Reading
Incoming search terms:
- pic onewire library (6)
- c18 ds1820 (5)
- 1-wire c18 (5)
- OW_write_byte (5)
- onewire c18 (5)
- c18 libraries (5)
- ds1820 pic 1 wire c18 (4)
- onewire c (3)
- pic ds18s20 prototype (2)
- pic DS18S20 (2)