BITS/de
From MCS Wiki AVR
< BITS
Revision as of 01:01, 1 March 2013 by Stefanhamburg (Talk | contribs)
Contents |
Funktion
Setzt alle angegebenen Bits auf 1.
Syntax
Var = Bits( b1 [,bn])
Anmerkungen
Var |
Die BYTE/PORT Variable die verändert werden soll. |
B1 , bn |
Eine Liste mit Bitnummern die auf 1 gesetzt werden soll. |
Während es möglich ist, einer Byte/Port-Variablen einen Wert zuzuweisen und es auch spezielle Binärnotation mit &B gibt um die Bits zuzuweisen ermöglicht die Bits() Funktion das einfache Zuweisen einzelner Bits.
B = &B1000001 ' Wieviele Nullen sind das?
Dies ist besser lesbar: B = Bits(0, 6)
Man sieht sofort, dass Bit 0 und Bit 6 auf 1 gesetzt werden.
Es wird kein Programmspeicher gespart weil der Effekt derselbe ist
Kann nur für Byte-Variable und Ports verwendet werden.
Gültige Bitnummern sind im Bereich von 0 bis 7.
Siehe auch
Example
'-------------------------------------------------------------------------------- '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 ' used crystal frequency $baud = 19200 ' use baud rate $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 '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
Languages | English • Deutsch |
---|