I've spent a good while getting my AVR development system set up 开发者_如何学Cwith 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
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 ]
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 ?
精彩评论