basref32.pdf

(407 KB) Pobierz
BASCOM-8051
LANGUAGE REFERENCE
© 1999 MCS Electronics
1WRESET,1WREAD,1WWRITE
Action
These routines can be used to communicate with Dallas Semiconductors 1Wire-devices.
Syntax
1WRESET
1WWRITE
var1
var2
= 1WREAD()
Remarks
1WRESET
1WWRITE
var1
var2
= 1WREAD()
Reset the 1WIRE bus. The error variable ERR will return 1
if an error occurred.
Sends the value of var1 to the bus.
Reads a byte from the bus and places it into var2.
var1 : Byte, Integer, Word, Long, Constant.
var2 : Byte, Integer, Word, Long.
Example
'--------------------------------------------------
'
1WIRE.BAS
' Demonstrates 1wreset, 1wwrite and 1wread()
' pullup of 4K7 required to VCC from P.1
' DS2401 serial button connected to P1.1
'--------------------------------------------------
Config
1wire =
P1.1
'use this pin
Dim
Ar(8)
As Byte
, A
As Byte
, I
As Byte
1wreset
Print Err
1wwrite
&H33
For
I = 1
To
8
Ar(I) =
1wread()
Next
For
I = 1
To
8
Printhex Ar(I);
Next
Print
End
'reset the bus
'print error 1 if error
'read ROM command
'read byte
'print output
'linefeed
$ASM - $END ASM
Action
Start of inline assembly code block.
Syntax
$ASM
Remarks
Use $ASM together with $END ASM to insert a block of assembler code in your BASIC code.
Example
Dim c as Byte
$ASM
Mov r0,#{C}
Mov a,#1
Mov @r0,a
$END ASM
Print c
End
;address of c
;store 1 into var c
$INCLUDE
Action
Includes an ASCII file in the program at the current position.
Syntax
$INCLUDE
file
Remarks
file
Name of the ASCII file, which must contain valid BASCOM statements.
This option can be used if you make use of the same routines in
Many programs. You can write modules and include them into your
program.
If there are changes to make you only have to change the module file,
not all your BASCOM programs.
You can only include ASCII files!
Example
'-----------------------------------------------------------
'
(c) 1997,1998 MCS Electronics
'------------------------------------------------------------
' file: INCLUDE.BAS
' demo: $INCLUDE
'------------------------------------------------------------
Print "INCLUDE.BAS"
$include c:\bascom\123.bas
'include file that prints Hello
Print "Back in INCLUDE.BAS"
End
$BAUD
Action
Instruct the compiler to override the baud rate setting from the options menu.
Syntax
$BAUD =
var
Remarks
var
The baud rate that you want to use.
var : Constant.
When you want to use a crystal/baud rate that can't be selected from the options, you can
use this compiler directive.
You must also use the $CRYSTAL directive.
These statements always work together.
In the generated report, you can view which baud rate is actually generated.
However, the baudrate is only shown when RS-232 statements are used like PRINT, INPUT
etc.
See also
$CRYSTAL
Example
$BAUD = 2400
$CRYSTAL = 14000000
PRINT "Hello"
END
' 14 MHz crystal
Zgłoś jeśli naruszono regulamin