Writing & Reading to iButton EEPROM


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77

    Default Writing & Reading to iButton EEPROM

    '************************************************* ***************
    '* How to write and then read back from an iButton EEPROM *
    '* DS1973 or the equivalent 1-wire device, the DS2433 EEPROM. *
    '* : All Rights Reserved *
    '************************************************* ***************
    @ device hs_OSC, wdt_on, pwrt_on, protect_off

    DEFINE OSC 20
    iButton var PortD.2 'Connected iButton on 16F877 at this port.

    RESULT VAR BYTE[19] 'Byte array to put string of characters into.
    IN VAR BYTE 'Byte to collect the 1 byte you want to read.
    Taddr var byte[2] 'Target address 2 bytes (TA1 & TA2)
    ES var byte 'Ending offset data status (E/S)

    IN=0
    RESULT=0

    '(Just connect your serout to to the serial communicator @ 19200)

    START:

    '------------------------------------------------
    'WRITE TO EEPROM
    '------------------------------------------------
    OWOUT ibutton,1,[$CC,$0F,$00,$00] 'Write to scratchpad

    OWOUT IBUTTON,0,["Testing this EEPROM",10,13] 'Write a few characters or values into EEPROM
    OWout IBUTTON,1,[$CC,$AA] 'get ready to read scratchpad
    owin ibutton,0,[Taddr[0],Taddr[1],ES] 'read back the scratchpad to get the Authorisation code
    owout ibutton,1,[$CC,$55] 'Write back the contents of the target address & E/S register
    'to allow copy scratchpad to take place.
    owout ibutton,0,[Taddr[0],Taddr[1],ES] 'Enter Authorisation code as TA1,TA2,E/S

    PAUSE 25 'Give EEPROM time to write


    '-----------------------------------------------
    'READ STRING OF BYTES FROM EEPROM
    '-----------------------------------------------
    OWOUT ibutton,1,[$CC,$F0,$00,$00] 'Read scratchpad
    OWIN IBUTTON,0,[STR RESULT\7] '
    PAUSE 1 'Not really nessesary
    SEROUT2 PORTD.7,16416,[RESULT],10,13] 'You should get the full string you put in.


    '------------------------------------------------
    'READ 1 BYTE FROM SPECIFIC ADDRESS
    '------------------------------------------------
    OWOUT ibutton,1,[$CC,$F0,$010,$00] 'Read from address $10, first byte of
    'target address is the Least Significant.

    OWIN IBUTTON,0,[IN]
    SEROUT2 PORTD.7,16416,[IN] 'You should get the letter "T"

    END

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Thanks Chris !
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Nice job! Will be useful.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Writing, Reading from Internal PIC EEPROM
    By NO2K in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th October 2007, 00:35
  3. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  4. reading, writing, and displaying from eeprom
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th January 2006, 22:05
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 18:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts