AVR sbi command - Error: number must be positive and less than 32

I've spent quite a bit of time building my AVR development system with the entire GCC tool chain (all the most recent stable release) and I've solved most of the problems with it, but one.

This following code is giving me an error that 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 throws an error. Can anyone shed some light on why he is doing this?

  #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 corresponding string is sbi PORTB, 0.

Compiled / built with

avr-gcc ledon.S -mmcu = atmega168

+2


source to share


2 answers


I think it is complaining about PORTB, not the number of bits (0). How did you define PORTB? It must be in the range 0..31. You might need to subtract 32 from PORTB if your ports are defined in the range 32..63?



+2


source


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

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

      



[removed debug hints without actual solution]

+5


source







All Articles