I would like to understand how to configure ports (port, ddr, pin) using the avr assembler atmega328p

0

Example I was testing, configuring outbound ports and inbound ports to be able to perform a sum, but they are not working:

ldi r21, 0x0a
ldi r22, 0x0b

out PINB, r16
out DDRB, r16
out PORTB, r17

add r21, r22
mov r17, r21
    
asked by anonymous 27.02.2017 / 21:24

1 answer

0
  • A nibble (half-byte) is being loaded in r16. Usually the right one is 0x0a or 0xa0.
  • 0xa0 in DDRB is equal to 0b10100000 which activates output pins 7 and 5. While 0x0a is equal to 0b00001010 which activates output pins 1 and 3.
  • To read a port, the correct one is:

    In  r16, pinb
    
  • 27.02.2017 / 22:07