OWRESET   OWRDBIT   OWRDBYTE   OWWRBIT   OWWRBYTE
please dont rip this site

           

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' This program scans the 1-wire bus and when a device is detected it will
' read and display its serial number.


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ            4_000_000


' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

DQ              VAR     RB.0                    ' 1-wire bus (4.7k pull-up)
Sout            VAR     RB.1                    ' output to SEETRON 2x16


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

Baud            CON     "N9600"

LcdI            CON     $FE                     ' instruction
LcdCls          CON     $01                     ' clear the LCD
LcdHome         CON     $02                     ' move cursor home
LcdCrsrL        CON     $10                     ' move cursor left
LcdCrsrR        CON     $14                     ' move cursor right
LcdDispL        CON     $18                     ' shift chars left
LcdDispR        CON     $1C                     ' shift chars right
LcdDDRam        CON     $80                     ' Display Data RAM control
LcdCGRam        CON     $40                     ' Character Generator RAM
LcdLine1        CON     $80                     ' DDRAM address of line 1
LcdLine2        CON     $C0                     ' DDRAM address of line 2

SearchROM       CON     $F0
ReadROM         CON     $33                     ' read ID, serial num, CRC


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

idx             VAR     Byte                    ' loop counter
char            VAR     Byte                    ' char for LCD
owByte          VAR     Byte                    ' byte for OW work
owSerial        VAR     Byte(8)                 ' OW serial number

regAddr         VAR     Byte                    ' register address
temp1           VAR     Byte                    ' work vars
temp2           VAR     Byte
temp3           VAR     Byte
temp4           VAR     Byte
temp5           VAR     Byte


' =========================================================================
  PROGRAM Start
' =========================================================================

Hex_Digits:
  DATA  "0123456789ABCDEF"


Messages:

Pgm_ID:
  DATA  "SX/B 1-wire Demo", 0

Bus_Short:
  DATA  "1-wire Bus short", 0

Bad_Bus:
  DATA  "Bad connection  ", 0

Good_PP:
  DATA  "Found device    ", 0

No_Device:
  DATA  "No device       ", 0

' Define message offsets

Msg1            CON     Pgm_ID - Messages
Msg2            CON     Bus_Short - Messages
Msg3            CON     Bad_Bus - Messages
Msg4            CON     Good_PP - Messages
Msg5            CON     No_Device - Messages


' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

DELAY           SUB     1, 2                    ' delay t {x m} ms
TXBYTE          SUB     1, 2                    ' transmit byte {x repeats}
TXHEX2          SUB     1                       ' transmit byte as HEX2
TXMSG           SUB     1                       ' transmit message


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_A = %0000                                 ' enable pull-ups
  PLP_B = %00000011                             ' .. except RB.0 and RB.1
  PLP_C = %00000000
  DELAY 250, 3                                  ' wait 750 ms for LCD

Main:
  TXBYTE LcdI                                   ' instruction prefix
  TXBYTE LcdCls                                 ' clear the LCD
  DELAY 10
  TXMSG Msg1                                    ' write banner in LCD

Scan_DQ:
  TXBYTE LcdI
  TXBYTE LcdLine2

  OWRESET DQ, owByte                            ' reset and sample presence

  IF owByte = %00 THEN                          ' bus short
    TXMSG Msg2
  ENDIF

  IF owByte = %01 THEN                          ' bad connection
    TXMSG Msg3
  ENDIF

  IF owByte = %10 THEN                          ' good presence detection
    TXMSG Msg4
    GOTO Show_SN
  ENDIF

  IF owByte = %11 THEN                          ' no device
    TXMSG Msg5
  ENDIF

  GOTO Fini

Show_SN:
  DELAY 250, 4                                  ' show found message
  TXBYTE LcdI                                   ' move back to L2/C0
  TXBYTE LcdLine2

  OWRESET DQ, owByte                            ' reset device
  OWWRBYTE DQ, ReadROM                          ' send read rom command
  FOR idx = 0 TO 7                              ' read serial number
    OWRDBYTE DQ, owByte
    owSerial(idx) = owByte
  NEXT
  FOR idx = 7 TO 0 STEP -1                      ' display on LCD
    owByte = owSerial(idx)
    TXHEX2 owbyte                               ' -- hex mode
  NEXT

Fini:
  DELAY 250, 8                                  ' 2 second pause
  GOTO Scan_DQ

  END


' -------------------------------------------------------------------------
' Subroutines
' -------------------------------------------------------------------------

' Use: DELAY timing {, multiplier}
' -- pauses for 'timing' {x 'multiplier'} milliseconds

DELAY:
  temp1 = __PARAM1
  IF __PARAMCNT = 1 THEN                        ' if no multiplier
    temp2 = 1                                   ' - set it to 1
  ELSE
    temp2 = __PARAM2
  ENDIF
  IF temp1 > 0 THEN
    IF temp2 > 0 THEN
      PAUSE temp1 * temp2
    ENDIF
  ENDIF
  RETURN


' Use: TXBYTE theByte {, repeats}
' -- transmit 'theByte' on Sio at Baud 'repeats' times

TXBYTE:
  temp1 = __PARAM1                              ' get byte
  IF __PARAMCNT = 1 THEN                        ' if no repeast
    temp2 = 1                                   ' - set it to 1
  ELSE
    temp2 = __PARAM2                            ' else get repeats
  ENDIF
  DO WHILE temp2 > 0                            ' send byte as required
    SEROUT Sout, Baud, temp1
    DEC temp2
  LOOP
  RETURN


' Use: TXMSG msgOffset
' -- transmits message in data statement

TXMSG:
  idx = __PARAM1                                ' get starting character
  DO
    READ Messages + idx, char                   ' read character
    IF char = 0 THEN EXIT                       ' if 0, message complete
    TXBYTE char                                 ' send character
    INC idx                                     ' point to next
  LOOP
  RETURN


' Use: TXHEX2 theByte
' -- transmit 'theByte' in HEX2 format

TXHEX2:
  temp4 = __PARAM1                              ' save byte
  temp5 = temp4                                 ' make copy
  SWAP temp5                                    ' swap nibs
  temp5 = temp5 & %00001111                     ' mask high nib
  READ Hex_Digits + temp5, char                 ' convert high nib to character
  TXBYTE char, 1                                ' send it
  temp4 = temp4 & %00001111                     ' get low nib
  READ Hex_Digits + temp4, char                 ' convert low nib to character
  TXBYTE char, 1                                ' send it
  RETURN

file: /Techref/parallax/sxb/sxb/1-wire_ex.htm, 8KB, , updated: 2006/4/10 14:47, local time: 2024/5/6 04:12,
TOP NEW HELP FIND: 
3.138.204.208:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.sxlist.com/techref/parallax/sxb/sxb/1-wire_ex.htm?key=1-wire&from;="> 1-Wire Example</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed? "1-wire"

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to www.sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .