Question

I've spent a good while getting my AVR development system set up with the full GCC tool chain (everything is the most recent current stable version) and I have solved most issues with it but one.

This following code gives me an error which I just don't get. The AVR assembly manual states that the sbi instruction can accept 0-7 as a constant expression but it still errors out on me. Can anyone shed some light onto why it does this please?

  #ifndef __AVR_ATmega168__
      #define __AVR_ATmega168__
  #endif

  #include <avr/io.h>

      rjmp Init

  Init:

      ser r16
      out DDRB, r16
      out DDRD, r16

      clr r16

      out PORTB, r16
      out PORTD, r16

  Start:

      sbi PORTB, 0
      rjmp Start

The line in question is sbi PORTB, 0.

Compiled / assembled with:

avr-gcc ledon.S -mmcu=atmega168

Was it helpful?

Solution

I think it's complaining about PORTB rather than the bit number (0). How have you defined PORTB ? It needs to be in the range 0..31. You may need to subtract 32 from PORTB if your ports are defined in the range 32..63 ?

OTHER TIPS

Update It turns out that you should write your assembly code like this when using avr-libc:

#include <avr/io.h>
sbi  _SFR_IO_ADDR(PORTB), 0

[deleted debugging hints with no actual solution ]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top