🇮🇹 IT 🇬🇧 EN

28BYJ-48 + ULN2003
in puro assembly AVR

La spina dorsale: passi sequenziali, niente fronzoli.

🧠 Immagina un armadio con tanti cassetti numerati (0x04, 0x05, 0x06...). Ogni cassetto ha 8 interruttori (bit 7...0).

Il microcontrollore può solo: accendere (SBI) o spegnere (CBI) questi interruttori. Quando accendi l'interruttore 5 del cassetto 0x05, il pin D13 si accende. Quando accendi gli interruttori 0-3 dello stesso cassetto, il motore fa un passo.

Niente magia: è solo un armadio con cassetti e interruttori. I nomi DDRB, PORTB sono solo etichette che abbiamo attaccato noi umani. Lui vede solo i numeri.

Registri 7 6 5 4 3 2 1 0
0x0D (0x2D)Reserved
0x0C (0x2C)Reserved
0x0B (0x2B)PORTDPORTD7PORTD6PORTD5PORTD4PORTD3PORTD2PORTD1PORTD073
0x0A (0x2A)DDRDDDD7DDD6DDD5DDD4DDD3DDD2DDD1DDD073
0x09 (0x29)PINDPIND7PIND6PIND5PIND4PIND3PIND2PIND1PIND073
0x08 (0x28)PORTCPORTC6PORTC5PORTC4PORTC3PORTC2PORTC1PORTC073
0x07 (0x27)DDRCDDC6DDC5DDC4DDC3DDC2DDC1DDC073
0x06 (0x26)PINCPINC6PINC5PINC4PINC3PINC2PINC1PINC073
0x05 (0x25)PORTBPORTB7PORTB6PORTB5PORTB4PORTB3PORTB2PORTB1PORTB072
0x04 (0x24)DDRBDDB7DDB6DDB5DDB4DDB3DDB2DDB1DDB072
0x03 (0x23)PINBPINB7PINB6PINB5PINB4PINB3PINB2PINB1PINB072
0x02 (0x22)Reserved
0x01 (0x21)Reserved
0x00 (0x20)Reserved
🧠 Realtà: Il microcontrollore vede solo i numeri (0x04, 0x05...). Noi umani abbiamo dato nomi come DDRB, PORTB.
📦 passo 0

Materiali e collegamenti

  • Arduino Uno / Nano (ATmega328P)
  • Modulo driver ULN2003
  • Motore passo‑passo 28BYJ-48 (5V)
  • Cavi dupont
  • Alimentazione esterna 5V (consigliata)

Collegamenti

D8PORTB0ULN2003 IN1
D9PORTB1ULN2003 IN2
D10PORTB2ULN2003 IN3
D11PORTB3ULN2003 IN4
5V-alimentazione modulo
GND-comune

Nota: D8-D11 sono i bit 0-3 del registro PORTB (0x05).

⚡ passo 1

LED D13 (test)

Il LED D13 è sul bit 5 di PORTB (0x05).

; configura PB5 come OUTPUT (DDRB 0x04 bit5) sbi 4, 5 ; accendi LED (PORTB 0x05 bit5) sbi 5, 5 loop: rjmp loop
🔧 passo 2

Configura D8-D11 come OUTPUT

; DDRB (0x04) bit 0-3 = 1 sbi 4, 0 sbi 4, 1 sbi 4, 2 sbi 4, 3

Test LED modulo (facoltativo):

; PORTB (0x05) bit 0-3 = 1 sbi 5, 0 sbi 5, 1 sbi 5, 2 sbi 5, 3
⏱️ passo 3

Pausa con r16, r17, r18

wait: ldi r16, 0xFF ldi r17, 0xFF ldi r18, 0x04 ; modifica per velocità loop_w: dec r16 brne loop_w dec r17 brne loop_w dec r18 brne loop_w ret
🔄 passo 4

Sequenza full-step

; passo 1 (D8) sbi 5, 0 cbi 5, 1 cbi 5, 2 cbi 5, 3 rcall wait ; passo 2 (D9) cbi 5, 0 sbi 5, 1 cbi 5, 2 cbi 5, 3 rcall wait ; passo 3 (D10) cbi 5, 0 cbi 5, 1 sbi 5, 2 cbi 5, 3 rcall wait ; passo 4 (D11) cbi 5, 0 cbi 5, 1 cbi 5, 2 sbi 5, 3 rcall wait
🏁 passo 5

Programma completo

; === motore-stepper.asm === .org 0x60 ; DDRB output (0x04) sbi 4, 0 sbi 4, 1 sbi 4, 2 sbi 4, 3 loop: ; passo 1 sbi 5, 0 cbi 5, 1 cbi 5, 2 cbi 5, 3 rcall wait ; passo 2 cbi 5, 0 sbi 5, 1 cbi 5, 2 cbi 5, 3 rcall wait ; passo 3 cbi 5, 0 cbi 5, 1 sbi 5, 2 cbi 5, 3 rcall wait ; passo 4 cbi 5, 0 cbi 5, 1 cbi 5, 2 sbi 5, 3 rcall wait rjmp loop wait: ldi r16, 0xFF ldi r17, 0xFF ldi r18, 0x04 loop_w: dec r16 brne loop_w dec r17 brne loop_w dec r18 brne loop_w ret

Carica su costycnc.it/avr1/compiler.html → il motore gira.

🧠 passo 6

Per andare oltre