On Sat, 1 Jul 2017, panic wrote:

Example: PINx toggle feature

DDRB = 0xff;
PORTB = 0xff;
PINB |= _BV(PB0); // sbi _SFR_IO_REG(PINB), 0

For such things, I recommend against using C code as an example.
What the compiler should do with such things is not obvious.
In the case of avr-gcc,
what it does depends signifcantly on the optimization level.
The choice of sbi or not affects the final outcome, not just the speed.
'Tain't obvious that such statements should even be allowed.

Expected behaviour:
 PB0 toggles from 1 -> 0
PINB is a bit-accessible IO register. The SBI instruction behaves as if
0x01 had been written.

Simulavr behaviour:
 All bits (PB7..PB0) toggle from 1 -> 0.
Simulavr emulates SBI as RMW:
- Read PINB: 0xff (each input stage=1)
- Modify: 0xff | 0x01 --> 0xff
- Write: 0xff --> PINB, == "PORTB ^= 0xff"

The PINx toggle feature can also be used to toggle pullups ("independent
on the value of DDRxn").

--
Michael   henne...@web.cs.ndsu.nodak.edu
"Sorry but your password must contain an uppercase letter, a number,
a haiku, a gang sign, a heiroglyph, and the blood of a virgin."
                                                             --  someeecards

_______________________________________________
Simulavr-devel mailing list
Simulavr-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/simulavr-devel

Reply via email to