TOP Contributors

  1. MIKROE (2784 codes)
  2. Alcides Ramos (405 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (133 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (141964 times)
  2. FAT32 Library (75152 times)
  3. Network Ethernet Library (59421 times)
  4. USB Device Library (49414 times)
  5. Network WiFi Library (45228 times)
  6. FT800 Library (44818 times)
  7. GSM click (31388 times)
  8. mikroSDK (30370 times)
  9. microSD click (27741 times)
  10. PID Library (27595 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

DS18X20 One Wire Library

Rating:

5

Author: Richard Lowe

Last Updated: 2013-09-19

Package Version: 1.0.0.3

Category: Measurement

Downloaded: 3653 times

Followed by: 1 user

License: MIT license  

Easily add DS18x20 sensor functions to your project.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "DS18X20 One Wire Library" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "DS18X20 One Wire Library" changes.

Do you want to report abuse regarding "DS18X20 One Wire Library".

  • Information
  • Comments (0)

Library Blog


This is the first version.  This library assumes that it is the only sensor on the bus.  Sensor addressing is not yet supported.


Requirements: stdbool ( boolean definition file ) found on libstock


To use this library, you will need to edit the header file and define your port and pin.

Example:
//#define DS18X20_BASE_ADDRESS    &PORTA
//#define DS18X20_PIN             3
#define DS18X20_BASE_ADDRESS    &GPIOA_BASE
#define DS18X20_PIN             3

The example file included shows 2 different methods the library supports, polled and immediate.

Temp sensors are SLOW.  On a 8Mhz AVR with resolution set at 10 you will achieve 5-6 readings per second.  If the reading is not critical, then using the polled method works best.

There is also a formatted string function: ds18x20_get_str_temp( DS18X20_MODE_C ); that produces a formatted string based on MODE_C or MODE_F.

UPDATE:

Forgot about compiling into a library and macros....

This new version has a different initialization:

Example:

#include "ds18x20.h"

#define msg( txt ) UART1_Write_Text( txt )

void main() 
{
    ds18x20_config_t sensor;
    char txt_buffer[50];
    
    sensor.port = &PORTA;
    sensor.pin = 7;
    sensor.resolution = RES12;
    sensor.alarm_high = 0x22;
    sensor.alarm_low = 0x01;
    
    UART1_Init( 38400 );
    Delay_ms( 100 );
    
    ds18x20_init( &sensor );
    
    while(1)
    {
        sprintf( txt_buffer, "Temp is: %f\r\n", ds18x20_get_temp() );
        msg( txt_buffer );
        Delay_ms( 1000 );
    }

}

ALSO FROM THIS AUTHOR

Printf Support AVR / ARM

0

Adds printf and sprintf functionality to MikroC. Uses about 1.5k.

[Learn More]

AVR Webserver

0

AVR Webserver: Dependencies - FAT32 library, Ethernet library Will allow you to load any size website, including images, css, and js files from SD media. This is my first version, but the example project included will give you a starting point.

[Learn More]

Add Standard bool / true / false to MikroC

0

This is not my library, but a opensource header file that adds boolean datatype to MikroC. Copy this file to the ../Mikroeleckronika/"your ide"/include/ directory. In your project that will use boolean types include this line: #include <stdbool.h>

[Learn More]