ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8166
Скачиваний: 1
© MCS Electronics, 1995-2007
See also
1WRESET , 1WREAD , 1WWRITE , 1WIRECOUNT , 1WRESET , 1WSEARCHFIRST , 1WSEARCHNEXT
Example
'----------------------------------------------------------------------------- |
|
--- |
: 1wire.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates 1wreset, 1wwrite and 1wread() |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
' pull-up of 4K7 required to VCC from Portb.2 |
|
' DS2401 serial button connected to Portb.2 |
|
'----------------------------------------------------------------------------- |
|
--- |
|
$regfile = "m48def.dat" |
|
$crystal = 8000000 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
'default use 10 |
$swstack = 10 |
|
for the SW stack |
'default use 40 |
$framesize = 40 |
|
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'when only bytes are used, use the following lib for smaller code $lib "mcsbyte.lib"
Config 1wire = Portb.0 |
'use this pin |
'On the STK200 jumper B.0 must be inserted |
|
Dim Ar(8) As Byte , A As Byte , I As Byte |
|
Do |
|
Wait 1 |
'reset the device |
1wreset |
|
Print Err |
'print error 1 if |
error |
'read ROM command |
1wwrite &H33 |
|
For I = 1 To 8 |
'place into array |
Ar(i) = 1wread() |
|
Next |
|
'You could also read 8 bytes a time by unremarking the next line |
|
'and by deleting the for next above |
'read 8 bytes |
'Ar(1) = 1wread(8) |
|
For I = 1 To 8 |
'print output |
Print Hex(ar(i)); |
|
Next |
'linefeed |
Loop |
|
'NOTE THAT WHEN YOU COMPILE THIS SAMPLE THE CODE WILL RUN TO THIS POINT
page -313-