The convention is either PINx or PORTx register and NOT PIN register. You have missed 'x' to which I have wished to draw your kind attention.
please see my code in post #12 and then decide, have I missed something or not
I am referring to your post #15.
ah got you, so you were saying that instead of writing
since the PIN register is read-only and zero bits do not affect it
@b707 should have written
since the PINx registers are read-only and zero bits do not affect them
because that's how it's referred to in the spec
OK OK... not sure how much it adds to the technical debate though...
Not much! However, the practice keeps us remembering/reciting the bureaucratic signature styles of data sheets.
yeah, when there is doubt it's good to pay attention to the exact wording, but here it was pretty clear from the context... I don't think anyone could have been confused but it's a matter of personal preference and I know lots of engineers who indeed care of correctness in the most simple details.
x has the range B, C, and D; so, the register is changed to its plural form (registers) that followed correct verb-form (are) and finally the plural object (them).
Amazing!
I'm really weak in English, I'm sorry if my messages annoy someone.
don't take that too seriously
@GolamMostafa likes sometimes to pull legs and is nit-picky (I'm too β but more on type coherence and syntactic style in C++ than in English as for many of us here it's not our primary language anyway )
I am a non-native. Based on my limited knowledge of English Language Grammar, I do not see any syntax/semantics error in your above sentence. You have used a singular subject (PIN) and accordingly have maintained its verb-form and the associated object-form.
that's what I call nit-picky
The relevant information from data sheets:
1. Schematic of General IO
Figure-1:
2. Text describing features of Digital IO pin
Figure-2:
3. Analyzing to see if the text of Fig-2 goes correctly with Fig-1
(1) Consider DPin-2 (PIND2) and an input line/pin with internal pull-up resistor.
void setup()
{
Serial.begin(9600);
bitClear(DDRD, DDD2); //DPin-2 input with internal pull-up
bitSet(PORTD, PORTD2); //enable internal pull-up
Serial.println(digitalRead(PIND2)); //shows 1 correct
Serial.println(bitRead(PORTD, PORTD2)); //shows 1 correct
bitSet(PIND, PIND2);
Serial.println(bitRead(PORTD, PORTD2)); //shows 0; disables internal pull-up
bitSet(PIND, PIND2);
Serial.println(bitRead(PORTD, PORTD2)); //shows 1; enables back the pull-up
}
void loop() {}
(2) My observation is --
Writing 1 into PIND2 latch toggles the output of the internal PORTD2 latch.
DPin-2 remains as an input line.
(3) My question is --
(a) Where is PIND2 latch (or PIND Register) in Fig-1 on which bitSet(PIND, PIND2) acts?
(b) Is there any practical use of togging the internal latch (PORTD2)?
is that what you are asking for?
Too many posts to read so if someone else posted this, I'm a +1 to that.
Arduino pins are in Ports of 8 pins.
Each Port has 3 registers to control it.
-- The DDRx (data direction register) with 8 bits for 8 pins. 0 for input, 1 for output.
-- The PORTx register with all bits/pins showing LOW or HIGH selected.
-- The PINx register that shows the actual pin state has 1 extra function....
____ If you write to the PINx register, every 1 bit/pin gets toggled.
If you have a toggle-the-pin byte then writing it to PINx toggles the pin in ONE CYCLE.
Nick Gammon used that to make an Uno run single-color VGA.
well not in one depending how you write it (in C++, not in assembly)
The interesting learning for me here was that PINB |= 1<<PB5;
will actually be faster than PINB = 1<<PB5;
because in the latter, the compiler generates first a load and then an assignment (2 cycles) versus the use of sbi
(1 clock cycle) in the first case
of course SBI will only touch 1 bit, so if you have more than 2 bits, you're better off with the direct assignment
Depending how you write it.
byte data = 1<<PB5
PINB = data
I can also give an example of a limited pre-defined data set that did lead to intelligence.... all DNA is made from 8 amino acids!
WPx is the "Write pulse for PINx Register". This is fine. However, the PORTxn latch is clearly mentioned in Fig-1 of post #32 and NOT any latch for PINxn. Does PORTxn latch also works for PINxn's latch as both WPx and WPx work on PORTxn'?
actually
uint8_t data = 1<<PB5;
PINB = data;
generates
ldi r24,lo8(32)
out 0x3,r24
whereas
uint8_t data = 1<<PB5;
PINB |= data;
generates
sbi 0x3,5
β so there is a x2 factor between the two since you really have only 1 cycle
but if you have more than 1 bit to set
This code
uint8_t data = 0b11;
PINB = data;
will consume also 2 clock cycles
ldi r24,lo8(3)
out 0x3,r24
when
uint8_t data = 0b11;
PINB |= data;
consumes 3 clock cycles
in r24,0x3
ori r24,lo8(3)
out 0x3,r24
as the compiler reads PINB and OR its content with the mask before writing it back
You're right I guess, one cycle to flip the pin(s that can be all 8) but a load first.
Perhaps data should be const and the compiler would use a register to hold the value.
out 0x3, that_register
I tried and it did not change the code