Maandelijks archief: februari 2012

1-Wire DS18B20 Thermometer

Measuring room or object temperatures with the DS18B20. It is a digital component wich does all the work for you. You only need to COMMAND it do the measurement. A short moment later you can request 2 bytes containing the temperature.

Of course there is a protocal wich says how to communicate. See 1-Wire and the DS18B20 datasheet.

How 1-Wire works (by Maxim): http://www.maxim-ic.com/products/1-wire/flash/overview/index.cfm

Maxim 1-Wire

Maxim 1-Wire, how to communicate

Used parts:

  • PIC16F689
    1. FLASH: 4096 Words
    2. RAM: 256 Bytes
    3. IO Pins: 18
    4. Clock internal: 8MHz internal, 4MHz default config
    5. Clock external:up to 20MHz external
  • LCD 2×16, HD44780 Compatible
  • DS18B20

Lees verder

PIC16 C Sample: 1-Wire

Environment: MPLAB X IDE + HI TECH Compiler for PIC16

#define OW_TRIS TRISA0      //Port mode register, 1=input,0=output
#define OW_PORT RA0         //Pin connected to 1-wire bus

int owReset(void)
{
    char state = 0;
    OW_TRIS = 0;        //Set as output
    OW_PORT = 0;        //Drive Low
    __delay_us(480);
    OW_TRIS = 1;        //Release, Set back as input
    __delay_us(70);
    state = !OW_PORT;   //If devices are present, it will keep the pin low
                        //! will invert 1=0, 0=1
    __delay_us(410);
    return state;       //Returns 1 if devices are present
}

Lees verder