I have written a piece of code which manipulates the DDR for port B:
#include <avr/io.h>
int main(void)
{
DDRB = 0;
DDRB = 1;
DDRB = 2;
DDRB = 4;
DDRB = 8;
DDRB = 16;
DDRB = 32;
DDRB = 64;
DDRB = 128;
return 0;
}
I'm using the simulator and I'm having a hard time in figuring out how this maps in the I/O view, and what will happen on the actual device. I'm stepping over the DDRB=1..128 instructions.
As expected, DDRB values in the I/O view go from 0x1 to 0x20 as I execute the first 6 instructions, DDRB=1..32. However the other two instructions DDRB=64,128 have the effect of setting DDRB in the I/O view to 0x0. In a way this is not entirely surprising, as the ATtiny85 has only 6 PB pins. But is this behavior expected?
The real question is: what are the little squares in the I/O view next to the value of DDRB saying? Here is the state of DDRB in I/O view after each single instruction in main:
DDRB= 0; --> DDRB 0x37 0x0 000000
DDRB= 1; --> DDRB 0x37 0x1 000000
DDRB= 2; --> DDRB 0x37 0x2 000000
DDRB= 4; --> DDRB 0x37 0x4 000001
DDRB= 8; --> DDRB 0x37 0x8 000010
DDRB= 16; --> DDRB 0x37 0x10 000100
DDRB= 32; --> DDRB 0x37 0x20 001000
DDRB= 64; --> DDRB 0x37 0x0 000000
DDRB=128; --> DDRB 0x37 0x0 000000
Also, if I hover the mouse on the little squares, their names range from Bit 2 (the rightmost) to Bit 7 (the leftmost). How does this map to the pins of the real device? and also Why are they named from 2 to 7 instead than from 0 to 5, as on the device (PB0-PB5)?.
I thought initially that the configuration fuses in the simulator are responsible for certain bits of DDRB not being programmable. For instance I know that RSTDISBL must be unprogrammed to enable PB5, and I guess the same is true for the corresponding DDR. But which column is PB5 on the I/O view?.
I also tried to set the fuses in C code:
FUSES =
{
.low = 0x62,
.high = 0x5f,
.extended = 0xff
};
The setting 0x5f for the high fuse should mean that RSTDISBL is disabled, according to the online fuse calculator. However the behavior in I/O view is still the same.