Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: Sample "c" code

2007-06-18 by microbrix@gmail.com

i've never been a big fan of macros.  i like to see the actual code.

normally there's only a few points in the code that actually talk to
the i/o directly anyway, so just fixing them by hand is easy.


On 6/18/07, Don Kinzer <dkinzer@easystreet.com> wrote:
> --- 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.net
>
>
>
>
> Yahoo! Groups Links
>
>
>
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.