• PicŪ Basic


  • Interfacing to a DS1990 i-Button device

    A DS1990 is an i-Button device that has a unique ID value imprinted within it. It can be used as an electronic key, or pass etc.. They're quite old devices, but are still extremely valid in modern times.















    The code below illustrates how to interface to a DS1990 one-wire i-Button device

    Code:
    '
    ' Read a DS1990 on-wire device
    '
       Device = 12F683
       Declare Xtal = 8
       Declare Optimiser_Level = 2
    
       Declare Serial_Baud = 9600
       Declare Rsout_Pin = GPIO.0
       Declare Rsout_Mode = 0
    
       Dim tDevicePresent As Bit       ' Holds 1 if the device is present, otherwise 0
       Dim ROM_NO[8] As Byte           ' Holds the read values from the device
    
       Symbol DQ_Pin = GPIO.1          ' Pin where the device is attached
    
    '--------------------------------------------------------------------------------------------
       GoTo Main                       ' Jump over the subroutines
    
    '--------------------------------------------------------------------------------------------
    ' Read a DS1990 one-wire device
    ' Input     : None
    ' Output    : tDevicePresent will contain 1 if a device is present
    ' Notes     : None
    '
    $define Device_Read() GoSub _Device_Read   
    
    _Device_Read:
      OWrite DQ_Pin, 1, _No_Device, [$33]
       ORead DQ_Pin, 0, [ROM_NO#0, ROM_NO#1, ROM_NO#2, ROM_NO#3, ROM_NO#4, ROM_NO#5, ROM_NO#6, ROM_NO#7]
       tDevicePresent = 1
       Return
    
    _No_Device:
        tDevicePresent = 0
        Return
    
    '---------------------------------------------------------------------------------------------------
    Main:
       Clear ANSEL                             ' \ Make pins digital
       CMCON0 = 7                              ' /
    
       While                                   ' Create an infinite loop
           Device_Read()                       ' Attempt to read the device
           If tDevicePresent = 1 Then          ' Is the device present?
               RSOut Dec ROM_NO#0, Dec ROM_NO#1, ",", Dec ROM_NO#2, ",",_
                     Dec ROM_NO#3, ",", Dec ROM_NO#4, ",", Dec ROM_NO#5, ",",_
                     Dec ROM_NO#6, ",", Dec ROM_NO#7, 13
           Else                                ' Otherwise... The device is not present. So....
               RSOut "No Device\r"             ' Transmit a message
           EndIf
           DelayMS 100
       Wend
    The video below shows the above program running within the proteus simulator:

  • Recent Activity

    towlerg-21522

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    towlerg Yesterday, 15:45 Go to last post
    towlerg-21522

    PIC18F1330 PLL problem

    Thread Starter: rcurl

    I'm just starting out on a new project that uses a PIC18F1330. I haven't used this specific chip before, so I began by trying to blink an LED just...

    towlerg Yesterday, 19:19 Go to last post
    towlerg-21522

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    towlerg Yesterday, 15:59 Go to last post