Loading...
Welcome,
Guest
. Please
login
or
register
.
May 20, 2013, 08:28:45 am
|
Arduino Forum
::
International
::
Italiano
(Moderators:
Federico Vanzati
,
leo72
,
UweFederer
) :: Or And
« previous topic
next topic »
Pages: [
1
]
Go Down
Print
Author
Topic: Or And (Read 142 times)
0 Members and 1 Guest are viewing this topic.
xSanciopanzax
Pavia
Offline
Newbie
Karma: 0
Posts: 25
Or And
«
on:
January 15, 2012, 04:25:32 pm »
Bigger
Smaller
Reset
Che cosa cambia fra:
TCCR2B &= ~(1<<CS21);
e..
TCCR2B |= ~(1<<CS21);
Prende il registro e....
Logged
leo72
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16440
Don't know what I do
Re: Or And
«
Reply #1 on:
January 15, 2012, 04:29:33 pm »
Bigger
Smaller
Reset
Un OR è una somma logica, si usa fare così quando si vuol essere sicuri che un bit assuma valore 1 in ogni caso.
1 OR 0 = 1
1 OR 1 = 1
Un AND restituisce invece 1 solo quando entrambi i bit sono a 1
1 AND 0 = 0
1 AND 1 = 1
0 AND 1 = 0
Però normalmente i codici citati NON si usano nella seconda forma che hai usato.
TCCR2B |= ~(1<<CS21);
Di solito è:
TCCR2B |= (1<<CS21);
Questa forma deve restituire 1, quindi il NOT (abbreviato dal simbolo ~) non si usa con l'OR ma solo con l'AND. Difatti questa forma:
TCCR2B &= ~(1<<CS21);
serve a porre a 0 il bit CS21 indipendentemente dal valore che ha nel registro TCCR2B
Logged
Guide for ATtinys, swRTC and secTimer libs, Micrologio, Atmega1284 core, ArduinoISP2, leOS operating system etc..
xSanciopanzax
Pavia
Offline
Newbie
Karma: 0
Posts: 25
Re: Or And
«
Reply #2 on:
January 15, 2012, 04:37:35 pm »
Bigger
Smaller
Reset
Si, ho sbagliato a scrivere.Grazie mille ho capito ma....
Ma posso scrivere direttamente:
TCCR2B &= (0<<CS21);
E lecito?
suppongo di no però.....
Logged
leo72
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16440
Don't know what I do
Re: Or And
«
Reply #3 on:
January 15, 2012, 04:49:45 pm »
Bigger
Smaller
Reset
No. Il segno "<<" è uno spostamento a SX del bit 1 di tante posizioni quanto è il valore rappresentato dal registro in uso.
Spostare il bit 0 equivale a non spostare nulla.
Cioè
0<<4 equivale a 0
1<<4 equivale a 16
Logged
Guide for ATtinys, swRTC and secTimer libs, Micrologio, Atmega1284 core, ArduinoISP2, leOS operating system etc..
uwefed
BZ (I)
Offline
Brattain Member
Karma: 161
Posts: 15651
+39 349 2158303
Re: Or And
«
Reply #4 on:
January 15, 2012, 05:43:36 pm »
Bigger
Smaller
Reset
Trovi di piú su
http://arduino.cc/en/Reference/BitwiseAnd
http://arduino.cc/en/Reference/BitwiseXorNot
http://arduino.cc/en/Reference/Bitshift
Sono operazioni a livello di singoli bit. Vene fatto un and/or/xor bit per bit di un bte o di un registro.
Queste operazioni vengono usate per settare o cancellare singoli bit all interno di un byte o un registro senza cambiare gli altri.
Ciao Uwe
Logged
Pages: [
1
]
Go Up
Print
« previous topic
next topic »
|
Arduino Forum
::
International
::
Italiano
(Moderators:
Federico Vanzati
,
leo72
,
UweFederer
) :: Or And
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> General Discussion
-----------------------------
Using Arduino
-----------------------------
=> Installation & Troubleshooting
=> Project Guidance
=> Programming Questions
=> General Electronics
=> LEDs and Multiplexing
=> Displays
=> Audio
=> Motors, Mechanics, and Power
=> Sensors
=> Networking, Protocols, and Devices
=> Interfacing w/ Software on the Computer
-----------------------------
Topics
-----------------------------
=> E-Textiles and Craft
=> Robotics
=> Science and Measurement
=> Home Automation and Networked Objects
=> Device Hacking
=> Education and Teaching
=> Interactive Art
=> Product Design
-----------------------------
Development
-----------------------------
=> Suggestions for the Arduino Project
=> Other Hardware Development
=> Other Software Development
-----------------------------
Community
-----------------------------
=> Website and Forum
=> Products and Services
=> Gigs and Collaborations
=> Workshops and Events
=> Local Groups
=> Exhibition / Gallery
=> Bar Sport
-----------------------------
International
-----------------------------
=> Deutsch
=> Español
=> Français
=> Italiano
=> Portugues
=> Scandinavia
-----------------------------
Forum 2005-2010 (read only)
-----------------------------
===> Uno Punto Zero
===> Bar Sport
===> Frequently-Asked Questions
===> News
===> Exhibition
===> Workshops
===> Interfacing
===> Bugs & Suggestions
===> Development
===> Troubleshooting
===> Portugues
===> Deutsch
===> Español
===> Français
===> Italiano
===> Scandinavia
===> Development
===> Interfacing
===> Syntax & Programs
===> Bugs & Suggestions
===> Troubleshooting
===> Report Spam at Arduino.cc
===> Forum
===> Playground Wiki
=> General
=> Hardware
=> Software
=> International
=> Web/Forum/Email/Spam
-----------------------------
Using Arduino
-----------------------------
=> Storage
=> Microcontrollers
-----------------------------
International
-----------------------------
===> Humor y Debate
===> Talleres, Encuentros, ...
===> Tutoriels et cours
===> Réalisations et Projets Finis
===> Le bar
=> Nederlands
===> Software
===> Hardware
===> Proyectos
===> Documentación
=> India
===> Hardware
===> Software
===> Megatopic
-----------------------------
Products
-----------------------------
=> The Arduino Starter Kit
=> Arduino Due
-----------------------------
International
-----------------------------
===> Generale
-----------------------------
Products
-----------------------------
=> Arduino Esplora
=> Arduino GSM Shield
-----------------------------
Maker Faire Rome - The European Edition
-----------------------------
=> Makers
=> Events and Tour
Loading...