' DS2423_1.Bas
'
' Reads 32 bytes in RAM page 01c0 and displays to the terminal.
' Reads four byte counter and displays the result.  Repeats for RAM
' page 0x01e0.
'
' PICAXE-20X2			DS2423
'
' C.0  ------------------------- DQ
'
' Note there is a 4.7K pull up resistor to +5 VDC on the data lead.
'
' copyright, Peter H Anderson, Baltimore, MD, Sept, '09
#picaxe 20x2
#Terminal 9600
#No_Table
#No_Data
#freq m4

    Symbol Dummy = B0

    Symbol AA = B1
    Symbol BB = B2
    Symbol CC = B3
    Symbol DD = B4
    Symbol N = B5

    Symbol X = W3
    Symbol Y = W4

    dirsB = %11111111
    adcsetup = 0

    Do
       OWOut C.0, %0001, ($cc, $a5, $c0, $01) ' read page c0 for Counter 0

       ' read memory page plus counter
       ' beginning at &H01c0

       For N = 1 to 32		  ' read the 32 bytes
          OWIn C.0, %0000, (Summy)
          SerTxD (#N, "  ", #Dummy, CR, LF)
       Next

       SerTxD ("000000000000000000000000", CR, LF)

         ' read the counter

       OWIn C.0, %0000, (AA)
       OWIn C.0, %0000, (BB)
       OWIn C.0, %0000, (CC)
       OWin C.0, %0000, (DD)

       X = BB
       X = X * 256 + AA

       Y = DD
       Y = Y * 256 + CC

       SerTxD (#X, "  ", #Y, CR, LF)

       OWOut C.0, %0001, ($cc, $a5, $e0, $01) ' page e0 for Counter 1

       ' read memory page plus counter
       ' beginning at &H01e0

       For N = 1 to 32		  ' read the 32 bytes
          OWIn C.0, %0000, (Dummy)
          'SerTxD (#N, "  ", #Dummy, CR, LF)
       Next

       SerTxD ("11111111111111111111111", CR, LF)

         ' read the counter

       OWIn C.0, %0000, (AA)
       OWIn C.0, %0000, (BB)
       OWIn C.0, %0000, (CC)
       OWin C.0, %0000, (DD)

       X = BB
       X = X * 256 + AA

       Y = DD
       Y = Y * 256 + CC

       SerTxD (#X, "  ", #Y, CR, LF)

       Pause 1000

    Loop