NBITS/de
m (1 revision) |
(→Example) |
||
Line 68: | Line 68: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Beispiel</span> = |
<br/><source lang="bascomavr"> | <br/><source lang="bascomavr"> | ||
Line 82: | Line 82: | ||
$regfile = "m48def.dat" ' specify the used micro | $regfile = "m48def.dat" ' specify the used micro | ||
− | $crystal = 4000000 ' | + | $crystal = 4000000 ' Taktfrequenz |
− | $baud = 19200 ' | + | $baud = 19200 ' Baudrate |
$hwstack = 32 ' default use 32 for the hardware stack | $hwstack = 32 ' default use 32 for the hardware stack | ||
$swstack = 10 ' default use 10 for the SW stack | $swstack = 10 ' default use 10 for the SW stack | ||
Line 90: | Line 90: | ||
Dim B As Byte | Dim B As Byte | ||
− | ' | + | 'Man kann die &B Notation zum Setzen von Bits benutzen B = &B1000_0111 |
− | ' | + | 'Deutlicher ist es, die zu setzenden Bits mit der BITS() Funktion anzugeben: |
− | B = Bits(0 , 1 , 2 , 7) ' | + | B = Bits(0 , 1 , 2 , 7) 'setzt nur die Bits 0,1,2 und 7 |
Print B | Print B | ||
− | ' | + | 'Während bits() alle genannten Bits auf 1 setzt gibt es auch Nbits() |
− | ' | + | 'Das N steht für NOT. Nbits(1,2) bedeutet, dass alle Bits außer 1 und 2 gesetzt werden. |
− | B = Nbits(7) ' | + | B = Nbits(7) 'Setze NICHT 7 |
Print B | Print B | ||
End | End | ||
+ | |||
</source><br/>{{Languages}} | </source><br/>{{Languages}} | ||
[[Category:BASCOM Language Reference/de]] | [[Category:BASCOM Language Reference/de]] |
Revision as of 01:07, 1 March 2013
Contents |
= (**COPIED FROM ENGLISH PAGE**) === Action
Set all except the specified bits to 1.
Syntax
Var = NBITS( b1 [,bn])
Remarks
Var |
The BYTE/PORT variable that is assigned with the constant. |
B1 , bn |
A list of bit numbers that NOT 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() and NBits() function makes it simple to assign a few bits.
B = &B01111101 : how many zero’s are there?
This would make it more readable: B = NBits(1, 7)
You can read from the code that bit 1 and bit 7 are NOT set to 1.
It does not save code space as the effect is the same.
The NBITS() function will set all bits to 1 except for the specified bits.
It can only be used on bytes and port registers.
Valid bits are in range from 0 to 7.
See Also
Beispiel
'-------------------------------------------------------------------------------- 'name : bits-nbits.bas '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 $crystal = 4000000 ' Taktfrequenz $baud = 19200 ' Baudrate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Dim B As Byte 'Man kann die &B Notation zum Setzen von Bits benutzen B = &B1000_0111 'Deutlicher ist es, die zu setzenden Bits mit der BITS() Funktion anzugeben: B = Bits(0 , 1 , 2 , 7) 'setzt nur die Bits 0,1,2 und 7 Print B 'Während bits() alle genannten Bits auf 1 setzt gibt es auch Nbits() 'Das N steht für NOT. Nbits(1,2) bedeutet, dass alle Bits außer 1 und 2 gesetzt werden. B = Nbits(7) 'Setze NICHT 7 Print B End
Languages | English • Deutsch |
---|