๐ง Imagine a wardrobe with many numbered drawers (0x04, 0x05, 0x06...). Each drawer has 8 switches (bits 7...0).
The microcontroller can only: turn on (SBI) or turn off (CBI) these switches. When you turn on switch 5 of drawer 0x05, pin D13 lights up. When you turn on switches 0-3 of the same drawer, the motor takes one step.
No magic: it's just a wardrobe with drawers and switches. The names DDRB, PORTB are just labels we humans attached. The chip only sees the numbers.
Registers
7
6
5
4
3
2
1
0
0x0D (0x2D)
Reserved
โ
โ
โ
โ
โ
โ
โ
โ
0x0C (0x2C)
Reserved
โ
โ
โ
โ
โ
โ
โ
โ
0x0B (0x2B)
PORTD
PORTD7
PORTD6
PORTD5
PORTD4
PORTD3
PORTD2
PORTD1
PORTD0
73
0x0A (0x2A)
DDRD
DDD7
DDD6
DDD5
DDD4
DDD3
DDD2
DDD1
DDD0
73
0x09 (0x29)
PIND
PIND7
PIND6
PIND5
PIND4
PIND3
PIND2
PIND1
PIND0
73
0x08 (0x28)
PORTC
โ
PORTC6
PORTC5
PORTC4
PORTC3
PORTC2
PORTC1
PORTC0
73
0x07 (0x27)
DDRC
โ
DDC6
DDC5
DDC4
DDC3
DDC2
DDC1
DDC0
73
0x06 (0x26)
PINC
โ
PINC6
PINC5
PINC4
PINC3
PINC2
PINC1
PINC0
73
0x05 (0x25)
PORTB
PORTB7
PORTB6
PORTB5
PORTB4
PORTB3
PORTB2
PORTB1
PORTB0
72
0x04 (0x24)
DDRB
DDB7
DDB6
DDB5
DDB4
DDB3
DDB2
DDB1
DDB0
72
0x03 (0x23)
PINB
PINB7
PINB6
PINB5
PINB4
PINB3
PINB2
PINB1
PINB0
72
0x02 (0x22)
Reserved
โ
โ
โ
โ
โ
โ
โ
โ
0x01 (0x21)
Reserved
โ
โ
โ
โ
โ
โ
โ
โ
0x00 (0x20)
Reserved
โ
โ
โ
โ
โ
โ
โ
โ
๐ง Reality: The microcontroller only sees the numbers (0x04, 0x05...). We humans gave names like DDRB, PORTB.
๐ฆ step 0
Materials & wiring
Arduino Uno / Nano (ATmega328P)
ULN2003 driver module
28BYJ-48 stepper motor (5V)
Dupont wires
External 5V power supply (recommended)
Wiring
D8PORTB0ULN2003 IN1
D9PORTB1ULN2003 IN2
D10PORTB2ULN2003 IN3
D11PORTB3ULN2003 IN4
5V-module power
GND-common ground
Note: D8-D11 are bits 0-3 of PORTB register (0x05).
โก step 1
LED D13 (test)
The built-in LED D13 is on bit 5 of PORTB (0x05).
; set PB5 as OUTPUT (DDRB 0x04 bit5)
sbi 4, 5
; turn LED on (PORTB 0x05 bit5)
sbi 5, 5
loop:
rjmp loop