--- In AVR-Chat@yahoogroups.com, "David VanHorn" <microbrix@...>
wrote:
> One easy way to code it, is to use IN and OUT everywhere,
> and fix them when the assembler complains.
A more efficient alternative is to use a macro that expands to
either IN/OUT or LDS/STS depending on the port address. This method
has the additional advantage of automatically using the shortest
instruction for the AVR you're using.
An example GNU Assembler macro for input is shown below. The
corresponding macro for output is similar. If you are using the AVR
assembler you may be able to implement something like this.
// Macro to input from an I/O port to a register. Example use:
//
// inPort r24, UDR0
//
.macro inPort _reg, _port
.if (_SFR_IO_ADDR(\_port) < 64)
in \_reg, _SFR_IO_ADDR(\_port)
.else
lds \_reg, \_port
.endif
.endm
Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.netMessage
Re: Sample "c" code
2007-06-18 by Don Kinzer
Attachments
- No local attachments were found for this message.