© MCS Electronics, 1995-2007 |
|
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
'Bin2Gray() converts a byte,integer,word or long into grey code. |
'Gray2Bin() converts a gray code into a binary value |
|
Dim B As Byte |
' could be |
word,integer or long too
Print "BIN" ; Spc(8) ; "GREY"
For B = 0 To 15
Print B ; Spc(10) ; Bin2gray(b)
Next
Print "GREY" ; Spc(8) ; "BIN"
For B = 0 To 15
Print B ; Spc(10) ; Gray2bin(b)
Next
End
BITWAIT
Action
Wait until a bit is set or reset.
Syntax
BITWAIT x , SET/RESET
Remarks
X |
Bit variable or internal register like PORTB.x , where x ranges from0-7. |
|
|
When using bit variables make sure that they are set/reset by software otherwise your program will stay in a loop.
When you use internal registers that can be set/reset by hardware such as PINB.0 this doesn't apply since this state can change as a result from for example a key press.
See also
NONE
ASM
Calls: NONE
Input: NONE
Output: NONE
Code : shown for address 0-31
© MCS Electronics, 1995-2007
label1:
Sbic PINB.0,label2 Rjmp label1 Label2:
Example
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
frequency |
' use baud rate |
$baud = 19200 |
$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
Dim A As Bit
Bitwait A , Set 'wait until bit a is set
'the above will never contine because it is not set i software 'it could be set in an ISR routine
Bitwait Pinb.7 , Reset |
'wait until bit 7 |
of Port B is 0. |
|
End |
|
BITS
Action
Set all specified bits to 1.
Syntax
Var = Bits( b1 [,bn])
Remarks
Var |
The BYTE/PORT variable that is assigned with the constant. |
|
B1 , bn A list of bit numbers that must be set to 1.
While it is simple to assign a value to a byte, and there is special boolean notation &B for assigning bits, the Bits() function makes it simple to assign a few bits.
B = &B1000001 : how many zero’s are there?
This would make it more readable : B = Bits(0, 6)
You can read from the code that bit 0 and bit 6 are set to 1.
It does not save code space as the effect is the same.
It can only be used on bytes and port registers.
page -288-
© MCS Electronics, 1995-2007
Valid bits are in range from 0 to 7.
See Also
NBITS
Example
'----------------------------------------------------------------------------- |
|
--- |
: bits-nbits.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo for Bits() AND Nbits() |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'use in simulator |
: possible |
'-----------------------------------------------------------------------------
---
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
frequency |
' use baud rate |
$baud = 19200 |
$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 |
|
Dim B As Byte |
|
'while you can use &B notation for setting bits, like B = &B1000_0111 'there is also an alternative by specifying the bits to set
B = Bits(0 , 1 , 2 , 7) 'set only bit 0,1,2 and 7
Print B
'and while bits() will set all bits specified to 1, there is also Nbits() 'the N is for NOT. Nbits(1,2) means, set all bits except 1 and 2
B = Nbits(7) 'do not set bit 7
Print B
End
BLOAD
Action
Writes the Content of a File into SRAM
Syntax
BLoad sFileName, wSRAMPointer
|
© MCS Electronics, 1995-2007 |
Remarks |
|
|
sFileName |
(String) Name of the File to be read |
|
wSRAMPointer |
(Word) Variable, which holds the SRAM Address to which the content |
|
|
of the file should be written |
|
|
|
|
This function writes the content of a file to a desired space in SRAM. A free handle is needed for this function.
See also
INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT
ASM
Calls |
_BLoad |
|
Input |
X: Pointer to string |
Z: Pointer to Long-variable, which holds the start position of |
|
with filename |
SRAM |
Output |
r25: Errorcode |
C-Flag: Set on Error |
|
|
|
Example
' THIS IS A CODE FRAGMENT, it needs AVR-DOS in order to work
'now the good old bsave and bload |
|
Dim Ar(100)as Byte , I Asbyte |
|
For I = 1 To 100 |
' fill the array |
Ar(i) = I |
Next |
|
Wait 2 |
|
W = Varptr(ar(1)) |
|
Bsave"josef.img", W , 100 |
|
For I = 1 To 100 |
' reset the array |
Ar(i) = 0 |
Next |
|
Bload "josef.img" , W |
' Josef you are |
amazing ! |
|
For I = 1 To 10 |
|
Print Ar(i) ; " "; |
|
Next |
|
Print |
|
BOX
Action
Create a filled box on a graphical display.